2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2018-08-21 10:56:32 +00:00
|
|
|
|
2020-07-01 12:28:05 +00:00
|
|
|
describe('sale deleteSales()', () => {
|
2018-08-22 06:24:54 +00:00
|
|
|
let sale;
|
2018-10-24 11:45:59 +00:00
|
|
|
let newsale;
|
2018-08-21 10:56:32 +00:00
|
|
|
|
2019-03-01 10:50:26 +00:00
|
|
|
beforeAll(async done => {
|
2018-10-24 11:45:59 +00:00
|
|
|
sale = await app.models.Sale.findOne({where: {id: 9}});
|
|
|
|
sale.id = null;
|
|
|
|
newsale = await app.models.Sale.create(sale);
|
2019-03-01 10:50:26 +00:00
|
|
|
|
|
|
|
done();
|
2018-08-21 10:56:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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}}};
|
2018-08-21 10:56:32 +00:00
|
|
|
let error;
|
|
|
|
|
2020-07-01 12:28:05 +00:00
|
|
|
const sales = [{id: 1, instance: 0}, {id: 2, instance: 1}];
|
|
|
|
const ticketId = 2;
|
2018-08-21 10:56:32 +00:00
|
|
|
|
|
|
|
try {
|
2020-07-01 12:28:05 +00:00
|
|
|
await app.models.Sale.deleteSales(ctx, sales, ticketId);
|
2018-08-21 10:56:32 +00:00
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toEqual(new Error(`The sales of this ticket can't be modified`));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete the sales', async() => {
|
2019-07-22 11:14:00 +00:00
|
|
|
let ctx = {req: {accessToken: {userId: 9}}};
|
2018-08-21 10:56:32 +00:00
|
|
|
|
2020-07-01 12:28:05 +00:00
|
|
|
const sales = [{id: newsale.id, instance: 0}];
|
|
|
|
const ticketId = 16;
|
|
|
|
|
|
|
|
let res = await app.models.Sale.deleteSales(ctx, sales, ticketId);
|
2018-08-21 10:56:32 +00:00
|
|
|
|
2018-08-22 06:24:54 +00:00
|
|
|
expect(res).toEqual([{count: 1}]);
|
2018-08-21 10:56:32 +00:00
|
|
|
});
|
|
|
|
});
|