Skip to content

Commit

Permalink
chore: add a unit test for a draft-07 JSON schema (see #406)
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Feb 28, 2024
1 parent 4087e3f commit 4e188fe
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/lib/plugins/validator/createAjvValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,39 @@ describe('createAjvValidator', () => {
}, /the signature of createAjvValidator is changed/)
})

// TODO: test support for draft04, draft-06, draft-07
test('should support draft-07', () => {
const schemaDraft07 = {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'My test schema',
type: 'object',
properties: {
userId: {
type: 'number'
},
name: {
type: 'string'
}
},
required: ['userId', 'name']
}

const validate = createAjvValidator({ schema: schemaDraft07 })

const validJson = {
userId: 1,
name: 'Luke Skywalker'
}

const invalidJson = {
userId: '1'
}

assert.deepStrictEqual(validate(validJson), [])
assert.deepStrictEqual(validate(invalidJson), [
{ path: [], message: "must have required property 'name'", severity: 'warning' },
{ path: ['userId'], message: 'must be number', severity: 'warning' }
])
})

// TODO: test support for draft04, draft-06
})

0 comments on commit 4e188fe

Please sign in to comment.