2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2018-10-22 07:29:58 +00:00
|
|
|
|
2018-10-22 07:30:21 +00:00
|
|
|
describe('Model crud()', () => {
|
2018-10-22 07:29:58 +00:00
|
|
|
let insertId;
|
|
|
|
let ItemBarcode = app.models.ItemBarcode;
|
|
|
|
|
|
|
|
it('should inherit crud method from VnModel', () => {
|
|
|
|
expect(ItemBarcode.crud).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2018-11-02 14:44:27 +00:00
|
|
|
it('should create a new instance', async () => {
|
2018-10-22 07:29:58 +00:00
|
|
|
let data = {code: '500', itemFk: '1'};
|
2018-11-02 14:44:27 +00:00
|
|
|
let creates = [data];
|
2018-10-22 07:29:58 +00:00
|
|
|
|
2018-11-02 14:44:27 +00:00
|
|
|
await ItemBarcode.crud(null, null, creates);
|
2018-10-22 07:29:58 +00:00
|
|
|
let instance = await ItemBarcode.findOne({where: data});
|
|
|
|
insertId = instance.id;
|
|
|
|
|
|
|
|
expect(instance).not.toEqual(null);
|
|
|
|
expect(instance.code).toEqual('500');
|
|
|
|
});
|
|
|
|
|
2018-11-02 14:44:27 +00:00
|
|
|
it('should update the instance', async () => {
|
|
|
|
let updates = [{
|
|
|
|
where: {id: insertId},
|
|
|
|
data: {code: '501', itemFk: 1}
|
|
|
|
}];
|
|
|
|
|
|
|
|
await ItemBarcode.crud(null, updates);
|
2018-10-22 07:29:58 +00:00
|
|
|
let instance = await ItemBarcode.findById(insertId);
|
|
|
|
|
|
|
|
expect(instance.code).toEqual('501');
|
|
|
|
});
|
|
|
|
|
2018-11-02 14:44:27 +00:00
|
|
|
it('should delete the created instance', async () => {
|
|
|
|
let deletes = [insertId];
|
|
|
|
await ItemBarcode.crud(deletes);
|
2018-10-22 07:29:58 +00:00
|
|
|
let instance = await ItemBarcode.findById(insertId);
|
|
|
|
|
|
|
|
expect(instance).toEqual(null);
|
|
|
|
});
|
|
|
|
});
|