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

45 lines
1.1 KiB
JavaScript

const app = require('vn-loopback/server/server');
describe('sale removes()', () => {
let sale;
let newsale;
beforeAll(async done => {
sale = await app.models.Sale.findOne({where: {id: 9}});
sale.id = null;
newsale = await app.models.Sale.create(sale);
done();
});
it('should throw an error if the ticket of the given sales is not editable', async() => {
let ctx = {req: {accessToken: {userId: 9}}};
let error;
let params = {
sales: [{id: 1, instance: 0}, {id: 2, instance: 1}],
actualTicketFk: 2
};
try {
await app.models.Sale.removes(ctx, params);
} catch (e) {
error = e;
}
expect(error).toEqual(new Error(`The sales of this ticket can't be modified`));
});
it('should delete the sales', async() => {
let ctx = {req: {accessToken: {userId: 9}}};
let params = {
sales: [{id: newsale.id, instance: 0}],
actualTicketFk: 16
};
let res = await app.models.Sale.removes(ctx, params);
expect(res).toEqual([{count: 1}]);
});
});