-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.test.js
41 lines (35 loc) · 1.37 KB
/
user.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const Ajv = require('ajv')
const addFormats = require('ajv-formats')
const fixtures = require('../../__fixtures__')
const clientCreatedSchema = require('../../src/schemas/user/created.json')
const clientDeletedSchema = require('../../src/schemas/user/deleted.json')
const ajv = new Ajv()
addFormats(ajv)
describe('clientDeleted Schema', () => {
it('Should keep the same schema', () => {
expect(clientDeletedSchema).toMatchSnapshot()
})
it('Should recognize a valid payload', () => {
const validate = ajv.compile(clientDeletedSchema.schema)
const valid = validate(fixtures.user.deleted)
expect(valid).toEqual(true)
expect(validate.errors).toEqual(null)
})
})
describe('clientCreated Schema', () => {
it('Should keep the same schema', () => {
expect(clientCreatedSchema).toMatchSnapshot()
})
it('Should recognize a valid payload with all properties included', () => {
const validate = ajv.compile(clientCreatedSchema.schema)
const valid = validate(fixtures.user.created.allProperties)
expect(valid).toEqual(true)
expect(validate.errors).toEqual(null)
})
it('Should recognize a valid payload with minimal properties included', () => {
const validate = ajv.compile(clientCreatedSchema.schema)
const valid = validate(fixtures.user.created.minimalProperties)
expect(valid).toEqual(true)
expect(validate.errors).toEqual(null)
})
})