Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GPaoloni committed Jan 3, 2025
1 parent a0e0f61 commit 7563f9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({}),
Expand All @@ -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<SafeRouterRequest>;
let mockRequestMethods: {
permit: jest.MockedFunction<SafeRouterRequest['permit']>;
Expand Down Expand Up @@ -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();
});

Expand Down Expand Up @@ -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 }),
Expand All @@ -178,7 +189,6 @@ const draftContactTests =
await canPerformEditContactAction(req, {}, next);
expect(getClient).toHaveBeenCalledWith({
accountSid: 'ACtwilio',
authToken: 'account1 token',
});

expectation();
Expand All @@ -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 }),
Expand Down

0 comments on commit 7563f9a

Please sign in to comment.