Skip to content

Commit

Permalink
add test for json schema
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Mar 17, 2019
1 parent cb37447 commit 69b39db
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion test/conditions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,64 @@ describe('conditions', () => {
});
});

describe('req.matchEGCondition', function () {
describe('jsonSchema', function () {
const req = Object.create(express.request);

it('should return true if the body matches the schema', function () {
req.body = {
name: 'Clark',
surname: 'Kent',
age: 30
};

should(conditions['json-schema']({
schema: {
$id: 'schema1',
type: 'object',
properties: {
name: {
type: 'string'
},
surname: {
type: 'string'
},
age: {
type: 'number'
}
},
required: ['name', 'surname', 'age']
}
})(req)).be.true();
});

it('should return false if the body does not match the schema', function () {
req.body = {
name: 'Clark',
surname: 'Kent'
};

should(conditions['json-schema']({
schema: {
$id: 'schema2',
type: 'object',
properties: {
name: {
type: 'string'
},
surname: {
type: 'string'
},
age: {
type: 'number'
}
},
required: ['name', 'surname', 'age']
}
})(req)).be.false();
});
});

describe('complex conditions', function () {
const req = Object.create(express.request);
it('correctly handles complex conditional rule', function () {
const control = { name: 'never' };
Expand Down

0 comments on commit 69b39db

Please sign in to comment.