2018-08-10 15:17:53 +00:00
|
|
|
const app = require(`${servicesDir}/ticket/server/server`);
|
|
|
|
|
2018-09-13 13:13:42 +00:00
|
|
|
describe('ticket deleted()', () => {
|
2018-09-13 12:29:59 +00:00
|
|
|
let ticket;
|
2018-09-13 13:13:42 +00:00
|
|
|
|
2018-11-20 09:32:54 +00:00
|
|
|
beforeAll(async () => {
|
2018-10-25 09:50:18 +00:00
|
|
|
let originalTicket = await app.models.Ticket.findOne({where: {id: 16}});
|
|
|
|
originalTicket.id = null;
|
|
|
|
ticket = await app.models.Ticket.create(originalTicket);
|
|
|
|
});
|
|
|
|
|
2018-11-20 09:32:54 +00:00
|
|
|
afterAll(async () => {
|
2018-10-25 09:50:18 +00:00
|
|
|
await app.models.Ticket.destroyById(ticket.id);
|
2018-09-13 12:29:59 +00:00
|
|
|
});
|
|
|
|
|
2018-11-20 09:32:54 +00:00
|
|
|
it('should make sure the ticket is not deleted yet', async () => {
|
2018-09-13 12:29:59 +00:00
|
|
|
expect(ticket.isDeleted).toEqual(false);
|
2018-09-13 13:29:38 +00:00
|
|
|
});
|
|
|
|
|
2018-11-20 09:32:54 +00:00
|
|
|
it('should set a ticket to deleted and log the change on TicketState table', async () => {
|
2018-09-13 13:29:38 +00:00
|
|
|
let ctx = {req: {accessToken: {userId: 9}}};
|
2018-10-25 09:50:18 +00:00
|
|
|
let params = {id: ticket.id};
|
2018-09-13 13:13:42 +00:00
|
|
|
await app.models.Ticket.deleted(ctx, params);
|
2018-08-10 15:17:53 +00:00
|
|
|
|
2018-10-25 09:50:18 +00:00
|
|
|
let deletedTicket = await app.models.Ticket.findOne({where: {id: ticket.id}, fields: ['isDeleted']});
|
|
|
|
let changedState = await app.models.TicketState.findOne({where: {ticketFk: ticket.id}});
|
2018-09-13 12:29:59 +00:00
|
|
|
|
|
|
|
expect(deletedTicket.isDeleted).toEqual(true);
|
2018-09-13 13:13:42 +00:00
|
|
|
expect(changedState.stateFk).toEqual(17);
|
2018-08-10 15:17:53 +00:00
|
|
|
});
|
2018-11-20 09:32:54 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
2018-08-10 15:17:53 +00:00
|
|
|
});
|