Skip to content

Commit

Permalink
Add test cases for v0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fedgiac committed Oct 13, 2023
1 parent 019dfc4 commit eb8c909
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import schemaV0_4_0 from '../schemas/v0.4.0.json'
import schemaV0_5_0 from '../schemas/v0.5.0.json'
import schemaV0_6_0 from '../schemas/v0.6.0.json'
import schemaV0_9_0 from '../schemas/v0.9.0.json'
import schemaV0_10_0 from '../schemas/v0.10.0.json'

const ADDRESS = '0xb6BAd41ae76A11D10f7b0E664C5007b908bC77C9'
const REFERRER_V0_1_0 = { address: ADDRESS, version: '0.1.0' }
Expand Down Expand Up @@ -487,6 +488,70 @@ describe('Schema v0.9.0', () => {
)
})

describe('Schema v0.10.0', () => {
const ajv = new Ajv()
const validator = ajv.compile(schemaV0_10_0)

const BASE_DOCUMENT = {
version: '0.10.0',
metadata: {},
}

test('Minimal valid schema', _buildAssertValidFn(validator, BASE_DOCUMENT))

test(
'With signer v0.1.0',
_buildAssertValidFn(validator, {
...BASE_DOCUMENT,
metadata: { signer: ADDRESS },
})
)

test(
'Signer with invalid address',
_buildAssertInvalidFn(
validator,
{
...BASE_DOCUMENT,
metadata: {
signer: '0xinvalid',
},
},
[
{
instancePath: '/metadata/signer',
keyword: 'pattern',
message: 'must match pattern "^0x[a-fA-F0-9]{40}$"',
params: { pattern: '^0x[a-fA-F0-9]{40}$' },
schemaPath: '#/properties/metadata/properties/signer/pattern',
},
]
)
)

test(
'Signer with invalid address',
_buildAssertInvalidFn(
validator,
{
...BASE_DOCUMENT,
metadata: {
signer: { address: ADDRESS },
},
},
[
{
instancePath: '/metadata/signer',
keyword: 'type',
message: 'must be string',
params: { type: 'string' },
schemaPath: '#/properties/metadata/properties/signer/type',
},
]
)
)
})

function _buildAssertValidFn(validator: ValidateFunction, doc: any) {
return () => {
// when
Expand Down

0 comments on commit eb8c909

Please sign in to comment.