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'}; 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); }); });