From 7563f9ad623a009f203e0c1f49b25b27a3777638 Mon Sep 17 00:00:00 2001 From: Gianfranco Paoloni Date: Fri, 3 Jan 2025 17:07:44 -0300 Subject: [PATCH] fix: unit tests --- .../contact-job/contact-job-publish.test.ts | 6 ------ .../contact/canPerformContactAction.test.ts | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/hrm-domain/hrm-core/unit-tests/contact-job/contact-job-publish.test.ts b/hrm-domain/hrm-core/unit-tests/contact-job/contact-job-publish.test.ts index e39e1cb0..02e1fd09 100644 --- a/hrm-domain/hrm-core/unit-tests/contact-job/contact-job-publish.test.ts +++ b/hrm-domain/hrm-core/unit-tests/contact-job/contact-job-publish.test.ts @@ -30,12 +30,6 @@ jest.mock('@tech-matters/ssm-cache', () => { }; }); -jest.mock('../../config/ssmCache', () => { - return { - getSsmParameter: jest.fn(), - }; -}); - const accountSid = 'AC-accountSid'; const twilioWorkerId = 'WK-twilioWorkerId'; const mockGetSsmParameter = getSsmParameter as jest.MockedFunction< diff --git a/hrm-domain/hrm-core/unit-tests/contact/canPerformContactAction.test.ts b/hrm-domain/hrm-core/unit-tests/contact/canPerformContactAction.test.ts index f7a12d00..865391d3 100644 --- a/hrm-domain/hrm-core/unit-tests/contact/canPerformContactAction.test.ts +++ b/hrm-domain/hrm-core/unit-tests/contact/canPerformContactAction.test.ts @@ -27,6 +27,7 @@ import { CaseService, getCase } from '../../case/caseService'; import { actionsMaps } from '../../permissions'; import { SafeRouterRequest } from '../../permissions/safe-router'; import { newTwilioUser } from '@tech-matters/twilio-worker-auth'; +import { mockingProxy, mockSsmParameters } from '@tech-matters/testing'; jest.mock('@tech-matters/twilio-client', () => ({ getClient: jest.fn().mockResolvedValue({}), @@ -51,6 +52,18 @@ const accountSid1 = 'ACtwilio-hrm1'; const thisWorkerSid = 'WK-thisWorker'; const otherWorkerSid = 'WK-otherWorker'; +beforeAll(async () => { + await mockingProxy.start(); + const mockttp = await mockingProxy.mockttpServer(); + await mockSsmParameters(mockttp, [ + { pathPattern: /.*\/auth_token$/, valueGenerator: () => 'account1 token' }, + ]); +}); + +afterAll(async () => { + await mockingProxy.stop(); +}); + let req: Partial; let mockRequestMethods: { permit: jest.MockedFunction; @@ -112,7 +125,6 @@ const draftContactTests = mockRequestMethods.can.mockReturnValue(false); req.body = { conversationDuration: 123 }; req.user = { ...req.user, accountSid: 'ACtwilio', workerSid: thisWorkerSid }; - process.env.TWILIO_AUTH_TOKEN_ACtwilio = 'account1 token'; await setup(); }); @@ -151,7 +163,6 @@ const draftContactTests = await canPerformEditContactAction(req, {}, next); expect(getClient).toHaveBeenCalledWith({ accountSid: 'ACtwilio', - authToken: 'account1 token', }); expect(isTwilioTaskTransferTarget).toHaveBeenCalledWith( await getClient({ accountSid: accountSid1 }), @@ -178,7 +189,6 @@ const draftContactTests = await canPerformEditContactAction(req, {}, next); expect(getClient).toHaveBeenCalledWith({ accountSid: 'ACtwilio', - authToken: 'account1 token', }); expectation(); @@ -197,7 +207,6 @@ const draftContactTests = await canPerformEditContactAction(req, {}, next); expect(getClient).toHaveBeenCalledWith({ accountSid: 'ACtwilio', - authToken: 'account1 token', }); expect(isTwilioTaskTransferTarget).toHaveBeenCalledWith( await getClient({ accountSid: accountSid1 }),