|
@@ -174,1780 +174,1782 @@ describe('ModelDataValidator', function () {
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describe('DataType.ANY', function () {
|
|
|
|
|
- describe('ShortPropertyDefinition', function () {
|
|
|
|
|
- it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ANY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: undefined,
|
|
|
|
|
|
|
+ describe('validate by property type', function () {
|
|
|
|
|
+ describe('DataType.ANY', function () {
|
|
|
|
|
+ describe('ShortPropertyDefinition', function () {
|
|
|
|
|
+ it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: undefined,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a null given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ANY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: null,
|
|
|
|
|
|
|
+ it('does not throw an error if a null given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: null,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a string given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ANY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 'bar',
|
|
|
|
|
|
|
+ it('does not throw an error if a string given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 'bar',
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a number given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ANY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 10,
|
|
|
|
|
|
|
+ it('does not throw an error if a number given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 10,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if true given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ANY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: true,
|
|
|
|
|
|
|
+ it('does not throw an error if true given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: true,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if false given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ANY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: false,
|
|
|
|
|
|
|
+ it('does not throw an error if false given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: false,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if an array given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ANY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: [],
|
|
|
|
|
|
|
+ it('does not throw an error if an array given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: [],
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if an object given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ANY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: {},
|
|
|
|
|
|
|
+ it('does not throw an error if an object given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: {},
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- describe('FullPropertyDefinition', function () {
|
|
|
|
|
- it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ANY,
|
|
|
|
|
|
|
+ describe('FullPropertyDefinition', function () {
|
|
|
|
|
+ it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: undefined,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: undefined,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a null given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ANY,
|
|
|
|
|
|
|
+ it('does not throw an error if a null given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: null,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: null,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a string given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ANY,
|
|
|
|
|
|
|
+ it('does not throw an error if a string given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 'bar',
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 'bar',
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a number given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ANY,
|
|
|
|
|
|
|
+ it('does not throw an error if a number given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 10,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 10,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if true given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ANY,
|
|
|
|
|
|
|
+ it('does not throw an error if true given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: true,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: true,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if false given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ANY,
|
|
|
|
|
|
|
+ it('does not throw an error if false given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: false,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: false,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if an array given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ANY,
|
|
|
|
|
|
|
+ it('does not throw an error if an array given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: [],
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: [],
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if an object given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ANY,
|
|
|
|
|
|
|
+ it('does not throw an error if an object given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ANY,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: {},
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: {},
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- describe('DataType.STRING', function () {
|
|
|
|
|
- describe('ShortPropertyDefinition', function () {
|
|
|
|
|
- it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.STRING,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: undefined,
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a null given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.STRING,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: null,
|
|
|
|
|
|
|
+ describe('DataType.STRING', function () {
|
|
|
|
|
+ describe('ShortPropertyDefinition', function () {
|
|
|
|
|
+ it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: undefined,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a string given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.STRING,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 'bar',
|
|
|
|
|
|
|
+ it('does not throw an error if a null given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: null,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if a number given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.STRING,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 10,
|
|
|
|
|
|
|
+ it('does not throw an error if a string given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 'bar',
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a String, but Number given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if true given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.STRING,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: true,
|
|
|
|
|
|
|
+ it('throws an error if a number given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 10,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a String, but Number given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a String, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if false given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.STRING,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: false,
|
|
|
|
|
|
|
+ it('throws an error if true given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a String, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a String, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an array given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.STRING,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: [],
|
|
|
|
|
|
|
+ it('throws an error if false given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a String, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a String, but Array given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an object given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.STRING,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: {},
|
|
|
|
|
|
|
+ it('throws an error if an array given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: [],
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a String, but Array given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a String, but Object given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- describe('FullPropertyDefinition', function () {
|
|
|
|
|
- it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.STRING,
|
|
|
|
|
|
|
+ it('throws an error if an object given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.STRING,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: undefined,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: {},
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a String, but Object given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('does not throw an error if a null given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.STRING,
|
|
|
|
|
|
|
+ describe('FullPropertyDefinition', function () {
|
|
|
|
|
+ it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: null,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: undefined,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a string given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.STRING,
|
|
|
|
|
|
|
+ it('does not throw an error if a null given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 'bar',
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: null,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if a number given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.STRING,
|
|
|
|
|
|
|
+ it('does not throw an error if a string given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 10,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 'bar',
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a String, but Number given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if true given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.STRING,
|
|
|
|
|
|
|
+ it('throws an error if a number given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: true,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 10,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a String, but Number given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a String, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if false given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.STRING,
|
|
|
|
|
|
|
+ it('throws an error if true given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: false,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a String, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a String, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an array given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.STRING,
|
|
|
|
|
|
|
+ it('throws an error if false given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: [],
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a String, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a String, but Array given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an object given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.STRING,
|
|
|
|
|
|
|
+ it('throws an error if an array given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: {},
|
|
|
|
|
- });
|
|
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a String, but Object given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- describe('DataType.NUMBER', function () {
|
|
|
|
|
- describe('ShortPropertyDefinition', function () {
|
|
|
|
|
- it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.NUMBER,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: undefined,
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('does not throw an error if a null given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.NUMBER,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: null,
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('throws an error if a string given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.NUMBER,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 'bar',
|
|
|
|
|
- });
|
|
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Number, but String given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('does not throw an error if a number given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.NUMBER,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 10,
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('throws an error if true given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.NUMBER,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: true,
|
|
|
|
|
- });
|
|
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Number, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('throws an error if false given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.NUMBER,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: false,
|
|
|
|
|
- });
|
|
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Number, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('throws an error if an array given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.NUMBER,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: [],
|
|
|
|
|
- });
|
|
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Number, but Array given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('throws an error if an object given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.NUMBER,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: {},
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: [],
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a String, but Array given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Number, but Object given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- describe('FullPropertyDefinition', function () {
|
|
|
|
|
- it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.NUMBER,
|
|
|
|
|
|
|
+ it('throws an error if an object given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: undefined,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: {},
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a String, but Object given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- it('does not throw an error if a null given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.NUMBER,
|
|
|
|
|
|
|
+ describe('DataType.NUMBER', function () {
|
|
|
|
|
+ describe('ShortPropertyDefinition', function () {
|
|
|
|
|
+ it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.NUMBER,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: null,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: undefined,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if a string given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.NUMBER,
|
|
|
|
|
|
|
+ it('does not throw an error if a null given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.NUMBER,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 'bar',
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: null,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Number, but String given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a number given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.NUMBER,
|
|
|
|
|
|
|
+ it('throws an error if a string given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.NUMBER,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 10,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 'bar',
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Number, but String given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if true given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.NUMBER,
|
|
|
|
|
|
|
+ it('does not throw an error if a number given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.NUMBER,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: true,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 10,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Number, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if false given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.NUMBER,
|
|
|
|
|
|
|
+ it('throws an error if true given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.NUMBER,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: false,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Number, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Number, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an array given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.NUMBER,
|
|
|
|
|
|
|
+ it('throws an error if false given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.NUMBER,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: [],
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Number, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Number, but Array given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an object given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.NUMBER,
|
|
|
|
|
|
|
+ it('throws an error if an array given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.NUMBER,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: {},
|
|
|
|
|
- });
|
|
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Number, but Object given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- describe('DataType.BOOLEAN', function () {
|
|
|
|
|
- describe('ShortPropertyDefinition', function () {
|
|
|
|
|
- it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.BOOLEAN,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: undefined,
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('does not throw an error if a null given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.BOOLEAN,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: null,
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('throws an error if a string given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.BOOLEAN,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 'bar',
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: [],
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Number, but Array given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Boolean, but String given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if a number given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.BOOLEAN,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 10,
|
|
|
|
|
|
|
+ it('throws an error if an object given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.NUMBER,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: {},
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Number, but Object given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Boolean, but Number given.',
|
|
|
|
|
- );
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('does not throw an error if true given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.BOOLEAN,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: true,
|
|
|
|
|
|
|
+ describe('FullPropertyDefinition', function () {
|
|
|
|
|
+ it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.NUMBER,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: undefined,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if false given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.BOOLEAN,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: false,
|
|
|
|
|
|
|
+ it('does not throw an error if a null given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.NUMBER,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: null,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an array given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.BOOLEAN,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: [],
|
|
|
|
|
|
|
+ it('throws an error if a string given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.NUMBER,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 'bar',
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Number, but String given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Boolean, but Array given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an object given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.BOOLEAN,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: {},
|
|
|
|
|
|
|
+ it('does not throw an error if a number given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.NUMBER,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 10,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Boolean, but Object given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- describe('FullPropertyDefinition', function () {
|
|
|
|
|
- it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.BOOLEAN,
|
|
|
|
|
|
|
+ it('throws an error if true given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.NUMBER,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: undefined,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Number, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a null given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.BOOLEAN,
|
|
|
|
|
|
|
+ it('throws an error if false given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.NUMBER,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: null,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Number, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if a string given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.BOOLEAN,
|
|
|
|
|
|
|
+ it('throws an error if an array given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.NUMBER,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: [],
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Number, but Array given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 'bar',
|
|
|
|
|
|
|
+
|
|
|
|
|
+ it('throws an error if an object given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.NUMBER,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: {},
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Number, but Object given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Boolean, but String given.',
|
|
|
|
|
- );
|
|
|
|
|
});
|
|
});
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- it('throws an error if a number given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.BOOLEAN,
|
|
|
|
|
|
|
+ describe('DataType.BOOLEAN', function () {
|
|
|
|
|
+ describe('ShortPropertyDefinition', function () {
|
|
|
|
|
+ it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.BOOLEAN,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 10,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: undefined,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Boolean, but Number given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if true given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.BOOLEAN,
|
|
|
|
|
|
|
+ it('does not throw an error if a null given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.BOOLEAN,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: null,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: true,
|
|
|
|
|
|
|
+
|
|
|
|
|
+ it('throws an error if a string given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.BOOLEAN,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 'bar',
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Boolean, but String given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if false given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.BOOLEAN,
|
|
|
|
|
|
|
+ it('throws an error if a number given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.BOOLEAN,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 10,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Boolean, but Number given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: false,
|
|
|
|
|
|
|
+
|
|
|
|
|
+ it('does not throw an error if true given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.BOOLEAN,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: true,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an array given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.BOOLEAN,
|
|
|
|
|
|
|
+ it('does not throw an error if false given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.BOOLEAN,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: [],
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: false,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Boolean, but Array given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an object given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.BOOLEAN,
|
|
|
|
|
|
|
+ it('throws an error if an array given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.BOOLEAN,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: {},
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: [],
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Boolean, but Array given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'a Boolean, but Object given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- describe('DataType.ARRAY', function () {
|
|
|
|
|
- describe('ShortPropertyDefinition', function () {
|
|
|
|
|
- it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ARRAY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: undefined,
|
|
|
|
|
|
|
+ it('throws an error if an object given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.BOOLEAN,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: {},
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Boolean, but Object given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('does not throw an error if a null given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ARRAY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: null,
|
|
|
|
|
|
|
+ describe('FullPropertyDefinition', function () {
|
|
|
|
|
+ it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.BOOLEAN,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: undefined,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if a string given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ARRAY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 'bar',
|
|
|
|
|
|
|
+ it('does not throw an error if a null given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.BOOLEAN,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: null,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Array, but String given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if a number given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ARRAY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 10,
|
|
|
|
|
|
|
+ it('throws an error if a string given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.BOOLEAN,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 'bar',
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Boolean, but String given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Array, but Number given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if true given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ARRAY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: true,
|
|
|
|
|
|
|
+ it('throws an error if a number given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.BOOLEAN,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 10,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Boolean, but Number given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Array, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if false given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ARRAY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: false,
|
|
|
|
|
|
|
+ it('does not throw an error if true given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.BOOLEAN,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: true,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Array, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if an array given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ARRAY,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: [],
|
|
|
|
|
|
|
+ it('does not throw an error if false given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.BOOLEAN,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: false,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an object given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.ARRAY,
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ it('throws an error if an array given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.BOOLEAN,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: [],
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Boolean, but Array given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: {},
|
|
|
|
|
|
|
+
|
|
|
|
|
+ it('throws an error if an object given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.BOOLEAN,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: {},
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'a Boolean, but Object given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Array, but Object given.',
|
|
|
|
|
- );
|
|
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describe('FullPropertyDefinition', function () {
|
|
|
|
|
- it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ARRAY,
|
|
|
|
|
|
|
+ describe('DataType.ARRAY', function () {
|
|
|
|
|
+ describe('ShortPropertyDefinition', function () {
|
|
|
|
|
+ it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ARRAY,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: undefined,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: undefined,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a null given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ARRAY,
|
|
|
|
|
|
|
+ it('does not throw an error if a null given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ARRAY,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: null,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: null,
|
|
|
|
|
|
|
+
|
|
|
|
|
+ it('throws an error if a string given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ARRAY,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 'bar',
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Array, but String given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if a string given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ARRAY,
|
|
|
|
|
|
|
+ it('throws an error if a number given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ARRAY,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 'bar',
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 10,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Array, but Number given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Array, but String given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if a number given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ARRAY,
|
|
|
|
|
|
|
+ it('throws an error if true given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ARRAY,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 10,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Array, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Array, but Number given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if true given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ARRAY,
|
|
|
|
|
|
|
+ it('throws an error if false given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ARRAY,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: true,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Array, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Array, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if false given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ARRAY,
|
|
|
|
|
|
|
+ it('does not throw an error if an array given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ARRAY,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: false,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: [],
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Array, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if an array given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ARRAY,
|
|
|
|
|
|
|
+ it('throws an error if an object given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.ARRAY,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: [],
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: {},
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Array, but Object given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('throws an error if an object given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.ARRAY,
|
|
|
|
|
|
|
+ describe('FullPropertyDefinition', function () {
|
|
|
|
|
+ it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ARRAY,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: {},
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: undefined,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Array, but Object given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- describe('the "model" option', function () {
|
|
|
|
|
- it('throws an error when the given object element has an invalid model', async function () {
|
|
|
|
|
|
|
+ it('does not throw an error if a null given', async function () {
|
|
|
const S = new Schema();
|
|
const S = new Schema();
|
|
|
S.defineModel({
|
|
S.defineModel({
|
|
|
- name: 'modelA',
|
|
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
properties: {
|
|
properties: {
|
|
|
- foo: DataType.STRING,
|
|
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ARRAY,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: null,
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('throws an error if a string given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
S.defineModel({
|
|
S.defineModel({
|
|
|
- name: 'modelB',
|
|
|
|
|
|
|
+ name: 'model',
|
|
|
datasource: 'datasource',
|
|
datasource: 'datasource',
|
|
|
properties: {
|
|
properties: {
|
|
|
- bar: {
|
|
|
|
|
|
|
+ foo: {
|
|
|
type: DataType.ARRAY,
|
|
type: DataType.ARRAY,
|
|
|
- itemType: DataType.OBJECT,
|
|
|
|
|
- model: 'modelA',
|
|
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
- const promise = S.getService(ModelDataValidator).validate(
|
|
|
|
|
- 'modelB',
|
|
|
|
|
- {
|
|
|
|
|
- bar: [{foo: 10}],
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 'bar',
|
|
|
|
|
+ });
|
|
|
await expect(promise).to.be.rejectedWith(
|
|
await expect(promise).to.be.rejectedWith(
|
|
|
- 'The property "foo" of the model "modelA" must have ' +
|
|
|
|
|
- 'a String, but Number given.',
|
|
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Array, but String given.',
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('does not throw an error when the given object element has a valid model', async function () {
|
|
|
|
|
|
|
+ it('throws an error if a number given', async function () {
|
|
|
const S = new Schema();
|
|
const S = new Schema();
|
|
|
S.defineModel({
|
|
S.defineModel({
|
|
|
- name: 'modelA',
|
|
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
properties: {
|
|
properties: {
|
|
|
- foo: DataType.STRING,
|
|
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ARRAY,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 10,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Array, but Number given.',
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('throws an error if true given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
S.defineModel({
|
|
S.defineModel({
|
|
|
- name: 'modelB',
|
|
|
|
|
|
|
+ name: 'model',
|
|
|
datasource: 'datasource',
|
|
datasource: 'datasource',
|
|
|
properties: {
|
|
properties: {
|
|
|
- bar: {
|
|
|
|
|
|
|
+ foo: {
|
|
|
type: DataType.ARRAY,
|
|
type: DataType.ARRAY,
|
|
|
- itemType: DataType.OBJECT,
|
|
|
|
|
- model: 'modelA',
|
|
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
- await S.getService(ModelDataValidator).validate('modelB', {
|
|
|
|
|
- bar: [{foo: '10'}],
|
|
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: true,
|
|
|
});
|
|
});
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Array, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- describe('DataType.OBJECT', function () {
|
|
|
|
|
- describe('ShortPropertyDefinition', function () {
|
|
|
|
|
- it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.OBJECT,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: undefined,
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('does not throw an error if a null given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.OBJECT,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: null,
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('throws an error if a string given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.OBJECT,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 'bar',
|
|
|
|
|
- });
|
|
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Object, but String given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if a number given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.OBJECT,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 10,
|
|
|
|
|
|
|
+ it('throws an error if false given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ARRAY,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Array, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Object, but Number given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if true given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.OBJECT,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: true,
|
|
|
|
|
|
|
+ it('does not throw an error if an array given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ARRAY,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: [],
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Object, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if false given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.OBJECT,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: false,
|
|
|
|
|
|
|
+ it('throws an error if an object given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.ARRAY,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: {},
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Array, but Object given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Object, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an array given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.OBJECT,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: [],
|
|
|
|
|
- });
|
|
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Object, but Array given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ describe('the "model" option', function () {
|
|
|
|
|
+ it('throws an error when the given object element has an invalid model', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'modelA',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'modelB',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ bar: {
|
|
|
|
|
+ type: DataType.ARRAY,
|
|
|
|
|
+ itemType: DataType.OBJECT,
|
|
|
|
|
+ model: 'modelA',
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate(
|
|
|
|
|
+ 'modelB',
|
|
|
|
|
+ {
|
|
|
|
|
+ bar: [{foo: 10}],
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "modelA" must have ' +
|
|
|
|
|
+ 'a String, but Number given.',
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- it('does not throw an error if an object given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: DataType.OBJECT,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: {},
|
|
|
|
|
|
|
+ it('does not throw an error when the given object element has a valid model', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'modelA',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'modelB',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ bar: {
|
|
|
|
|
+ type: DataType.ARRAY,
|
|
|
|
|
+ itemType: DataType.OBJECT,
|
|
|
|
|
+ model: 'modelA',
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('modelB', {
|
|
|
|
|
+ bar: [{foo: '10'}],
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describe('FullPropertyDefinition', function () {
|
|
|
|
|
- it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.OBJECT,
|
|
|
|
|
|
|
+ describe('DataType.OBJECT', function () {
|
|
|
|
|
+ describe('ShortPropertyDefinition', function () {
|
|
|
|
|
+ it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.OBJECT,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: undefined,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: undefined,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('does not throw an error if a null given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.OBJECT,
|
|
|
|
|
|
|
+ it('does not throw an error if a null given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.OBJECT,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: null,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: null,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if a string given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.OBJECT,
|
|
|
|
|
|
|
+ it('throws an error if a string given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.OBJECT,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 'bar',
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 'bar',
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Object, but String given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Object, but String given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if a number given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.OBJECT,
|
|
|
|
|
|
|
+ it('throws an error if a number given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.OBJECT,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: 10,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 10,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Object, but Number given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Object, but Number given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if true given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.OBJECT,
|
|
|
|
|
|
|
+ it('throws an error if true given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.OBJECT,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: true,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Object, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Object, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if false given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.OBJECT,
|
|
|
|
|
|
|
+ it('throws an error if false given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.OBJECT,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: false,
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Object, but Boolean given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Object, but Boolean given.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- it('throws an error if an array given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.OBJECT,
|
|
|
|
|
|
|
+ it('throws an error if an array given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.OBJECT,
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: [],
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Object, but Array given.',
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
- const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: [],
|
|
|
|
|
|
|
+
|
|
|
|
|
+ it('does not throw an error if an object given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.OBJECT,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: {},
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await expect(promise).to.be.rejectedWith(
|
|
|
|
|
- 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
- 'an Object, but Array given.',
|
|
|
|
|
- );
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('does not throw an error if an object given', async function () {
|
|
|
|
|
- const S = new Schema();
|
|
|
|
|
- S.defineModel({
|
|
|
|
|
- name: 'model',
|
|
|
|
|
- datasource: 'datasource',
|
|
|
|
|
- properties: {
|
|
|
|
|
- foo: {
|
|
|
|
|
- type: DataType.OBJECT,
|
|
|
|
|
|
|
+ describe('FullPropertyDefinition', function () {
|
|
|
|
|
+ it('does not throw an error if an undefined given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.OBJECT,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: undefined,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
- foo: {},
|
|
|
|
|
|
|
+
|
|
|
|
|
+ it('does not throw an error if a null given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.OBJECT,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: null,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- describe('the "model" option', function () {
|
|
|
|
|
- it('throws an error when the given object has an invalid model', async function () {
|
|
|
|
|
|
|
+ it('throws an error if a string given', async function () {
|
|
|
const S = new Schema();
|
|
const S = new Schema();
|
|
|
S.defineModel({
|
|
S.defineModel({
|
|
|
- name: 'modelA',
|
|
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
properties: {
|
|
properties: {
|
|
|
- foo: DataType.STRING,
|
|
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.OBJECT,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 'bar',
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Object, but String given.',
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('throws an error if a number given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
S.defineModel({
|
|
S.defineModel({
|
|
|
- name: 'modelB',
|
|
|
|
|
|
|
+ name: 'model',
|
|
|
datasource: 'datasource',
|
|
datasource: 'datasource',
|
|
|
properties: {
|
|
properties: {
|
|
|
- bar: {
|
|
|
|
|
|
|
+ foo: {
|
|
|
type: DataType.OBJECT,
|
|
type: DataType.OBJECT,
|
|
|
- model: 'modelA',
|
|
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
- const promise = S.getService(ModelDataValidator).validate(
|
|
|
|
|
- 'modelB',
|
|
|
|
|
- {
|
|
|
|
|
- bar: {foo: 10},
|
|
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: 10,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Object, but Number given.',
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('throws an error if true given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.OBJECT,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Object, but Boolean given.',
|
|
|
);
|
|
);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('throws an error if false given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.OBJECT,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: false,
|
|
|
|
|
+ });
|
|
|
await expect(promise).to.be.rejectedWith(
|
|
await expect(promise).to.be.rejectedWith(
|
|
|
- 'The property "foo" of the model "modelA" must have ' +
|
|
|
|
|
- 'a String, but Number given.',
|
|
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Object, but Boolean given.',
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('does not throw an error when the given object has a valid model', async function () {
|
|
|
|
|
|
|
+ it('throws an error if an array given', async function () {
|
|
|
const S = new Schema();
|
|
const S = new Schema();
|
|
|
S.defineModel({
|
|
S.defineModel({
|
|
|
- name: 'modelA',
|
|
|
|
|
|
|
+ name: 'model',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
properties: {
|
|
properties: {
|
|
|
- foo: DataType.STRING,
|
|
|
|
|
|
|
+ foo: {
|
|
|
|
|
+ type: DataType.OBJECT,
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: [],
|
|
|
|
|
+ });
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "model" must have ' +
|
|
|
|
|
+ 'an Object, but Array given.',
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('does not throw an error if an object given', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
S.defineModel({
|
|
S.defineModel({
|
|
|
- name: 'modelB',
|
|
|
|
|
|
|
+ name: 'model',
|
|
|
datasource: 'datasource',
|
|
datasource: 'datasource',
|
|
|
properties: {
|
|
properties: {
|
|
|
- bar: {
|
|
|
|
|
|
|
+ foo: {
|
|
|
type: DataType.OBJECT,
|
|
type: DataType.OBJECT,
|
|
|
- model: 'modelA',
|
|
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
- await S.getService(ModelDataValidator).validate('modelB', {
|
|
|
|
|
- bar: {foo: '10'},
|
|
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('model', {
|
|
|
|
|
+ foo: {},
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ describe('the "model" option', function () {
|
|
|
|
|
+ it('throws an error when the given object has an invalid model', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'modelA',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'modelB',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ bar: {
|
|
|
|
|
+ type: DataType.OBJECT,
|
|
|
|
|
+ model: 'modelA',
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const promise = S.getService(ModelDataValidator).validate(
|
|
|
|
|
+ 'modelB',
|
|
|
|
|
+ {
|
|
|
|
|
+ bar: {foo: 10},
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
+ await expect(promise).to.be.rejectedWith(
|
|
|
|
|
+ 'The property "foo" of the model "modelA" must have ' +
|
|
|
|
|
+ 'a String, but Number given.',
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('does not throw an error when the given object has a valid model', async function () {
|
|
|
|
|
+ const S = new Schema();
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'modelA',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ foo: DataType.STRING,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ S.defineModel({
|
|
|
|
|
+ name: 'modelB',
|
|
|
|
|
+ datasource: 'datasource',
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ bar: {
|
|
|
|
|
+ type: DataType.OBJECT,
|
|
|
|
|
+ model: 'modelA',
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await S.getService(ModelDataValidator).validate('modelB', {
|
|
|
|
|
+ bar: {foo: '10'},
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|