Skip to content

Commit 0e69bd0

Browse files
committed
test(profile-sync-controller): allow Env customization for exported mocks
1 parent 91d59c3 commit 0e69bd0

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

packages/profile-sync-controller/src/controllers/authentication/mocks/mockResponses.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
import {
2-
MOCK_NONCE_RESPONSE as SDK_MOCK_NONCE_RESPONSE,
2+
NONCE_URL,
3+
OIDC_TOKEN_URL,
4+
PAIR_SOCIAL_IDENTIFIER,
5+
SRP_LOGIN_URL,
6+
} from '../../../sdk/authentication-jwt-bearer/services';
7+
import {
38
MOCK_JWT as SDK_MOCK_JWT,
4-
MOCK_SRP_LOGIN_RESPONSE as SDK_MOCK_SRP_LOGIN_RESPONSE,
9+
MOCK_NONCE_RESPONSE as SDK_MOCK_NONCE_RESPONSE,
510
MOCK_OIDC_TOKEN_RESPONSE as SDK_MOCK_OIDC_TOKEN_RESPONSE,
6-
MOCK_NONCE_URL,
7-
MOCK_SRP_LOGIN_URL,
8-
MOCK_OIDC_TOKEN_URL,
11+
MOCK_SRP_LOGIN_RESPONSE as SDK_MOCK_SRP_LOGIN_RESPONSE,
912
} from '../../../sdk/mocks/auth';
13+
import { Env } from '../../../shared/env';
1014

1115
type MockResponse = {
1216
url: string;
1317
requestMethod: 'GET' | 'POST' | 'PUT';
1418
response: unknown;
19+
statusCode?: number;
1520
};
1621

1722
export const MOCK_NONCE_RESPONSE = SDK_MOCK_NONCE_RESPONSE;
1823
export const MOCK_NONCE = MOCK_NONCE_RESPONSE.nonce;
1924
export const MOCK_JWT = SDK_MOCK_JWT;
2025

21-
export const getMockAuthNonceResponse = () => {
26+
export const getMockAuthNonceResponse = (env: Env = Env.PRD) => {
2227
return {
23-
url: MOCK_NONCE_URL,
28+
url: NONCE_URL(env),
2429
requestMethod: 'GET',
2530
response: (
2631
_?: unknown,
@@ -34,7 +39,7 @@ export const getMockAuthNonceResponse = () => {
3439

3540
return {
3641
...MOCK_NONCE_RESPONSE,
37-
nonce: e2eIdentifier ?? MOCK_NONCE_RESPONSE.nonce,
42+
nonce: e2eIdentifier ?? MOCK_NONCE,
3843
identifier: MOCK_NONCE_RESPONSE.identifier,
3944
};
4045
},
@@ -43,9 +48,9 @@ export const getMockAuthNonceResponse = () => {
4348

4449
export const MOCK_LOGIN_RESPONSE = SDK_MOCK_SRP_LOGIN_RESPONSE;
4550

46-
export const getMockAuthLoginResponse = () => {
51+
export const getMockAuthLoginResponse = (env: Env = Env.PRD) => {
4752
return {
48-
url: MOCK_SRP_LOGIN_URL,
53+
url: SRP_LOGIN_URL(env),
4954
requestMethod: 'POST',
5055
// In case this mock is used in an E2E test, we populate token, profile_id and identifier_id with the e2eIdentifier
5156
// to make it easier to segregate data in the test environment.
@@ -69,9 +74,9 @@ export const getMockAuthLoginResponse = () => {
6974

7075
export const MOCK_OATH_TOKEN_RESPONSE = SDK_MOCK_OIDC_TOKEN_RESPONSE;
7176

72-
export const getMockAuthAccessTokenResponse = () => {
77+
export const getMockAuthAccessTokenResponse = (env: Env = Env.PRD) => {
7378
return {
74-
url: MOCK_OIDC_TOKEN_URL,
79+
url: OIDC_TOKEN_URL(env),
7580
requestMethod: 'POST',
7681
response: (requestJsonBody?: string) => {
7782
// We end up setting the access token to the e2eIdentifier in the test environment
@@ -88,3 +93,14 @@ export const getMockAuthAccessTokenResponse = () => {
8893
},
8994
} satisfies MockResponse;
9095
};
96+
97+
export const getMockPairSocialTokenResponse = (env: Env = Env.PRD) => {
98+
return {
99+
url: PAIR_SOCIAL_IDENTIFIER(env),
100+
requestMethod: 'POST',
101+
response: () => {
102+
return 'OK';
103+
},
104+
statusCode: 204,
105+
} satisfies MockResponse;
106+
};

packages/profile-sync-controller/src/controllers/user-storage/mocks/mockResponses.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ export const getMockUserStorageEndpoint = (
2727
path:
2828
| UserStorageGenericPathWithFeatureAndKey
2929
| UserStorageGenericPathWithFeatureOnly,
30+
env: Env = Env.PRD,
3031
) => {
3132
if (path.split('.').length === 1) {
32-
return `${getEnvUrls(Env.PRD).userStorageApiUrl}/api/v1/userstorage/${path}`;
33+
return `${getEnvUrls(env).userStorageApiUrl}/api/v1/userstorage/${path}`;
3334
}
3435

35-
return `${getEnvUrls(Env.PRD).userStorageApiUrl}/api/v1/userstorage/${createEntryPath(
36+
return `${getEnvUrls(env).userStorageApiUrl}/api/v1/userstorage/${createEntryPath(
3637
path as UserStorageGenericPathWithFeatureAndKey,
3738
MOCK_STORAGE_KEY,
3839
)}`;

0 commit comments

Comments
 (0)