Skip to content

Commit 58cb114

Browse files
committed
refactor campaignId access in tests
1 parent d6615c1 commit 58cb114

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type TestUserStaticDetails = {
3434

3535
type TestUserDynamicDetails = {
3636
email: string;
37+
campaignId?: string;
3738
campaignIds?: string[];
3839
clientId: string;
3940
password: string;
@@ -261,8 +262,8 @@ export class CognitoAuthHelper {
261262
const clientId = `${userDetails.clientKey}--${this.runId}`;
262263
const clientConfig: ClientConfiguration | undefined =
263264
testClients[userDetails.clientKey];
264-
const clientName = clientConfig?.name;
265-
const campaignIds = clientConfig?.campaignIds;
265+
266+
const { name: clientName, campaignId, campaignIds } = clientConfig ?? {};
266267

267268
const clientAttributes = [
268269
{ Name: 'custom:sbx_client_id', Value: clientId },
@@ -313,18 +314,20 @@ export class CognitoAuthHelper {
313314
})
314315
);
315316

317+
const sub =
318+
user.User?.Attributes?.find((attr) => attr.Name === 'sub')?.Value ?? '';
319+
316320
await CognitoAuthHelper.authContextFile.set(
317321
this.runId,
318322
userDetails.userId,
319323
{
320324
email,
321-
userId:
322-
user.User?.Attributes?.find((attr) => attr.Name === 'sub')?.Value ??
323-
'',
325+
userId: sub,
326+
campaignId,
324327
campaignIds,
325-
clientId: clientId,
328+
clientId,
326329
clientKey: userDetails.clientKey,
327-
clientName: clientName,
330+
clientName,
328331
identityAttributes,
329332
password: tempPassword,
330333
}

tests/test-team/helpers/factories/template-factory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const TemplateFactory = {
1010
name: string = 'test'
1111
): Template => {
1212
return TemplateFactory.create({
13-
campaignId: testClients[user.clientKey]?.campaignId,
13+
campaignId: user.campaignId,
1414
clientId: user.clientId,
1515
id,
1616
message: 'test-message',
@@ -27,7 +27,7 @@ export const TemplateFactory = {
2727
name: string = 'test'
2828
): Template => {
2929
return TemplateFactory.create({
30-
campaignId: testClients[user.clientKey]?.campaignId,
30+
campaignId: user.campaignId,
3131
clientId: user.clientId,
3232
id,
3333
message: 'test-message',
@@ -43,7 +43,7 @@ export const TemplateFactory = {
4343
name: string = 'test'
4444
): Template => {
4545
return TemplateFactory.create({
46-
campaignId: testClients[user.clientKey]?.campaignId,
46+
campaignId: user.campaignId,
4747
clientId: user.clientId,
4848
id,
4949
message: 'test-message',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test.describe('GET /v1/client-configuration', () => {
5757
expect(await response.json()).toEqual({
5858
statusCode: 200,
5959
clientConfiguration: {
60-
campaignIds: testClients[userWithClientConfig.clientKey]?.campaignIds,
60+
campaignIds: userWithClientConfig.campaignIds,
6161
features: testClients[userWithClientConfig.clientKey]?.features,
6262
},
6363
});

tests/test-team/template-mgmt-api-tests/request-proof.api.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ test.describe('POST /v1/template/:templateId/proof', () => {
115115
},
116116
},
117117
personalisationParameters: ['nhsNumber'],
118-
campaignId: testClients[userProofingEnabled.clientKey]?.campaignIds?.[0],
118+
campaignId: userProofingEnabled.campaignIds?.[0],
119119
};
120120

121121
await templateStorageHelper.seedTemplateData([template]);
@@ -246,7 +246,7 @@ test.describe('POST /v1/template/:templateId/proof', () => {
246246
},
247247
},
248248
personalisationParameters: ['nhsNumber'],
249-
campaignId: testClients[userProofingEnabled.clientKey]?.campaignIds?.[0],
249+
campaignId: userProofingEnabled.campaignIds?.[0],
250250
};
251251

252252
await templateStorageHelper.seedTemplateData([template]);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ test.describe('POST /v1/template/:templateId/submit', () => {
11491149
owner: user1.userId,
11501150
proofingEnabled: true,
11511151
files: { ...baseTemplateData.files, proofs },
1152-
campaignId: testClients[user1.clientKey]?.campaignIds?.[0],
1152+
campaignId: user1?.campaignIds?.[0],
11531153
};
11541154

11551155
await templateStorageHelper.seedTemplateData([template]);
@@ -1170,7 +1170,7 @@ test.describe('POST /v1/template/:templateId/submit', () => {
11701170
expect(updated).toEqual({
11711171
statusCode: 200,
11721172
data: {
1173-
campaignId: testClients[user1.clientKey]?.campaignIds?.[0],
1173+
campaignId: user1.campaignIds?.[0],
11741174
clientId: user1.clientId,
11751175
createdAt: expect.stringMatching(isoDateRegExp),
11761176
id: expect.stringMatching(uuidRegExp),

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test.describe('POST /v1/letter-template', () => {
8585
expect(result).toEqual({
8686
statusCode: 201,
8787
data: {
88-
campaignId: testClients[user1.clientKey]?.campaignIds?.[0],
88+
campaignId: user1.campaignIds?.[0],
8989
createdAt: expect.stringMatching(isoDateRegExp),
9090
files: {
9191
pdfTemplate: {
@@ -177,8 +177,7 @@ test.describe('POST /v1/letter-template', () => {
177177
expect(result).toEqual({
178178
statusCode: 201,
179179
data: {
180-
campaignId:
181-
testClients[userWithFallbackCampaignId.clientKey]?.campaignId,
180+
campaignId: userWithFallbackCampaignId.campaignId,
182181
createdAt: expect.stringMatching(isoDateRegExp),
183182
files: {
184183
pdfTemplate: {
@@ -263,7 +262,7 @@ test.describe('POST /v1/letter-template', () => {
263262
expect(result).toEqual({
264263
statusCode: 201,
265264
data: {
266-
campaignId: testClients[user1.clientKey]?.campaignIds?.[0],
265+
campaignId: user1?.campaignIds?.[0],
267266
createdAt: expect.stringMatching(isoDateRegExp),
268267
files: {
269268
pdfTemplate: {

tests/test-team/template-mgmt-e2e-tests/template-mgmt-proof-request.e2e.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ test.describe('SFTP proof request send', () => {
7272
const pdfVersionId = template.files?.pdfTemplate?.currentVersion;
7373
const csvVersionId = template.files?.testDataCsv?.currentVersion;
7474

75-
const campaignId = testClients[user.clientKey]?.campaignIds?.[0];
75+
const campaignId = user.campaignIds?.[0];
7676

7777
expect(pdfVersionId).toBeDefined();
7878
expect(csvVersionId).toBeDefined();

0 commit comments

Comments
 (0)