-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add the LinkerAuthorization validator (#246)
- Loading branch information
1 parent
7859afb
commit 52cf77b
Showing
4 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { JSONSchema, ValidateFunction, generateLazyValidator } from '../validation' | ||
|
||
/** | ||
* Represents a Linker-Server Authorization. | ||
* | ||
* @public | ||
*/ | ||
export type LinkerAuthorization = { | ||
name: string | ||
desc: string | ||
startDate?: number | ||
endDate?: number | ||
contactInfo: { | ||
name: string | ||
[key: string]: string | ||
} | ||
addresses: string[] | ||
plots: string[] | ||
} | ||
|
||
export namespace LinkerAuthorization { | ||
export const schema: JSONSchema<LinkerAuthorization> = { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string' }, | ||
desc: { type: 'string' }, | ||
startDate: { type: 'number', nullable: true }, | ||
endDate: { type: 'number', nullable: true }, | ||
contactInfo: { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string' } | ||
}, | ||
required: ['name'] | ||
}, | ||
addresses: { | ||
type: 'array', | ||
items: { type: 'string' }, | ||
minItems: 1 | ||
}, | ||
plots: { | ||
type: 'array', | ||
items: { type: 'string' }, | ||
minItems: 1 | ||
} | ||
}, | ||
required: ['name', 'desc', 'contactInfo', 'addresses', 'plots'] | ||
} | ||
|
||
export const validate: ValidateFunction<LinkerAuthorization> = generateLazyValidator(schema) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import expect from 'expect' | ||
import { LinkerAuthorization } from '../../src' | ||
|
||
describe('when validation authorizations', () => { | ||
describe('and the authorization does not include a name', () => { | ||
it('should return false', () => { | ||
expect( | ||
LinkerAuthorization.validate({ | ||
desc: 'aDesc', | ||
contactInfo: { | ||
name: 'aContactInfoName' | ||
}, | ||
addresses: ['0x4730182099bc4e60075C657cCeCEc8879826bb43'], | ||
plots: ['-73,50'] | ||
}) | ||
).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('and the authorization does not include a description', () => { | ||
it('should return false', () => { | ||
expect( | ||
LinkerAuthorization.validate({ | ||
name: 'aName', | ||
contactInfo: { | ||
name: 'aContactInfoName' | ||
}, | ||
addresses: ['0x4730182099bc4e60075C657cCeCEc8879826bb43'], | ||
plots: ['-73,50'] | ||
}) | ||
).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('and the authorization does not include the contact information', () => { | ||
it('should return false', () => { | ||
expect( | ||
LinkerAuthorization.validate({ | ||
name: 'aName', | ||
desc: 'aDesc', | ||
addresses: ['0x4730182099bc4e60075C657cCeCEc8879826bb43'], | ||
plots: ['-73,50'] | ||
}) | ||
).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('and the authorization contains an empty contact information', () => { | ||
it('should return false', () => { | ||
expect( | ||
LinkerAuthorization.validate({ | ||
name: 'aName', | ||
desc: 'aDesc', | ||
contactInfo: {}, | ||
addresses: ['0x4730182099bc4e60075C657cCeCEc8879826bb43'], | ||
plots: ['-73,50'] | ||
}) | ||
).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('and the authorization does not include the addresses', () => { | ||
it('should return false', () => { | ||
expect( | ||
LinkerAuthorization.validate({ | ||
name: 'aName', | ||
desc: 'aDesc', | ||
contactInfo: { | ||
name: 'aContactInfoName' | ||
}, | ||
plots: ['-73,50'] | ||
}) | ||
).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('and the authorization contains an empty list of addresses', () => { | ||
it('should return false', () => { | ||
expect( | ||
LinkerAuthorization.validate({ | ||
name: 'aName', | ||
desc: 'aDesc', | ||
contactInfo: { | ||
name: 'aContactInfoName' | ||
}, | ||
addresses: [], | ||
plots: ['-73,50'] | ||
}) | ||
).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('and the authorization does not include the plots', () => { | ||
it('should return false', () => { | ||
expect( | ||
LinkerAuthorization.validate({ | ||
name: 'aName', | ||
desc: 'aDesc', | ||
contactInfo: { | ||
name: 'aContactInfoName' | ||
}, | ||
addresses: ['0x4730182099bc4e60075C657cCeCEc8879826bb43'] | ||
}) | ||
).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('and the authorization contains an empty list of plots', () => { | ||
it('should return false', () => { | ||
expect( | ||
LinkerAuthorization.validate({ | ||
name: 'aName', | ||
desc: 'aDesc', | ||
contactInfo: { | ||
name: 'aContactInfoName' | ||
}, | ||
addresses: ['0x4730182099bc4e60075C657cCeCEc8879826bb43'], | ||
plots: [] | ||
}) | ||
).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('and the authorization is formatted accordingly', () => { | ||
it('should return true', () => { | ||
expect( | ||
LinkerAuthorization.validate({ | ||
name: 'aName', | ||
desc: 'aDesc', | ||
contactInfo: { | ||
name: 'aContactInfoName' | ||
}, | ||
addresses: ['0x4730182099bc4e60075C657cCeCEc8879826bb43'], | ||
plots: ['-73,50'] | ||
}) | ||
).toBe(true) | ||
}) | ||
}) | ||
}) |