From 9b085d13e11502f249b78761004743fe4c13a394 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 14 May 2020 17:32:52 +0200 Subject: [PATCH] Updated back unit test --- .../claim/specs/regularizeClaim.spec.js | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js index 6622de116e..db8a898026 100644 --- a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js @@ -55,7 +55,7 @@ describe('regularizeClaim()', () => { expect(claimBefore.claimStateFk).toEqual(pendentState); expect(claimAfter.claimStateFk).toEqual(resolvedState); expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Trash'); - expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(5); + expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(4); }); it('should send a chat message with value "Bueno" and then change claim state to resolved', async() => { @@ -78,6 +78,32 @@ describe('regularizeClaim()', () => { await app.models.Claim.regularizeClaim(ctx, claimFk); + expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Bueno'); + expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(4); + }); + + it('should send a chat message to the salesPerson when claim isPickUp is enabled', async() => { + const ctx = { + req: { + accessToken: {userId: 18}, + headers: {origin: 'http://localhost'} + } + }; + ctx.req.__ = (value, params) => { + return params.nickname; + }; + + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); + + claimEnds.forEach(async claimEnd => { + claimEnd.updateAttributes({claimDestinationFk: okDestination}); + }); + + const claim = await app.models.Claim.findById(claimFk); + await claim.updateAttribute('hasToPickUp', true); + await app.models.Claim.regularizeClaim(ctx, claimFk); + expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Bueno'); expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(5); });