Skip to content

Commit 5241739

Browse files
committed
CCM-11889: update tests
1 parent 932e12c commit 5241739

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

infrastructure/terraform/components/sandbox/aws_cognito_user_pool_sandbox.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@ resource "aws_cognito_user_pool" "sandbox" {
2525
required = false
2626
string_attribute_constraints {}
2727
}
28+
29+
schema {
30+
name = "nhs_notify_user_id"
31+
attribute_data_type = "String"
32+
mutable = true
33+
required = false
34+
string_attribute_constraints {}
35+
}
2836
}

lambdas/cognito-triggers/src/pre-token-generation.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class PreTokenGenerationLambda {
2525

2626
const clientId = userAttributes['custom:sbx_client_id'];
2727
const clientName = userAttributes['custom:sbx_client_name'];
28+
const internalUserId = userAttributes['custom:nhs_notify_user_id'];
2829

2930
if (clientId) {
3031
response = PreTokenGenerationLambda.setTokenClaims(
@@ -73,6 +74,19 @@ export class PreTokenGenerationLambda {
7374
);
7475
}
7576

77+
if (internalUserId) {
78+
response = PreTokenGenerationLambda.setTokenClaims(
79+
response,
80+
'idTokenGeneration',
81+
{ 'nhs-notify:internal-user-id': internalUserId }
82+
);
83+
response = PreTokenGenerationLambda.setTokenClaims(
84+
response,
85+
'accessTokenGeneration',
86+
{ 'nhs-notify:internal-user-id': internalUserId }
87+
);
88+
}
89+
7690
return response;
7791
};
7892

tests/accessibility/pa11y-setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const setup = async () => {
9393
const familyName = 'Bergstrom';
9494
const userName = ['Dr', givenName, familyName];
9595

96-
const { userId } = await testUserClient.createTestUser(
96+
const { internalUserId } = await testUserClient.createTestUser(
9797
testEmail,
9898
testPassword,
9999
clientId,
@@ -168,7 +168,7 @@ const setup = async () => {
168168
email: testEmail,
169169
password: testPassword,
170170
templateIds,
171-
userId,
171+
internalUserId,
172172
clientId,
173173
clientName,
174174
userName,

tests/accessibility/test-user-client.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export class TestUserClient {
4646
})
4747
);
4848

49+
const internalUserId = crypto.randomUUID();
50+
4951
const res = await this.cognitoClient.send(
5052
new AdminCreateUserCommand({
5153
UserPoolId: this.userPoolId,
@@ -55,6 +57,7 @@ export class TestUserClient {
5557
{ Name: 'email_verified', Value: 'true' },
5658
{ Name: 'custom:sbx_client_id', Value: clientId },
5759
{ Name: 'custom:sbx_client_name', Value: clientName },
60+
{ Name: 'custom:nhs_notify_user_id', Value: internalUserId },
5861
{ Name: 'given_name', Value: displayUsernameParts.at(-2) },
5962
{ Name: 'family_name', Value: displayUsernameParts.at(-1) },
6063
{ Name: 'preferred_username', Value: displayUsernameParts.join(' ') },
@@ -73,16 +76,11 @@ export class TestUserClient {
7376
);
7477

7578
const username = res.User?.Username;
76-
77-
const userId = res.User?.Attributes?.find(
78-
(attr) => attr.Name === 'sub'
79-
)?.Value;
80-
81-
if (!username || !userId) {
79+
if (!username) {
8280
throw new Error('Error during user creation');
8381
}
8482

85-
return { username, userId };
83+
return { username, internalUserId };
8684
}
8785

8886
async deleteTestUser(email: string, clientId: string) {

0 commit comments

Comments
 (0)