salix/modules/ticket/back/methods/sale/specs/deleteSales.spec.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-01-24 08:08:28 +00:00
const app = require('vn-loopback/server/server');
describe('sale deleteSales()', () => {
let sale;
2020-10-08 14:00:19 +00:00
let newSale;
beforeAll(async done => {
2020-10-15 16:57:27 +00:00
try {
sale = await app.models.Sale.findOne({where: {id: 9}});
sale.id = null;
newSale = await app.models.Sale.create(sale);
} catch (error) {
console.error(error);
}
done();
});
it('should throw an error if the ticket of the given sales is not editable', async() => {
2019-07-22 11:14:00 +00:00
let ctx = {req: {accessToken: {userId: 9}}};
let error;
const sales = [{id: 1, instance: 0}, {id: 2, instance: 1}];
const ticketId = 2;
try {
await app.models.Sale.deleteSales(ctx, sales, ticketId);
} catch (e) {
error = e;
}
expect(error).toEqual(new Error(`The sales of this ticket can't be modified`));
});
2020-10-15 16:57:27 +00:00
it('should delete the sale', async() => {
2019-07-22 11:14:00 +00:00
let ctx = {req: {accessToken: {userId: 9}}};
2020-10-08 14:00:19 +00:00
const sales = [{id: newSale.id, instance: 0}];
const ticketId = 16;
let res = await app.models.Sale.deleteSales(ctx, sales, ticketId);
expect(res).toEqual([{count: 1}]);
});
});