2018-10-22 07:29:58 +00:00
|
|
|
const app = require('../../../../../item/server/server');
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|