52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
|
|
describe('sale deleteSales()', () => {
|
|
const ctx = beforeAll.getCtx();
|
|
beforeAll.mockLoopBackContext();
|
|
|
|
it('should throw an error if the ticket of the given sales is not editable', async() => {
|
|
const tx = await models.Sale.beginTransaction({});
|
|
|
|
let error;
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const sales = [{id: 1, instance: 0}, {id: 2, instance: 1}];
|
|
const ticketId = 2;
|
|
|
|
await models.Sale.deleteSales(ctx, sales, ticketId, 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`));
|
|
});
|
|
|
|
it('should delete the sale', async() => {
|
|
const tx = await models.Sale.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const sale = await models.Sale.findOne({where: {id: 9}}, options);
|
|
sale.id = null;
|
|
const newSale = await models.Sale.create(sale, options);
|
|
|
|
const sales = [{id: newSale.id, instance: 0}];
|
|
const ticketId = 16;
|
|
|
|
const deletions = await models.Sale.deleteSales(ctx, sales, ticketId, options);
|
|
|
|
expect(deletions).toEqual([{count: 1}]);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
});
|