Skip to content

Commit 34e3922

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

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

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

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

1114
type MockResponse = {
1215
url: string;
1316
requestMethod: 'GET' | 'POST' | 'PUT';
1417
response: unknown;
18+
statusCode?: number;
1519
};
1620

1721
export const MOCK_NONCE_RESPONSE = SDK_MOCK_NONCE_RESPONSE;
1822
export const MOCK_NONCE = MOCK_NONCE_RESPONSE.nonce;
1923
export const MOCK_JWT = SDK_MOCK_JWT;
2024

21-
export const getMockAuthNonceResponse = () => {
25+
export const getMockAuthNonceResponse = (env: Env = Env.PRD) => {
2226
return {
23-
url: MOCK_NONCE_URL,
27+
url: NONCE_URL(env),
2428
requestMethod: 'GET',
2529
response: (
2630
_?: unknown,
@@ -34,7 +38,7 @@ export const getMockAuthNonceResponse = () => {
3438

3539
return {
3640
...MOCK_NONCE_RESPONSE,
37-
nonce: e2eIdentifier ?? MOCK_NONCE_RESPONSE.nonce,
41+
nonce: e2eIdentifier ?? MOCK_NONCE,
3842
identifier: MOCK_NONCE_RESPONSE.identifier,
3943
};
4044
},
@@ -43,9 +47,9 @@ export const getMockAuthNonceResponse = () => {
4347

4448
export const MOCK_LOGIN_RESPONSE = SDK_MOCK_SRP_LOGIN_RESPONSE;
4549

46-
export const getMockAuthLoginResponse = () => {
50+
export const getMockAuthLoginResponse = (env: Env = Env.PRD) => {
4751
return {
48-
url: MOCK_SRP_LOGIN_URL,
52+
url: SRP_LOGIN_URL(env),
4953
requestMethod: 'POST',
5054
// In case this mock is used in an E2E test, we populate token, profile_id and identifier_id with the e2eIdentifier
5155
// to make it easier to segregate data in the test environment.
@@ -69,9 +73,9 @@ export const getMockAuthLoginResponse = () => {
6973

7074
export const MOCK_OATH_TOKEN_RESPONSE = SDK_MOCK_OIDC_TOKEN_RESPONSE;
7175

72-
export const getMockAuthAccessTokenResponse = () => {
76+
export const getMockAuthAccessTokenResponse = (env: Env = Env.PRD) => {
7377
return {
74-
url: MOCK_OIDC_TOKEN_URL,
78+
url: OIDC_TOKEN_URL(env),
7579
requestMethod: 'POST',
7680
response: (requestJsonBody?: string) => {
7781
// We end up setting the access token to the e2eIdentifier in the test environment
@@ -88,3 +92,14 @@ export const getMockAuthAccessTokenResponse = () => {
8892
},
8993
} satisfies MockResponse;
9094
};
95+
96+
export const getMockPairSocialTokenResponse = (env: Env = Env.PRD) => {
97+
return {
98+
url: PAIR_SOCIAL_IDENTIFIER(env),
99+
requestMethod: 'POST',
100+
response: () => {
101+
return 'OK';
102+
},
103+
statusCode: 204,
104+
} satisfies MockResponse;
105+
};

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)