From be07e33e5f65af733eec711c3578845066f45b93 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 13 Feb 2020 14:39:33 +0100 Subject: [PATCH] updated unit test --- .../claim/specs/regularizeClaim.spec.js | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js index fd3fb3c3d..96f2c8172 100644 --- a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js @@ -1,6 +1,6 @@ const app = require('vn-loopback/server/server'); -describe('regularizeClaim()', () => { +fdescribe('regularizeClaim()', () => { const claimFk = 1; const pendentState = 1; const resolvedState = 3; @@ -21,15 +21,20 @@ describe('regularizeClaim()', () => { done(); }); - it('should change claim state to resolved', async() => { - const ctx = {req: { - accessToken: {userId: 18}, - headers: {origin: 'http://localhost'}} + it('should send a chat message with value "Trash" and then change claim state to resolved', async() => { + const ctx = { + req: { + accessToken: {userId: 18}, + headers: {origin: 'http://localhost'} + } }; - ctx.req.__ = value => { - return value; + ctx.req.__ = (value, params) => { + return params.nickname; }; + let params = {claimFk: claimFk}; + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); claimEnds = await app.models.ClaimEnd.importTicketSales(ctx, { claimFk: claimFk, @@ -49,5 +54,30 @@ describe('regularizeClaim()', () => { expect(trashTicket.addressFk).toEqual(trashAddress); expect(claimBefore.claimStateFk).toEqual(pendentState); expect(claimAfter.claimStateFk).toEqual(resolvedState); + expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Trash'); + }); + + it('should send a chat message with value "Bueno" and then change claim state to resolved', async() => { + const ctx = { + req: { + accessToken: {userId: 18}, + headers: {origin: 'http://localhost'} + } + }; + ctx.req.__ = (value, params) => { + return params.nickname; + }; + + let params = {claimFk: claimFk}; + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); + + claimEnds.forEach(async claimEnd => { + claimEnd.updateAttributes({claimDestinationFk: 1}); + }); + + await app.models.Claim.regularizeClaim(ctx, params); + + expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Bueno'); }); });