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

40 lines
1.2 KiB
JavaScript

const app = require('vn-loopback/server/server');
describe('Model crud()', () => {
beforeAll.mockLoopBackContext();
let insertId;
const barcodeModel = app.models.ItemBarcode;
it('should inherit crud method from VnModel', () => {
expect(barcodeModel.crud).toBeDefined();
});
it('should create, edit and delete an instance', async() => {
let barcodeData = {code: '500', itemFk: '1'};
let creates = [barcodeData];
await barcodeModel.crud(null, null, creates);
let instance = await barcodeModel.findOne({where: barcodeData});
insertId = instance.id;
expect(instance).not.toEqual(null);
expect(instance.code).toEqual('500');
let updates = [{
where: {id: insertId},
data: {code: '501', itemFk: 1}
}];
await barcodeModel.crud(null, updates);
let editedInstance = await barcodeModel.findById(insertId);
expect(editedInstance.code).toEqual('501');
let deletes = [insertId];
await barcodeModel.crud(deletes);
let deletedInstance = await barcodeModel.findById(insertId);
expect(deletedInstance).toEqual(null);
});
});