|
@@ -8,143 +8,143 @@ const S = new RelationsDefinitionValidator();
|
|
|
describe('RelationsDefinitionValidator', function () {
|
|
describe('RelationsDefinitionValidator', function () {
|
|
|
describe('validate', function () {
|
|
describe('validate', function () {
|
|
|
it('requires a first argument to be a non-empty string', function () {
|
|
it('requires a first argument to be a non-empty string', function () {
|
|
|
- const validate = value => () => S.validate(value, {});
|
|
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const validate = v => () => S.validate(v, {});
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'A first argument of RelationsDefinitionValidator.validate ' +
|
|
'A first argument of RelationsDefinitionValidator.validate ' +
|
|
|
- 'should be a non-empty String, but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'should be a non-empty String, but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('model')();
|
|
validate('model')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('requires a second argument to be an object', function () {
|
|
it('requires a second argument to be an object', function () {
|
|
|
- const validate = value => () => S.validate('model', value);
|
|
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const validate = v => () => S.validate('model', v);
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The provided option "relations" of the model "model" ' +
|
|
'The provided option "relations" of the model "model" ' +
|
|
|
- 'should be an Object, but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'should be an Object, but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('str')).to.throw(error('str'));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('str')).to.throw(error('"str"'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate({})();
|
|
validate({})();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('requires a relation name to be a non-empty string', function () {
|
|
it('requires a relation name to be a non-empty string', function () {
|
|
|
- const validate = relations => () => S.validate('model', relations);
|
|
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const validate = v => () => S.validate('model', v);
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation name of the model "model" should be ' +
|
|
'The relation name of the model "model" should be ' +
|
|
|
- 'a non-empty String, but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'a non-empty String, but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate({['']: {}})).to.throw(error(''));
|
|
|
|
|
|
|
+ expect(validate({['']: {}})).to.throw(error('""'));
|
|
|
validate({foo: {type: RelationType.BELONGS_TO, model: 'model'}})();
|
|
validate({foo: {type: RelationType.BELONGS_TO, model: 'model'}})();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('requires a relation definition to be an object', function () {
|
|
it('requires a relation definition to be an object', function () {
|
|
|
- const validate = foo => () => S.validate('model', {foo});
|
|
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const validate = v => () => S.validate('model', {foo: v});
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" should ' +
|
|
'The relation "foo" of the model "model" should ' +
|
|
|
- 'be an Object, but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'be an Object, but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('str')).to.throw(error('str'));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('str')).to.throw(error('"str"'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate({type: RelationType.BELONGS_TO, model: 'model'})();
|
|
validate({type: RelationType.BELONGS_TO, model: 'model'})();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('requires the option "type" to be a RelationType', function () {
|
|
it('requires the option "type" to be a RelationType', function () {
|
|
|
- const validate = type => () => {
|
|
|
|
|
- const foo = {type, model: 'model'};
|
|
|
|
|
|
|
+ const validate = v => () => {
|
|
|
|
|
+ const foo = {type: v, model: 'model'};
|
|
|
S.validate('model', {foo});
|
|
S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" requires the option "type" ' +
|
|
'The relation "foo" of the model "model" requires the option "type" ' +
|
|
|
- 'to have one of relation types: %l, but %v given.',
|
|
|
|
|
|
|
+ 'to have one of relation types: %l, but %s given.',
|
|
|
Object.values(RelationType),
|
|
Object.values(RelationType),
|
|
|
- value,
|
|
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('str')).to.throw(error('str'));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('str')).to.throw(error('"str"'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate(RelationType.BELONGS_TO)();
|
|
validate(RelationType.BELONGS_TO)();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
describe('belongsTo', function () {
|
|
describe('belongsTo', function () {
|
|
|
describe('a regular relation', function () {
|
|
describe('a regular relation', function () {
|
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.BELONGS_TO,
|
|
type: RelationType.BELONGS_TO,
|
|
|
- model: value,
|
|
|
|
|
|
|
+ model: v,
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "belongsTo", ' +
|
|
'The relation "foo" of the model "model" has the type "belongsTo", ' +
|
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('model')();
|
|
validate('model')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('expects the provided option "foreignKey" to be a string', function () {
|
|
it('expects the provided option "foreignKey" to be a string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.BELONGS_TO,
|
|
type: RelationType.BELONGS_TO,
|
|
|
model: 'model',
|
|
model: 'model',
|
|
|
- foreignKey: value,
|
|
|
|
|
|
|
+ foreignKey: v,
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "belongsTo", ' +
|
|
'The relation "foo" of the model "model" has the type "belongsTo", ' +
|
|
|
'so it expects the provided option "foreignKey" to be a String, ' +
|
|
'so it expects the provided option "foreignKey" to be a String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
validate('foreignKey')();
|
|
validate('foreignKey')();
|
|
|
validate('')();
|
|
validate('')();
|
|
|
validate(false)();
|
|
validate(false)();
|
|
@@ -170,47 +170,47 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
|
|
|
|
|
describe('a polymorphic relation', function () {
|
|
describe('a polymorphic relation', function () {
|
|
|
it('requires the option "polymorphic" to be a boolean', function () {
|
|
it('requires the option "polymorphic" to be a boolean', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.BELONGS_TO,
|
|
type: RelationType.BELONGS_TO,
|
|
|
- polymorphic: value,
|
|
|
|
|
|
|
+ polymorphic: v,
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "belongsTo", ' +
|
|
'The relation "foo" of the model "model" has the type "belongsTo", ' +
|
|
|
'so it expects the option "polymorphic" to be a Boolean, ' +
|
|
'so it expects the option "polymorphic" to be a Boolean, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('str')).to.throw(error('str'));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
|
|
+ expect(validate('str')).to.throw(error('"str"'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
validate(true)();
|
|
validate(true)();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('expects the provided option "foreignKey" to be a string', function () {
|
|
it('expects the provided option "foreignKey" to be a string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.BELONGS_TO,
|
|
type: RelationType.BELONGS_TO,
|
|
|
polymorphic: true,
|
|
polymorphic: true,
|
|
|
- foreignKey: value,
|
|
|
|
|
|
|
+ foreignKey: v,
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" is a polymorphic "belongsTo" relation, ' +
|
|
'The relation "foo" of the model "model" is a polymorphic "belongsTo" relation, ' +
|
|
|
'so it expects the provided option "foreignKey" to be a String, ' +
|
|
'so it expects the provided option "foreignKey" to be a String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
validate('foreignKey')();
|
|
validate('foreignKey')();
|
|
|
validate('')();
|
|
validate('')();
|
|
|
validate(false)();
|
|
validate(false)();
|
|
@@ -219,25 +219,25 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('expects the provided option "discriminator" to be a string', function () {
|
|
it('expects the provided option "discriminator" to be a string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.BELONGS_TO,
|
|
type: RelationType.BELONGS_TO,
|
|
|
polymorphic: true,
|
|
polymorphic: true,
|
|
|
- discriminator: value,
|
|
|
|
|
|
|
+ discriminator: v,
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" is a polymorphic "belongsTo" relation, ' +
|
|
'The relation "foo" of the model "model" is a polymorphic "belongsTo" relation, ' +
|
|
|
'so it expects the provided option "discriminator" to be a String, ' +
|
|
'so it expects the provided option "discriminator" to be a String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
validate('discriminator')();
|
|
validate('discriminator')();
|
|
|
validate('')();
|
|
validate('')();
|
|
|
validate(false)();
|
|
validate(false)();
|
|
@@ -250,56 +250,56 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
describe('hasOne', function () {
|
|
describe('hasOne', function () {
|
|
|
describe('a regular relation', function () {
|
|
describe('a regular relation', function () {
|
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.HAS_ONE,
|
|
type: RelationType.HAS_ONE,
|
|
|
model: 'model',
|
|
model: 'model',
|
|
|
- foreignKey: value,
|
|
|
|
|
|
|
+ foreignKey: v,
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "hasOne", ' +
|
|
'The relation "foo" of the model "model" has the type "hasOne", ' +
|
|
|
'so it requires the option "foreignKey" to be a non-empty String, ' +
|
|
'so it requires the option "foreignKey" to be a non-empty String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('modelId')();
|
|
validate('modelId')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('requires the option "foreignKey" to be a string', function () {
|
|
it('requires the option "foreignKey" to be a string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.HAS_ONE,
|
|
type: RelationType.HAS_ONE,
|
|
|
- model: value,
|
|
|
|
|
|
|
+ model: v,
|
|
|
foreignKey: 'modelId',
|
|
foreignKey: 'modelId',
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "hasOne", ' +
|
|
'The relation "foo" of the model "model" has the type "hasOne", ' +
|
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('model')();
|
|
validate('model')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -322,29 +322,29 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
|
|
|
|
|
describe('a polymorphic relation with a target relation name', function () {
|
|
describe('a polymorphic relation with a target relation name', function () {
|
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.HAS_ONE,
|
|
type: RelationType.HAS_ONE,
|
|
|
- model: value,
|
|
|
|
|
|
|
+ model: v,
|
|
|
polymorphic: 'reference',
|
|
polymorphic: 'reference',
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "hasOne", ' +
|
|
'The relation "foo" of the model "model" has the type "hasOne", ' +
|
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('model')();
|
|
validate('model')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -385,89 +385,89 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
|
|
|
|
|
describe('a polymorphic relation with target relation keys', function () {
|
|
describe('a polymorphic relation with target relation keys', function () {
|
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.HAS_ONE,
|
|
type: RelationType.HAS_ONE,
|
|
|
- model: value,
|
|
|
|
|
|
|
+ model: v,
|
|
|
polymorphic: true,
|
|
polymorphic: true,
|
|
|
foreignKey: 'referenceId',
|
|
foreignKey: 'referenceId',
|
|
|
discriminator: 'referenceType',
|
|
discriminator: 'referenceType',
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "hasOne", ' +
|
|
'The relation "foo" of the model "model" has the type "hasOne", ' +
|
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('model')();
|
|
validate('model')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('requires the option "foreignKey" to be a non-empty string', function () {
|
|
it('requires the option "foreignKey" to be a non-empty string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.HAS_ONE,
|
|
type: RelationType.HAS_ONE,
|
|
|
model: 'model',
|
|
model: 'model',
|
|
|
polymorphic: true,
|
|
polymorphic: true,
|
|
|
- foreignKey: value,
|
|
|
|
|
|
|
+ foreignKey: v,
|
|
|
discriminator: 'referenceType',
|
|
discriminator: 'referenceType',
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
'The relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
|
'with "true" value, so it requires the option "foreignKey" ' +
|
|
'with "true" value, so it requires the option "foreignKey" ' +
|
|
|
- 'to be a non-empty String, but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'to be a non-empty String, but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('referenceId')();
|
|
validate('referenceId')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('requires the option "discriminator" to be a non-empty string', function () {
|
|
it('requires the option "discriminator" to be a non-empty string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.HAS_ONE,
|
|
type: RelationType.HAS_ONE,
|
|
|
model: 'model',
|
|
model: 'model',
|
|
|
polymorphic: true,
|
|
polymorphic: true,
|
|
|
foreignKey: 'referenceId',
|
|
foreignKey: 'referenceId',
|
|
|
- discriminator: value,
|
|
|
|
|
|
|
+ discriminator: v,
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
'The relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
|
'with "true" value, so it requires the option "discriminator" ' +
|
|
'with "true" value, so it requires the option "discriminator" ' +
|
|
|
- 'to be a non-empty String, but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'to be a non-empty String, but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('referenceType')();
|
|
validate('referenceType')();
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -476,56 +476,56 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
describe('hasMany', function () {
|
|
describe('hasMany', function () {
|
|
|
describe('a regular relation', function () {
|
|
describe('a regular relation', function () {
|
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.HAS_MANY,
|
|
type: RelationType.HAS_MANY,
|
|
|
model: 'model',
|
|
model: 'model',
|
|
|
- foreignKey: value,
|
|
|
|
|
|
|
+ foreignKey: v,
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "hasMany", ' +
|
|
'The relation "foo" of the model "model" has the type "hasMany", ' +
|
|
|
'so it requires the option "foreignKey" to be a non-empty String, ' +
|
|
'so it requires the option "foreignKey" to be a non-empty String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('modelId')();
|
|
validate('modelId')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('requires the option "foreignKey" to be a string', function () {
|
|
it('requires the option "foreignKey" to be a string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.HAS_MANY,
|
|
type: RelationType.HAS_MANY,
|
|
|
- model: value,
|
|
|
|
|
|
|
+ model: v,
|
|
|
foreignKey: 'modelId',
|
|
foreignKey: 'modelId',
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "hasMany", ' +
|
|
'The relation "foo" of the model "model" has the type "hasMany", ' +
|
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('model')();
|
|
validate('model')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -548,29 +548,29 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
|
|
|
|
|
describe('a polymorphic relation with a target relation name', function () {
|
|
describe('a polymorphic relation with a target relation name', function () {
|
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.HAS_MANY,
|
|
type: RelationType.HAS_MANY,
|
|
|
- model: value,
|
|
|
|
|
|
|
+ model: v,
|
|
|
polymorphic: 'reference',
|
|
polymorphic: 'reference',
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "hasMany", ' +
|
|
'The relation "foo" of the model "model" has the type "hasMany", ' +
|
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('model')();
|
|
validate('model')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -611,89 +611,89 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
|
|
|
|
|
describe('a polymorphic relation with target relation keys', function () {
|
|
describe('a polymorphic relation with target relation keys', function () {
|
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.HAS_MANY,
|
|
type: RelationType.HAS_MANY,
|
|
|
- model: value,
|
|
|
|
|
|
|
+ model: v,
|
|
|
polymorphic: true,
|
|
polymorphic: true,
|
|
|
foreignKey: 'referenceId',
|
|
foreignKey: 'referenceId',
|
|
|
discriminator: 'referenceType',
|
|
discriminator: 'referenceType',
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "hasMany", ' +
|
|
'The relation "foo" of the model "model" has the type "hasMany", ' +
|
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('model')();
|
|
validate('model')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('requires the option "foreignKey" to be a non-empty string', function () {
|
|
it('requires the option "foreignKey" to be a non-empty string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.HAS_MANY,
|
|
type: RelationType.HAS_MANY,
|
|
|
model: 'model',
|
|
model: 'model',
|
|
|
polymorphic: true,
|
|
polymorphic: true,
|
|
|
- foreignKey: value,
|
|
|
|
|
|
|
+ foreignKey: v,
|
|
|
discriminator: 'referenceType',
|
|
discriminator: 'referenceType',
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
'The relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
|
'with "true" value, so it requires the option "foreignKey" ' +
|
|
'with "true" value, so it requires the option "foreignKey" ' +
|
|
|
- 'to be a non-empty String, but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'to be a non-empty String, but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('referenceId')();
|
|
validate('referenceId')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('requires the option "discriminator" to be a non-empty string', function () {
|
|
it('requires the option "discriminator" to be a non-empty string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.HAS_MANY,
|
|
type: RelationType.HAS_MANY,
|
|
|
model: 'model',
|
|
model: 'model',
|
|
|
polymorphic: true,
|
|
polymorphic: true,
|
|
|
foreignKey: 'referenceId',
|
|
foreignKey: 'referenceId',
|
|
|
- discriminator: value,
|
|
|
|
|
|
|
+ discriminator: v,
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
'The relation "foo" of the model "model" has the option "polymorphic" ' +
|
|
|
'with "true" value, so it requires the option "discriminator" ' +
|
|
'with "true" value, so it requires the option "discriminator" ' +
|
|
|
- 'to be a non-empty String, but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'to be a non-empty String, but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('referenceType')();
|
|
validate('referenceType')();
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -701,51 +701,51 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
|
|
|
|
|
describe('referencesMany', function () {
|
|
describe('referencesMany', function () {
|
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
it('requires the option "model" to be a non-empty string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.REFERENCES_MANY,
|
|
type: RelationType.REFERENCES_MANY,
|
|
|
- model: value,
|
|
|
|
|
|
|
+ model: v,
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "referencesMany", ' +
|
|
'The relation "foo" of the model "model" has the type "referencesMany", ' +
|
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
'so it requires the option "model" to be a non-empty String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate('')).to.throw(error(''));
|
|
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate(false)).to.throw(error(false));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
- expect(validate(undefined)).to.throw(error(undefined));
|
|
|
|
|
- expect(validate(null)).to.throw(error(null));
|
|
|
|
|
|
|
+ expect(validate('')).to.throw(error('""'));
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate(false)).to.throw(error('false'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
|
|
+ expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
|
|
+ expect(validate(null)).to.throw(error('null'));
|
|
|
validate('model')();
|
|
validate('model')();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('expects the provided option "foreignKey" to be a string', function () {
|
|
it('expects the provided option "foreignKey" to be a string', function () {
|
|
|
- const validate = value => {
|
|
|
|
|
|
|
+ const validate = v => {
|
|
|
const foo = {
|
|
const foo = {
|
|
|
type: RelationType.REFERENCES_MANY,
|
|
type: RelationType.REFERENCES_MANY,
|
|
|
model: 'model',
|
|
model: 'model',
|
|
|
- foreignKey: value,
|
|
|
|
|
|
|
+ foreignKey: v,
|
|
|
};
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
};
|
|
|
- const error = value =>
|
|
|
|
|
|
|
+ const error = v =>
|
|
|
format(
|
|
format(
|
|
|
'The relation "foo" of the model "model" has the type "referencesMany", ' +
|
|
'The relation "foo" of the model "model" has the type "referencesMany", ' +
|
|
|
'so it expects the provided option "foreignKey" to be a String, ' +
|
|
'so it expects the provided option "foreignKey" to be a String, ' +
|
|
|
- 'but %v given.',
|
|
|
|
|
- value,
|
|
|
|
|
|
|
+ 'but %s given.',
|
|
|
|
|
+ v,
|
|
|
);
|
|
);
|
|
|
- expect(validate(10)).to.throw(error(10));
|
|
|
|
|
- expect(validate(true)).to.throw(error(true));
|
|
|
|
|
- expect(validate({})).to.throw(error({}));
|
|
|
|
|
- expect(validate([])).to.throw(error([]));
|
|
|
|
|
|
|
+ expect(validate(10)).to.throw(error('10'));
|
|
|
|
|
+ expect(validate(true)).to.throw(error('true'));
|
|
|
|
|
+ expect(validate({})).to.throw(error('Object'));
|
|
|
|
|
+ expect(validate([])).to.throw(error('Array'));
|
|
|
validate('foreignKey')();
|
|
validate('foreignKey')();
|
|
|
validate('')();
|
|
validate('')();
|
|
|
validate(false)();
|
|
validate(false)();
|