2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2018-10-15 09:29:17 +00:00
|
|
|
|
|
|
|
describe('order addToOrder()', () => {
|
2018-10-24 12:10:08 +00:00
|
|
|
let rowToDelete;
|
|
|
|
afterAll(async() => {
|
2019-02-13 12:19:15 +00:00
|
|
|
await app.models.OrderRow.removes({rows: [rowToDelete], actualOrderId: 20});
|
2018-10-24 12:10:08 +00:00
|
|
|
});
|
|
|
|
|
2018-10-15 09:29:17 +00:00
|
|
|
it('should add a row to a given order', async() => {
|
2019-02-13 12:19:15 +00:00
|
|
|
let unmodifiedRows = await app.models.OrderRow.find({where: {orderFk: 20}});
|
2018-10-15 09:29:17 +00:00
|
|
|
|
2019-02-13 12:19:15 +00:00
|
|
|
expect(unmodifiedRows.length).toBe(1);
|
2018-10-15 09:29:17 +00:00
|
|
|
|
|
|
|
let params = {
|
2019-02-13 12:19:15 +00:00
|
|
|
orderFk: 20,
|
2018-10-15 09:29:17 +00:00
|
|
|
items: [{
|
|
|
|
itemFk: 1,
|
2019-02-15 12:26:49 +00:00
|
|
|
quantity: 10,
|
2018-10-15 09:29:17 +00:00
|
|
|
warehouseFk: 1
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
await app.models.OrderRow.addToOrder(params);
|
|
|
|
|
2019-02-13 12:19:15 +00:00
|
|
|
let modifiedRows = await app.models.OrderRow.find({where: {orderFk: 20}});
|
2018-10-15 09:29:17 +00:00
|
|
|
|
2018-10-24 12:10:08 +00:00
|
|
|
rowToDelete = modifiedRows[modifiedRows.length - 1].id;
|
|
|
|
|
2019-02-13 12:19:15 +00:00
|
|
|
expect(modifiedRows.length).toBe(2);
|
2018-10-15 09:29:17 +00:00
|
|
|
});
|
|
|
|
});
|