2021-09-29 06:27:18 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2019-11-14 13:19:39 +00:00
|
|
|
|
2019-11-21 11:00:56 +00:00
|
|
|
describe('sale recalculatePrice()', () => {
|
2024-06-14 06:39:57 +00:00
|
|
|
const ctx = beforeAll.getCtx();
|
2019-11-14 13:19:39 +00:00
|
|
|
it('should update the sale price', async() => {
|
2021-09-29 06:27:18 +00:00
|
|
|
const tx = await models.Sale.beginTransaction({});
|
2021-11-30 12:47:16 +00:00
|
|
|
const sales = [
|
|
|
|
{id: 7, ticketFk: 11},
|
|
|
|
{id: 8, ticketFk: 11}
|
|
|
|
];
|
2021-09-29 06:27:18 +00:00
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
2021-11-30 12:47:16 +00:00
|
|
|
const response = await models.Sale.recalculatePrice(ctx, sales, options);
|
2021-09-29 06:27:18 +00:00
|
|
|
|
2021-11-30 12:47:16 +00:00
|
|
|
expect(response[0].affectedRows).toBeDefined();
|
|
|
|
expect(response[1].affectedRows).toBeDefined();
|
2021-09-29 06:27:18 +00:00
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
2019-11-14 13:19:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error if the ticket is not editable', async() => {
|
2021-09-29 06:27:18 +00:00
|
|
|
const tx = await models.Sale.beginTransaction({});
|
|
|
|
|
|
|
|
let error;
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
2021-11-30 12:47:16 +00:00
|
|
|
const immutableSale = [{id: 1, ticketFk: 1}];
|
|
|
|
await models.Sale.recalculatePrice(ctx, immutableSale, options);
|
2021-09-29 06:27:18 +00:00
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toEqual(new Error(`The sales of this ticket can't be modified`));
|
2019-11-14 13:19:39 +00:00
|
|
|
});
|
|
|
|
});
|