salix/services/loopback/common/methods/ticket/specs/deleted.spec.js

47 lines
1.5 KiB
JavaScript

const app = require(`${servicesDir}/ticket/server/server`);
describe('ticket deleted()', () => {
let ticket;
beforeAll(async () => {
let originalTicket = await app.models.Ticket.findOne({where: {id: 16}});
originalTicket.id = null;
ticket = await app.models.Ticket.create(originalTicket);
});
afterAll(async () => {
await app.models.Ticket.destroyById(ticket.id);
});
it('should make sure the ticket is not deleted yet', async () => {
expect(ticket.isDeleted).toEqual(false);
});
it('should set a ticket to deleted and log the change on TicketState table', async () => {
let ctx = {req: {accessToken: {userId: 9}}};
let params = {id: ticket.id};
await app.models.Ticket.deleted(ctx, params);
let deletedTicket = await app.models.Ticket.findOne({where: {id: ticket.id}, fields: ['isDeleted']});
let changedState = await app.models.TicketState.findOne({where: {ticketFk: ticket.id}});
expect(deletedTicket.isDeleted).toEqual(true);
expect(changedState.stateFk).toEqual(17);
});
it('should throw an error if the given ticket has a claim', async () => {
let ctx = {req: {accessToken: {userId: 9}}};
let params = {id: 16};
let error;
try {
await app.models.Ticket.deleted(ctx, params);
} catch (e) {
error = e;
}
expect(error.translateArgs[0]).toEqual(2);
expect(error.message).toEqual('You must delete the claim id %d first');
});
});