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

43 lines
1.2 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;
let ItemBarcode = app.models.ItemBarcode;
it('should inherit crud method from VnModel', () => {
expect(ItemBarcode.crud).toBeDefined();
});
it('should create a new instance', async() => {
let data = {code: '500', itemFk: '1'};
let creates = [data];
await ItemBarcode.crud(null, null, creates);
let instance = await ItemBarcode.findOne({where: data});
insertId = instance.id;
expect(instance).not.toEqual(null);
expect(instance.code).toEqual('500');
});
it('should update the instance', async() => {
let updates = [{
where: {id: insertId},
data: {code: '501', itemFk: 1}
}];
await ItemBarcode.crud(null, updates);
let instance = await ItemBarcode.findById(insertId);
expect(instance.code).toEqual('501');
});
it('should delete the created instance', async() => {
let deletes = [insertId];
await ItemBarcode.crud(deletes);
let instance = await ItemBarcode.findById(insertId);
expect(instance).toEqual(null);
});
});