Skip to content

Commit 380e818

Browse files
committed
add clientId to test users
1 parent b122507 commit 380e818

File tree

41 files changed

+171
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+171
-124
lines changed

tests/accessibility/pa11y-setup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ const setup = async () => {
6262

6363
const { userId } = await testUserClient.createTestUser(
6464
testEmail,
65-
testPassword
65+
testPassword,
66+
'accessibility-test-client'
6667
);
6768

6869
const ddbDocClient = DynamoDBDocumentClient.from(

tests/accessibility/test-user-client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class TestUserClient {
1212

1313
constructor(private readonly userPoolId: string) {}
1414

15-
async createTestUser(email: string, password: string) {
15+
async createTestUser(email: string, password: string, clientId: string) {
1616
const res = await this.cognitoClient.send(
1717
new AdminCreateUserCommand({
1818
UserPoolId: this.userPoolId,
@@ -26,6 +26,10 @@ export class TestUserClient {
2626
Name: 'email_verified',
2727
Value: 'true',
2828
},
29+
{
30+
Name: 'custom:sbx:client_id',
31+
Value: clientId,
32+
},
2933
],
3034
MessageAction: 'SUPPRESS',
3135
})

tests/test-team/config/component/component.setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { BackendConfigHelper } from 'nhs-notify-web-template-management-util-bac
88
import { TemplateMgmtSignInPage } from '../../pages/templates-mgmt-login-page';
99
import {
1010
createAuthHelper,
11-
TestUserId,
11+
testUsers,
1212
} from '../../helpers/auth/cognito-auth-helper';
1313

1414
setup('component test setup', async ({ page }) => {
@@ -22,7 +22,7 @@ setup('component test setup', async ({ page }) => {
2222

2323
await auth.setup();
2424

25-
const user = await auth.getTestUser(TestUserId.User1);
25+
const user = await auth.getTestUser(testUsers.User1.userId);
2626

2727
const loginPage = new TemplateMgmtSignInPage(page);
2828

tests/test-team/config/e2e/e2e.setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { BackendConfigHelper } from 'nhs-notify-web-template-management-util-bac
88
import { TemplateMgmtSignInPage } from '../../pages/templates-mgmt-login-page';
99
import {
1010
createAuthHelper,
11-
TestUserId,
11+
testUsers,
1212
} from '../../helpers/auth/cognito-auth-helper';
1313

1414
setup('e2e test setup', async ({ page }) => {
@@ -22,7 +22,7 @@ setup('e2e test setup', async ({ page }) => {
2222

2323
await auth.setup();
2424

25-
const user = await auth.getTestUser(TestUserId.User1);
25+
const user = await auth.getTestUser(testUsers.User1.userId);
2626

2727
const loginPage = new TemplateMgmtSignInPage(page);
2828

tests/test-team/helpers/auth/cognito-auth-helper.ts

Lines changed: 66 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,66 @@ import { faker } from '@faker-js/faker';
1212
import { CredentialsFile } from './credentials-file';
1313

1414
export type TestUserCredential = {
15-
user: { email: string; userId: string };
15+
user: { email: string; userId: string; clientId: string | undefined };
1616
password: string;
1717
accessToken: string;
1818
refreshToken: string;
1919
};
2020

21-
export enum TestUserId {
21+
type TestUserStaticDetails = {
22+
userId: string;
23+
clientId: string | undefined;
24+
};
25+
26+
export const testUsers = {
2227
/**
2328
* User1 is generally the signed in user
2429
*/
25-
User1 = 'User1',
26-
30+
User1: {
31+
userId: 'User1',
32+
clientId: 'Client1',
33+
},
2734
/**
2835
* User2 provides an alternative user allowing to check for things like template ownership
2936
*/
30-
User2 = 'User2',
31-
37+
User2: {
38+
userId: 'User1',
39+
clientId: 'Client1',
40+
},
3241
/**
3342
* User3 idle user that stays stayed in
3443
*/
35-
User3 = 'User3',
36-
44+
User3: {
45+
userId: 'User1',
46+
clientId: 'Client1',
47+
},
3748
/**
3849
* User4 idle user which signs out automatically
3950
*/
40-
User4 = 'User4',
41-
51+
User4: {
52+
userId: 'User1',
53+
clientId: 'Client1',
54+
},
4255
/**
4356
* User5 idle user which signs out manually
4457
*/
45-
User5 = 'User5',
46-
}
58+
User5: {
59+
userId: 'User1',
60+
clientId: 'Client1',
61+
},
62+
/**
63+
* User6 does not belong to a client
64+
*/
65+
User6: {
66+
userId: 'User1',
67+
clientId: undefined,
68+
},
69+
} as const satisfies Record<string, TestUserStaticDetails>;
70+
71+
type TestUserId = keyof typeof testUsers;
4772

48-
export type TestUser = {
73+
export type TestUser = TestUserStaticDetails & {
4974
email: string;
50-
userId: string;
5175
password: string;
5276
/**
5377
* Gets an access token for a test user
@@ -79,7 +103,9 @@ export class CognitoAuthHelper {
79103

80104
public async setup() {
81105
await Promise.all(
82-
Object.values(TestUserId).map((id) => this.createUser(id))
106+
Object.values(testUsers).map((userDetails) =>
107+
this.createUser(userDetails)
108+
)
83109
);
84110
}
85111

@@ -142,32 +168,47 @@ export class CognitoAuthHelper {
142168
return user;
143169
}
144170

145-
private async createUser(id: TestUserId): Promise<void> {
171+
private async createUser(userDetails: TestUserStaticDetails): Promise<void> {
146172
const email = faker.internet.exampleEmail();
147173
const tempPassword = CognitoAuthHelper.generatePassword();
148174

175+
const clientAttribute = userDetails.clientId
176+
? [
177+
{
178+
Name: 'custom:sbx:client_id',
179+
Value: userDetails.clientId,
180+
},
181+
]
182+
: [];
183+
149184
const user = await this.client.send(
150185
new AdminCreateUserCommand({
151186
UserPoolId: this.userPoolId,
152187
Username: email,
153188
UserAttributes: [
154189
{ Name: 'email', Value: email },
155190
{ Name: 'email_verified', Value: 'True' },
191+
...clientAttribute,
156192
],
157193
TemporaryPassword: tempPassword,
158194
MessageAction: 'SUPPRESS',
159195
})
160196
);
161197

162-
await CognitoAuthHelper.credentialsFile.set(this.runId, id, {
163-
user: {
164-
email,
165-
userId:
166-
user.User?.Attributes?.find((attr) => attr.Name === 'sub')?.Value ??
167-
'',
168-
},
169-
password: tempPassword,
170-
});
198+
await CognitoAuthHelper.credentialsFile.set(
199+
this.runId,
200+
userDetails.userId,
201+
{
202+
user: {
203+
email,
204+
clientId: userDetails.clientId,
205+
userId:
206+
user.User?.Attributes?.find((attr) => attr.Name === 'sub')?.Value ??
207+
'',
208+
},
209+
password: tempPassword,
210+
}
211+
);
171212
}
172213

173214
private async deleteUser(email: string) {

tests/test-team/template-mgmt-api-tests/create-letter-template.api.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { test, expect } from '@playwright/test';
22
import {
33
createAuthHelper,
4-
TestUser,
5-
TestUserId,
4+
type TestUser,
5+
testUsers,
66
} from '../helpers/auth/cognito-auth-helper';
77
import { TemplateStorageHelper } from '../helpers/db/template-storage-helper';
88
import { TemplateAPIPayloadFactory } from '../helpers/factories/template-api-payload-factory';
@@ -18,7 +18,7 @@ test.describe('POST /v1/letter-template', () => {
1818
let user1: TestUser;
1919

2020
test.beforeAll(async () => {
21-
user1 = await authHelper.getTestUser(TestUserId.User1);
21+
user1 = await authHelper.getTestUser(testUsers.User1.userId);
2222
});
2323

2424
test.afterAll(async () => {

tests/test-team/template-mgmt-api-tests/create-template.api.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { test, expect } from '@playwright/test';
22
import {
33
createAuthHelper,
4-
TestUser,
5-
TestUserId,
4+
type TestUser,
5+
testUsers,
66
} from '../helpers/auth/cognito-auth-helper';
77
import { TemplateStorageHelper } from '../helpers/db/template-storage-helper';
88
import {
@@ -17,7 +17,7 @@ test.describe('POST /v1/template', () => {
1717
let user1: TestUser;
1818

1919
test.beforeAll(async () => {
20-
user1 = await authHelper.getTestUser(TestUserId.User1);
20+
user1 = await authHelper.getTestUser(testUsers.User1.userId);
2121
});
2222

2323
test.afterAll(async () => {

tests/test-team/template-mgmt-api-tests/delete-template.api.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { test, expect } from '@playwright/test';
22
import {
33
createAuthHelper,
4-
TestUser,
5-
TestUserId,
4+
type TestUser,
5+
testUsers,
66
} from '../helpers/auth/cognito-auth-helper';
77
import { TemplateStorageHelper } from '../helpers/db/template-storage-helper';
88
import { TemplateAPIPayloadFactory } from '../helpers/factories/template-api-payload-factory';
@@ -20,8 +20,8 @@ test.describe('DELETE /v1/template/:templateId', () => {
2020
let user2: TestUser;
2121

2222
test.beforeAll(async () => {
23-
user1 = await authHelper.getTestUser(TestUserId.User1);
24-
user2 = await authHelper.getTestUser(TestUserId.User2);
23+
user1 = await authHelper.getTestUser(testUsers.User1.userId);
24+
user2 = await authHelper.getTestUser(testUsers.User2.userId);
2525
});
2626

2727
test.afterAll(async () => {

tests/test-team/template-mgmt-api-tests/get-template.api.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { test, expect } from '@playwright/test';
22
import {
33
createAuthHelper,
4-
TestUser,
5-
TestUserId,
4+
type TestUser,
5+
testUsers,
66
} from '../helpers/auth/cognito-auth-helper';
77
import { TemplateStorageHelper } from '../helpers/db/template-storage-helper';
88
import { TemplateAPIPayloadFactory } from '../helpers/factories/template-api-payload-factory';
@@ -14,8 +14,8 @@ test.describe('GET /v1/template/:templateId', () => {
1414
let user2: TestUser;
1515

1616
test.beforeAll(async () => {
17-
user1 = await authHelper.getTestUser(TestUserId.User1);
18-
user2 = await authHelper.getTestUser(TestUserId.User2);
17+
user1 = await authHelper.getTestUser(testUsers.User1.userId);
18+
user2 = await authHelper.getTestUser(testUsers.User2.userId);
1919
});
2020

2121
test.afterAll(async () => {

tests/test-team/template-mgmt-api-tests/list-templates.api.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { test, expect } from '@playwright/test';
22
import { TemplateStorageHelper } from '../helpers/db/template-storage-helper';
33
import {
44
createAuthHelper,
5-
TestUser,
6-
TestUserId,
5+
type TestUser,
6+
testUsers,
77
} from '../helpers/auth/cognito-auth-helper';
88
import { TemplateAPIPayloadFactory } from '../helpers/factories/template-api-payload-factory';
99

@@ -14,8 +14,8 @@ test.describe('GET /v1/templates', () => {
1414
let user2: TestUser;
1515

1616
test.beforeAll(async () => {
17-
user1 = await authHelper.getTestUser(TestUserId.User1);
18-
user2 = await authHelper.getTestUser(TestUserId.User2);
17+
user1 = await authHelper.getTestUser(testUsers.User1.userId);
18+
user2 = await authHelper.getTestUser(testUsers.User2.userId);
1919
});
2020

2121
test.afterEach(async () => {

0 commit comments

Comments
 (0)