|
|
@@ -253,15 +253,15 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
const validate = v => {
|
|
|
const foo = {
|
|
|
type: RelationType.HAS_ONE,
|
|
|
- model: 'model',
|
|
|
- foreignKey: v,
|
|
|
+ model: v,
|
|
|
+ foreignKey: 'modelId',
|
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
|
const error = v =>
|
|
|
format(
|
|
|
'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 "model" to be a non-empty String, ' +
|
|
|
'but %s given.',
|
|
|
v,
|
|
|
);
|
|
|
@@ -273,22 +273,22 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
expect(validate([])).to.throw(error('Array'));
|
|
|
expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
expect(validate(null)).to.throw(error('null'));
|
|
|
- validate('modelId')();
|
|
|
+ validate('model')();
|
|
|
});
|
|
|
|
|
|
- it('requires the option "foreignKey" to be a string', function () {
|
|
|
+ it('requires the option "foreignKey" to be a non-empty string', function () {
|
|
|
const validate = v => {
|
|
|
const foo = {
|
|
|
type: RelationType.HAS_ONE,
|
|
|
- model: v,
|
|
|
- foreignKey: 'modelId',
|
|
|
+ model: 'model',
|
|
|
+ foreignKey: v,
|
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
|
const error = v =>
|
|
|
format(
|
|
|
'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 "foreignKey" to be a non-empty String, ' +
|
|
|
'but %s given.',
|
|
|
v,
|
|
|
);
|
|
|
@@ -300,7 +300,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
expect(validate([])).to.throw(error('Array'));
|
|
|
expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
expect(validate(null)).to.throw(error('null'));
|
|
|
- validate('model')();
|
|
|
+ validate('modelId')();
|
|
|
});
|
|
|
|
|
|
it('throws an error if the option "discriminator" is provided', function () {
|
|
|
@@ -479,15 +479,15 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
const validate = v => {
|
|
|
const foo = {
|
|
|
type: RelationType.HAS_MANY,
|
|
|
- model: 'model',
|
|
|
- foreignKey: v,
|
|
|
+ model: v,
|
|
|
+ foreignKey: 'modelId',
|
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
|
const error = v =>
|
|
|
format(
|
|
|
'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 "model" to be a non-empty String, ' +
|
|
|
'but %s given.',
|
|
|
v,
|
|
|
);
|
|
|
@@ -499,22 +499,22 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
expect(validate([])).to.throw(error('Array'));
|
|
|
expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
expect(validate(null)).to.throw(error('null'));
|
|
|
- validate('modelId')();
|
|
|
+ validate('model')();
|
|
|
});
|
|
|
|
|
|
- it('requires the option "foreignKey" to be a string', function () {
|
|
|
+ it('requires the option "foreignKey" to be a non-empty string', function () {
|
|
|
const validate = v => {
|
|
|
const foo = {
|
|
|
type: RelationType.HAS_MANY,
|
|
|
- model: v,
|
|
|
- foreignKey: 'modelId',
|
|
|
+ model: 'model',
|
|
|
+ foreignKey: v,
|
|
|
};
|
|
|
return () => S.validate('model', {foo});
|
|
|
};
|
|
|
const error = v =>
|
|
|
format(
|
|
|
'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 "foreignKey" to be a non-empty String, ' +
|
|
|
'but %s given.',
|
|
|
v,
|
|
|
);
|
|
|
@@ -526,7 +526,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
expect(validate([])).to.throw(error('Array'));
|
|
|
expect(validate(undefined)).to.throw(error('undefined'));
|
|
|
expect(validate(null)).to.throw(error('null'));
|
|
|
- validate('model')();
|
|
|
+ validate('modelId')();
|
|
|
});
|
|
|
|
|
|
it('throws an error if the option "discriminator" is provided', function () {
|