From 46dcfb01e43ce59b75183a04e00ca5c352da0e00 Mon Sep 17 00:00:00 2001 From: snaerseljan Date: Tue, 26 Nov 2024 11:43:32 +0000 Subject: [PATCH] Fix tests and change separator for cache key --- .../bff/src/app/modules/auth/auth.controller.spec.ts | 10 +++++++--- .../bff/src/app/modules/cache/cache.service.ts | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/services/bff/src/app/modules/auth/auth.controller.spec.ts b/apps/services/bff/src/app/modules/auth/auth.controller.spec.ts index 11f9a980c964..c6b8aa3f625c 100644 --- a/apps/services/bff/src/app/modules/auth/auth.controller.spec.ts +++ b/apps/services/bff/src/app/modules/auth/auth.controller.spec.ts @@ -121,7 +121,7 @@ describe('AuthController', () => { const [key, value] = setSpy.mock.calls[0] - expect(key).toEqual(`attempt_${SID_VALUE}`) + expect(key).toEqual(`attempt::${mockConfig.name}::${SID_VALUE}`) expect(value).toMatchObject({ originUrl: baseUrlWithKey, codeVerifier: expect.any(String), @@ -319,7 +319,9 @@ describe('AuthController', () => { const loginAttempt = setCacheSpy.mock.calls[0] // Assert - First request should cache the login attempt - expect(setCacheSpy.mock.calls[0]).toContain(`attempt_${SID_VALUE}`) + expect(setCacheSpy.mock.calls[0]).toContain( + `attempt::${mockConfig.name}::${SID_VALUE}`, + ) expect(loginAttempt[1]).toMatchObject({ originUrl: baseUrlWithKey, codeVerifier: expect.any(String), @@ -337,7 +339,9 @@ describe('AuthController', () => { // Assert expect(setCacheSpy).toHaveBeenCalled() - expect(currentLogin[0]).toContain(`current_${SID_VALUE}`) + expect(currentLogin[0]).toContain( + `current::${mockConfig.name}::${SID_VALUE}`, + ) // Check if the cache contains the correct values for the current login expect(currentLogin[1]).toMatchObject(tokensResponse) diff --git a/apps/services/bff/src/app/modules/cache/cache.service.ts b/apps/services/bff/src/app/modules/cache/cache.service.ts index f90bc4913777..e5888f9b2c93 100644 --- a/apps/services/bff/src/app/modules/cache/cache.service.ts +++ b/apps/services/bff/src/app/modules/cache/cache.service.ts @@ -26,11 +26,11 @@ export class CacheService { * `current` represents the current login session. * * @example - * createSessionKeyType('attempt', '1234') // attempt_{bffName}_1234 - * createSessionKeyType('current', '1234') // current_{bffName}_1234 + * createSessionKeyType('attempt', '1234') // attempt::{bffName}::1234 + * createSessionKeyType('current', '1234') // current::{bffName}::1234 */ public createSessionKeyType(type: 'attempt' | 'current', sid: string) { - return `${type}_${this.config.name}_${sid}` + return `${type}::${this.config.name}::${sid}` } public async save({