salix/modules/order/back/methods/order-row/specs/addToOrder.spec.js

38 lines
1.1 KiB
JavaScript

const models = require('vn-loopback/server/server').models;
describe('order addToOrder()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
const orderId = 8;
it('should add a row to a given order', async() => {
const tx = await models.Order.beginTransaction({});
try {
const options = {transaction: tx};
const unmodifiedRows = await models.OrderRow.find({where: {orderFk: orderId}}, options);
expect(unmodifiedRows.length).toBe(2);
const params = {
orderFk: orderId,
items: [{
itemFk: 1,
quantity: 10,
warehouseFk: 1
}]
};
await models.OrderRow.addToOrder(ctx, params, options);
const modifiedRows = await models.OrderRow.find({where: {orderFk: orderId}}, options);
expect(modifiedRows.length).toBe(3);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});