From 1e4f36b77540546de5381273b93ca4513e3d1a93 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 2 Jun 2020 09:34:42 +0200 Subject: [PATCH] Updated back unit test --- .../ticket/back/methods/ticket/setDeleted.js | 2 +- .../methods/ticket/specs/setDeleted.spec.js | 57 +++++++++++++++---- modules/ticket/back/models/ticket-state.json | 3 + 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index 86fb89e4d..06e443e94 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -112,7 +112,7 @@ module.exports = Self => { otherTicketId = ticket.ship().id; if (otherTicketId) { - models.TicketTracking.changeState(ctx, { + await models.TicketTracking.changeState(ctx, { ticketFk: otherTicketId, code: 'FIXING' }); diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 990e69fa9..8c94f012e 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -4,6 +4,7 @@ const models = app.models; describe('ticket deleted()', () => { let ticket; let sale; + let deletedClaim; beforeAll(async done => { let originalTicket = await models.Ticket.findOne({where: {id: 16}}); @@ -27,8 +28,36 @@ describe('ticket deleted()', () => { }); afterAll(async done => { + const ticketId = 16; + const stowawayTicketId = 17; + const ctx = { + req: { + accessToken: {userId: 106}, + headers: { + origin: 'http://localhost:5000' + }, + __: () => {} + } + }; await models.Ticket.destroyById(ticket.id); - + const stowaway = await models.Stowaway.findOne({ + where: { + id: stowawayTicketId, + shipFk: ticketId + } + }); + await stowaway.destroy(); + await models.Claim.create(deletedClaim); + await models.TicketTracking.changeState(ctx, { + ticketFk: ticketId, + code: 'OK' + }); + await models.TicketTracking.changeState(ctx, { + ticketFk: stowawayTicketId, + code: 'OK' + }); + const orgTicket = await models.Ticket.findById(ticketId); + await orgTicket.updateAttribute('isDeleted', false); done(); }); @@ -104,8 +133,10 @@ describe('ticket deleted()', () => { expect(error.message).toEqual('You must delete the claim id %d first'); }); - fit('should delete the ticket and change the state to "FIXING" to the stowaway ticket', async() => { + it('should delete the ticket and change the state to "FIXING" to the stowaway ticket', async() => { const ticketId = 16; + const claimIdToRemove = 2; + const stowawayTicketId = 17; const ctx = { req: { accessToken: {userId: 106}, @@ -115,15 +146,21 @@ describe('ticket deleted()', () => { __: () => {} } }; - let error; - try { - await app.models.Ticket.setDeleted(ctx, ticketId); - } catch (e) { - error = e; - } + await app.models.Stowaway.rawSql(` + INSERT INTO vn.stowaway(id, shipFk) + VALUES (?, ?)`, [stowawayTicketId, ticketId]); - expect(error.translateArgs[0]).toEqual(2); - expect(error.message).toEqual('You must delete the claim id %d first'); + deletedClaim = await app.models.Claim.findById(claimIdToRemove); + await app.models.Claim.destroyById(claimIdToRemove); + await app.models.Ticket.setDeleted(ctx, ticketId); + + const stowawayTicket = await app.models.TicketState.findOne({ + where: { + ticketFk: stowawayTicketId + } + }); + + expect(stowawayTicket.code).toEqual('FIXING'); }); }); diff --git a/modules/ticket/back/models/ticket-state.json b/modules/ticket/back/models/ticket-state.json index e53c4d0f5..a7f0f8242 100644 --- a/modules/ticket/back/models/ticket-state.json +++ b/modules/ticket/back/models/ticket-state.json @@ -17,6 +17,9 @@ }, "alertLevel": { "type": "Number" + }, + "code": { + "type": "string" } }, "relations": {