Alexandre Bodin 919aae2211 Fix unit tests
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
2020-07-08 10:21:28 +02:00

79 lines
1.6 KiB
JavaScript

const { getNature } = require('../models');
describe('getNature', () => {
describe('oneWay', () => {
test('oneWay', () => {
global.strapi = {
models: {
baseModel: {
attributes: {
test: {
model: 'modelName',
},
},
},
modelName: {},
},
db: {
getModelsByPluginName() {
return strapi.models;
},
},
plugins: {},
};
const nature = getNature({
attribute: global.strapi.models.baseModel.attributes.test,
attributeName: 'test',
modelName: 'baseModel',
});
expect(nature).toEqual({
nature: 'oneWay',
verbose: 'belongsTo',
});
});
});
describe('oneToOne', () => {
test('oneToOne', () => {
global.strapi = {
models: {
baseModel: {
attributes: {
test: {
model: 'modelName',
via: 'reverseAttribute',
},
},
},
modelName: {
attributes: {
reverseAttribute: {
model: 'baseModel',
},
},
},
},
db: {
getModelsByPluginName() {
return strapi.models;
},
},
plugins: {},
};
const nature = getNature({
attribute: global.strapi.models.baseModel.attributes.test,
attributeName: 'test',
modelName: 'baseModel',
});
expect(nature).toEqual({
nature: 'oneToOne',
verbose: 'belongsTo',
});
});
});
});