From ae387dd3bb801e95e8631c06ab9867fe499c9c69 Mon Sep 17 00:00:00 2001 From: CeciliaLiu8 Date: Fri, 12 Apr 2024 08:13:24 -0500 Subject: [PATCH] MAT-6819 fix auth guard test issue --- src/auth/auth.guard.spec.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/auth/auth.guard.spec.ts b/src/auth/auth.guard.spec.ts index 57370f7..8d80bf2 100644 --- a/src/auth/auth.guard.spec.ts +++ b/src/auth/auth.guard.spec.ts @@ -19,7 +19,7 @@ describe('AuthGuard', () => { expect(guard).toBeDefined(); }); - it.skip('should have a fully mocked Execution Context with good auth token', async () => { + it('should have a fully mocked Execution Context with good auth token', async () => { const mockExecutionContext = createMock(); expect(mockExecutionContext.switchToHttp()).toBeDefined(); @@ -37,6 +37,18 @@ describe('AuthGuard', () => { }), }); + jest.mock('@okta/jwt-verifier', () => { + return jest.fn().mockImplementation(() => ({ + verifyAccessToken: () => ({ + oktaToken: { + claims: { + sub: 'testUser@testcompany.com', + }, + }, + }), + })); + }); + jest .spyOn(mockExecutionContext.switchToHttp(), 'getRequest') .mockImplementation(() => { @@ -48,7 +60,7 @@ describe('AuthGuard', () => { body: undefined, headers: { authorization: - 'Bearer eyJraWQiOiJNNG9CMW9DSmthdC0tYTNENFFXUFA3RWZCbUl3NG9BV05KYWJxdEJhUnM4IiwiYWxnIjoiUlMyNTYifQ.eyJ2ZXIiOjEsImp0aSI6IkFULlBlN3hEc000MksyTnhHSW5vSWV1UEVEVmgxY3YydDVqQ1FKZmU1Sm9ZbkUiLCJpc3MiOiJodHRwczovL2Rldi0xODA5MjU3OC5va3RhLmNvbS9vYXV0aDIvZGVmYXVsdCIsImF1ZCI6ImFwaTovL2RlZmF1bHQiLCJpYXQiOjE3MTI4NjMyNzcsImV4cCI6MTcxMjg2Njg3NywiY2lkIjoiMG9hMmZxdGF6OTVmcUpxYmY1ZDciLCJ1aWQiOiIwMHUyNWh3c3AxUG04MW5jTzVkNyI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