Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve uniqueItemProperties error messaging #123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added test for uniqueItemProperties error message with property name
Pushkarang committed May 23, 2020
commit 81aaea065ae7e75594b7cef45bdfe9b464a0a8f9
53 changes: 53 additions & 0 deletions spec/uniqueItemProperties.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

var Ajv = require('ajv');
var defFunc = require('../keywords/uniqueItemProperties');
var defineKeywords = require('..');

describe('keyword "uniqueItemProperties"', function () {
var ajvs = [
defFunc(new Ajv({ $data: true })),
defineKeywords(new Ajv({ $data: true }), 'uniqueItemProperties'),
defineKeywords(new Ajv({ $data: true, allErrors: true }))
];

describe('with scalar propery', function () {
ajvs.forEach(function (ajv, i) {
it('should return error message with property name #' + i, function () {
var invalidData = [
{ 'id': 1 },
{ 'id': 1 },
{ 'id': 3 }
];
var validate = ajv.compile({ uniqueItemProperties: ['id'] });

validate(invalidData).should.equal(false);
var error = validate.errors[0];

error.keyword.should.equal('uniqueItemProperties');
error.params.keyword.should.equal('uniqueItemProperties');
error.message.should.equal('should have unique id');
});
});
});

describe('with non scalar propery', function () {
ajvs.forEach(function (ajv, i) {
it('should return error message with property name #' + i, function () {
var invalidData = [
{ 'name': {'firstName': 'John', 'lastName': 'Doe'}},
{ 'name': {'firstName': 'John', 'lastName': 'Doe'}},
{ 'name': {'firstName': 'Lorem', 'lastName': 'Ipsum'}}
];
var validate = ajv.compile({ uniqueItemProperties: ['name'] });

validate(invalidData).should.equal(false);
var error = validate.errors[0];

error.keyword.should.equal('uniqueItemProperties');
error.params.keyword.should.equal('uniqueItemProperties');
error.message.should.equal('should have unique name');
});
});
});
});