Skip to content

Commit

Permalink
Fix tests and change separator for cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
snaerseljan committed Nov 26, 2024
1 parent ec6556b commit 46dcfb0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions apps/services/bff/src/app/modules/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions apps/services/bff/src/app/modules/cache/cache.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 46dcfb0

Please sign in to comment.