salix/services/loopback/common/methods/vnModel/specs/installCrudModel.spec.js

61 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-02-27 13:55:59 +00:00
const app = require('../../../../../item/server/server');
describe('Model installCrudModel()', () => {
it('should extend installCrudModel properties to any model passed', () => {
let exampleModel = app.models.ItemBarcode;
2018-02-27 13:55:59 +00:00
expect(exampleModel.installCrudModel).toBeDefined();
2018-02-27 13:55:59 +00:00
});
describe('installCrudModel()', () => {
it('should create a new remothed method', () => {
let exampleModel = app.models.ItemBarcode;
exampleModel.installCrudModel('crudItemBarcodes');
2018-02-27 13:55:59 +00:00
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);
});
2018-02-27 13:55:59 +00:00
});
});