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

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-01-24 08:08:28 +00:00
const app = require('vn-loopback/server/server');
2018-10-22 07:30:21 +00:00
describe('Model crud()', () => {
let insertId;
2020-10-06 08:15:27 +00:00
const barcodeModel = app.models.ItemBarcode;
it('should inherit crud method from VnModel', () => {
2020-10-06 08:15:27 +00:00
expect(barcodeModel.crud).toBeDefined();
});
2020-10-06 08:15:27 +00:00
it('should create, edit and delete an instance', async() => {
let barcodeData = {code: '500', itemFk: '1'};
let creates = [barcodeData];
2020-10-06 08:15:27 +00:00
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}
}];
2020-10-06 08:15:27 +00:00
await barcodeModel.crud(null, updates);
let editedInstance = await barcodeModel.findById(insertId);
2020-10-06 08:15:27 +00:00
expect(editedInstance.code).toEqual('501');
let deletes = [insertId];
2020-10-06 08:15:27 +00:00
await barcodeModel.crud(deletes);
let deletedInstance = await barcodeModel.findById(insertId);
2020-10-06 08:15:27 +00:00
expect(deletedInstance).toEqual(null);
});
});