const app = require('../../../../../item/server/server'); 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'}; crudObject = { create: [data] }; await ItemBarcode.crud(crudObject); 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() => { crudObject = { update: [{ where: {id: insertId}, data: {code: '501', itemFk: 1} }] }; await ItemBarcode.crud(crudObject); let instance = await ItemBarcode.findById(insertId); expect(instance.code).toEqual('501'); }); it('should delete the created instance', async() => { crudObject = { delete: [insertId] }; await ItemBarcode.crud(crudObject); let instance = await ItemBarcode.findById(insertId); expect(instance).toEqual(null); }); });