45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
|
|
describe('sale recalculatePrice()', () => {
|
|
const ctx = beforeAll.getCtx();
|
|
it('should update the sale price', async() => {
|
|
const tx = await models.Sale.beginTransaction({});
|
|
const sales = [
|
|
{id: 7, ticketFk: 11},
|
|
{id: 8, ticketFk: 11}
|
|
];
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const response = await models.Sale.recalculatePrice(ctx, sales, options);
|
|
|
|
expect(response[0].affectedRows).toBeDefined();
|
|
expect(response[1].affectedRows).toBeDefined();
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
|
|
it('should throw an error if the ticket is not editable', async() => {
|
|
const tx = await models.Sale.beginTransaction({});
|
|
|
|
let error;
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const immutableSale = [{id: 1, ticketFk: 1}];
|
|
await models.Sale.recalculatePrice(ctx, immutableSale, options);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
error = e;
|
|
}
|
|
|
|
expect(error).toEqual(new Error(`The sales of this ticket can't be modified`));
|
|
});
|
|
});
|