2021-12-15 14:29:22 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2018-10-15 09:29:17 +00:00
|
|
|
|
|
|
|
describe('order addToOrder()', () => {
|
2023-06-01 06:32:06 +00:00
|
|
|
const ctx = {req: {accessToken: {userId: 9}}};
|
2019-06-14 10:27:41 +00:00
|
|
|
const orderId = 8;
|
2018-10-15 09:29:17 +00:00
|
|
|
it('should add a row to a given order', async() => {
|
2021-12-15 14:29:22 +00:00
|
|
|
const tx = await models.Order.beginTransaction({});
|
|
|
|
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
const unmodifiedRows = await models.OrderRow.find({where: {orderFk: orderId}}, options);
|
2018-10-15 09:29:17 +00:00
|
|
|
|
2021-12-15 14:29:22 +00:00
|
|
|
expect(unmodifiedRows.length).toBe(2);
|
2018-10-15 09:29:17 +00:00
|
|
|
|
2021-12-15 14:29:22 +00:00
|
|
|
const params = {
|
|
|
|
orderFk: orderId,
|
|
|
|
items: [{
|
|
|
|
itemFk: 1,
|
|
|
|
quantity: 10,
|
|
|
|
warehouseFk: 1
|
|
|
|
}]
|
|
|
|
};
|
2018-10-15 09:29:17 +00:00
|
|
|
|
2023-06-01 06:32:06 +00:00
|
|
|
await models.OrderRow.addToOrder(ctx, params, options);
|
2018-10-15 09:29:17 +00:00
|
|
|
|
2021-12-15 14:29:22 +00:00
|
|
|
const modifiedRows = await models.OrderRow.find({where: {orderFk: orderId}}, options);
|
2018-10-15 09:29:17 +00:00
|
|
|
|
2021-12-15 14:29:22 +00:00
|
|
|
expect(modifiedRows.length).toBe(3);
|
2018-10-24 12:10:08 +00:00
|
|
|
|
2021-12-15 14:29:22 +00:00
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
2018-10-15 09:29:17 +00:00
|
|
|
});
|
|
|
|
});
|