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

55 lines
1.6 KiB
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
describe('sale payBack()', () => {
it('should create ticket with the selected lines changing the sign to the quantites', async() => {
const tx = await models.Sale.beginTransaction({});
const ctx = {req: {accessToken: {userId: 9}}};
const ticketId = 11;
const sales = [
{id: 7, ticketFk: 11},
{id: 8, ticketFk: 11}
];
try {
const options = {transaction: tx};
const response = await models.Sale.payBack(ctx, sales, ticketId, options);
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;
}
});
it('should throw error for not have privileges', async() => {
const tx = await models.Sale.beginTransaction({});
const ctx = {req: {accessToken: {userId: 1}}};
const ticketId = 11;
const sales = [
{id: 7, ticketFk: 11}
];
let error;
try {
const options = {transaction: tx};
await models.Sale.payBack(ctx, sales, ticketId, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error).toBeDefined();
expect(error.message).toEqual(`You don't have privileges to create pay back`);
});
});