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()', () => {
|
2019-06-14 10:27:41 +00:00
|
|
|
const orderId = 8;
|
2018-10-24 12:10:08 +00:00
|
|
|
let rowToDelete;
|
2021-10-15 12:45:41 +00:00
|
|
|
afterAll(async() => {
|
2019-06-14 10:27:41 +00:00
|
|
|
await app.models.OrderRow.removes({rows: [rowToDelete], actualOrderId: orderId});
|
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-06-14 10:27:41 +00:00
|
|
|
let unmodifiedRows = await app.models.OrderRow.find({where: {orderFk: orderId}});
|
2018-10-15 09:29:17 +00:00
|
|
|
|
2019-06-14 10:27:41 +00:00
|
|
|
expect(unmodifiedRows.length).toBe(2);
|
2018-10-15 09:29:17 +00:00
|
|
|
|
|
|
|
let params = {
|
2019-06-14 10:27:41 +00:00
|
|
|
orderFk: orderId,
|
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-06-14 10:27:41 +00:00
|
|
|
let modifiedRows = await app.models.OrderRow.find({where: {orderFk: orderId}});
|
2018-10-15 09:29:17 +00:00
|
|
|
|
2018-10-24 12:10:08 +00:00
|
|
|
rowToDelete = modifiedRows[modifiedRows.length - 1].id;
|
|
|
|
|
2019-06-14 10:27:41 +00:00
|
|
|
expect(modifiedRows.length).toBe(3);
|
2018-10-15 09:29:17 +00:00
|
|
|
});
|
|
|
|
});
|