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()', () => {
|
2019-11-14 13:19:39 +00:00
|
|
|
const saleId = 7;
|
|
|
|
|
|
|
|
it('should update the sale price', async() => {
|
2021-09-29 06:27:18 +00:00
|
|
|
const tx = await models.Sale.beginTransaction({});
|
2019-11-14 13:19:39 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
const ctx = {req: {accessToken: {userId: 9}}};
|
|
|
|
const response = await models.Sale.recalculatePrice(ctx, saleId, options);
|
|
|
|
|
|
|
|
expect(response.affectedRows).toBeDefined();
|
|
|
|
|
|
|
|
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};
|
|
|
|
|
|
|
|
const ctx = {req: {accessToken: {userId: 9}}};
|
|
|
|
const immutableSaleId = 1;
|
|
|
|
await models.Sale.recalculatePrice(ctx, immutableSaleId, 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`));
|
2019-11-14 13:19:39 +00:00
|
|
|
});
|
|
|
|
});
|