salix/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js

44 lines
1.2 KiB
JavaScript

const models = require('vn-loopback/server/server').models;
const ForbiddenError = require('vn-loopback/util/forbiddenError');
describe('ticket recalculateComponents()', () => {
const ticketId = 11;
const ctx = beforeAll.getCtx();
it('should update the ticket components', async() => {
const tx = await models.Ticket.beginTransaction({});
try {
const options = {transaction: tx};
const response = await models.Ticket.recalculateComponents(ctx, ticketId, options);
expect(response.affectedRows).toBeDefined();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should throw an error if the ticket is not editable', async() => {
const tx = await models.Ticket.beginTransaction({});
let error;
try {
const options = {transaction: tx};
const immutableTicketId = 1;
await models.Ticket.recalculateComponents(ctx, immutableTicketId, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error).toEqual(new ForbiddenError(`This ticket is locked`));
});
});