salix/services/loopback/common/methods/vn-model/specs/installCrudModel.spec.js

61 lines
2.0 KiB
JavaScript

const app = require('../../../../../item/server/server');
describe('Model installCrudModel()', () => {
it('should extend installCrudModel properties to any model passed', () => {
let exampleModel = app.models.ItemBarcode;
expect(exampleModel.installCrudModel).toBeDefined();
});
describe('installCrudModel()', () => {
it('should create a new remothed method', () => {
let exampleModel = app.models.ItemBarcode;
exampleModel.installCrudModel('crudItemBarcodes');
expect(exampleModel.crudItemBarcodes).toBeDefined();
});
});
describe('ItemBarcode crudMethod()', () => {
let createdId;
it('should create a new barcode', async() => {
crudObject = {
create: [{code: '500', itemFk: '1'}],
update: [],
delete: []
};
await app.models.ItemBarcode.crudItemBarcodes(crudObject);
let result = await app.models.ItemBarcode.find({where: {itemFk: 1}});
createdId = result[3].id;
expect(result[3].code).toEqual('500');
expect(result.length).toEqual(4);
});
it('should update a barcode', async() => {
crudObject = {
create: [],
update: [{id: createdId, code: '501', itemFk: 1}],
delete: []
};
await app.models.ItemBarcode.crudItemBarcodes(crudObject);
let result = await app.models.ItemBarcode.find({where: {itemFk: 1}});
expect(result[3].code).toEqual('501');
expect(result.length).toEqual(4);
});
it('should delete a barcode', async() => {
crudObject = {
create: [],
update: [],
delete: [createdId]
};
await app.models.ItemBarcode.crudItemBarcodes(crudObject);
let result = await app.models.ItemBarcode.find({where: {itemFk: 1}});
expect(result.length).toEqual(3);
});
});
});