2021-12-21 13:43:53 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
|
2022-04-04 11:26:53 +00:00
|
|
|
describe('sale refund()', () => {
|
2022-04-26 11:25:12 +00:00
|
|
|
const sales = [
|
|
|
|
{id: 7, ticketFk: 11},
|
|
|
|
{id: 8, ticketFk: 11}
|
|
|
|
];
|
|
|
|
const services = [{id: 1}];
|
|
|
|
|
2021-12-21 13:43:53 +00:00
|
|
|
it('should create ticket with the selected lines changing the sign to the quantites', async() => {
|
|
|
|
const tx = await models.Sale.beginTransaction({});
|
2022-01-21 10:40:48 +00:00
|
|
|
const ctx = {req: {accessToken: {userId: 9}}};
|
|
|
|
|
2021-12-21 13:43:53 +00:00
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
2022-04-26 11:25:12 +00:00
|
|
|
const response = await models.Sale.refund(ctx, sales, services, options);
|
2021-12-21 13:43:53 +00:00
|
|
|
const [newTicketId] = await models.Sale.rawSql('SELECT MAX(t.id) id FROM vn.ticket t;', null, options);
|
|
|
|
|
|
|
|
expect(response).toEqual(newTicketId.id);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
});
|
2022-01-21 10:40:48 +00:00
|
|
|
|
2022-04-04 11:26:53 +00:00
|
|
|
it(`should throw an error if the user doesn't have privileges to create a refund`, async() => {
|
2022-01-21 10:40:48 +00:00
|
|
|
const tx = await models.Sale.beginTransaction({});
|
|
|
|
const ctx = {req: {accessToken: {userId: 1}}};
|
|
|
|
|
|
|
|
let error;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
2022-04-26 11:25:12 +00:00
|
|
|
await models.Sale.refund(ctx, sales, services, options);
|
2022-01-21 10:40:48 +00:00
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
2022-04-04 11:26:53 +00:00
|
|
|
expect(error.message).toEqual(`You don't have privileges to create refund`);
|
2022-01-21 10:40:48 +00:00
|
|
|
});
|
2021-12-21 13:43:53 +00:00
|
|
|
});
|