Skip to content

Commit c5e379f

Browse files
committed
updating api tests
1 parent e64c3c1 commit c5e379f

File tree

7 files changed

+32
-18
lines changed

7 files changed

+32
-18
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717

1818
type TestUserStaticDetails = {
1919
userId: string;
20-
clientKey: ClientKey | undefined;
20+
clientKey: ClientKey | 'NONE';
2121
};
2222

2323
type TestUserDynamicDetails = {
@@ -75,7 +75,7 @@ export const testUsers: Record<string, TestUserStaticDetails> = {
7575
*/
7676
User6: {
7777
userId: 'User6',
78-
clientKey: undefined,
78+
clientKey: 'NONE',
7979
},
8080
};
8181

@@ -184,9 +184,10 @@ export class CognitoAuthHelper {
184184
const email = faker.internet.exampleEmail();
185185
const tempPassword = CognitoAuthHelper.generatePassword();
186186

187-
const clientId = userDetails.clientKey
188-
? `${userDetails.clientKey}--${this.runId}`
189-
: undefined;
187+
const clientId =
188+
userDetails.clientKey === 'NONE'
189+
? undefined
190+
: `${userDetails.clientKey}--${this.runId}`;
190191

191192
const clientAttribute = clientId
192193
? [

tests/test-team/helpers/client/client-helper.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ type ClientConfiguration = {
1111
campaignId?: string;
1212
};
1313

14-
export type ClientKey = `Client${1 | 2 | 3}`;
14+
export type ClientKey = `Client${1 | 2 | 3}` | 'NONE';
1515

16-
export const testClients: Record<ClientKey, ClientConfiguration | null> = {
16+
type TestClients = Record<
17+
Exclude<ClientKey, 'NONE'>,
18+
ClientConfiguration | undefined
19+
>;
20+
21+
export const testClients = {
1722
/**
1823
* Client1 has proofing enabled
1924
*/
@@ -35,8 +40,8 @@ export const testClients: Record<ClientKey, ClientConfiguration | null> = {
3540
/**
3641
* Client3 has no configuration
3742
*/
38-
Client3: null,
39-
};
43+
Client3: undefined,
44+
} satisfies TestClients as TestClients & { NONE: undefined };
4045

4146
export class ClientConfigurationHelper {
4247
private readonly ssmClient = new SSMClient({ region: 'eu-west-2' });
@@ -51,7 +56,7 @@ export class ClientConfigurationHelper {
5156
Object.entries(testClients).map(async ([clientKey, value]) => {
5257
const id = `${clientKey}--${this.runId}`;
5358

54-
if (value !== null) {
59+
if (value !== undefined) {
5560
await this.ssmClient.send(
5661
new PutParameterCommand({
5762
Name: this.ssmKey(id),

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
uuidRegExp,
1212
} from 'nhs-notify-web-template-management-test-helper-utils';
1313
import { pdfUploadFixtures } from '../fixtures/pdf-upload/multipart-pdf-letter-fixtures';
14+
import { testClients } from '../helpers/client/client-helper';
1415

1516
test.describe('POST /v1/letter-template', () => {
1617
const authHelper = createAuthHelper();
@@ -81,6 +82,7 @@ test.describe('POST /v1/letter-template', () => {
8182
expect(result).toEqual({
8283
statusCode: 201,
8384
template: {
85+
campaignId: testClients[user1.clientKey]?.campaignId,
8486
createdAt: expect.stringMatching(isoDateRegExp),
8587
id: expect.stringMatching(uuidRegExp),
8688
name: templateData.name,
@@ -165,6 +167,7 @@ test.describe('POST /v1/letter-template', () => {
165167
expect(result).toEqual({
166168
statusCode: 201,
167169
template: {
170+
campaignId: testClients[user1.clientKey]?.campaignId,
168171
createdAt: expect.stringMatching(isoDateRegExp),
169172
id: expect.stringMatching(uuidRegExp),
170173
name: templateData.name,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
uuidRegExp,
1111
} from 'nhs-notify-web-template-management-test-helper-utils';
1212
import { TemplateAPIPayloadFactory } from '../helpers/factories/template-api-payload-factory';
13+
import { testClients } from '../helpers/client/client-helper';
1314

1415
test.describe('POST /v1/template', () => {
1516
const authHelper = createAuthHelper();
@@ -142,6 +143,7 @@ test.describe('POST /v1/template', () => {
142143
expect(created).toEqual({
143144
statusCode: 201,
144145
template: {
146+
campaignId: testClients[user1.clientKey]?.campaignId,
145147
createdAt: expect.stringMatching(isoDateRegExp),
146148
id: expect.stringMatching(uuidRegExp),
147149
message: template.message,
@@ -425,6 +427,7 @@ test.describe('POST /v1/template', () => {
425427
expect(created).toEqual({
426428
statusCode: 201,
427429
template: {
430+
campaignId: testClients[user1.clientKey]?.campaignId,
428431
createdAt: expect.stringMatching(isoDateRegExp),
429432
id: expect.stringMatching(uuidRegExp),
430433
message: template.message,
@@ -632,6 +635,7 @@ test.describe('POST /v1/template', () => {
632635
expect(created).toEqual({
633636
statusCode: 201,
634637
template: {
638+
campaignId: testClients[user1.clientKey]?.campaignId,
635639
createdAt: expect.stringMatching(isoDateRegExp),
636640
id: expect.stringMatching(uuidRegExp),
637641
message: template.message,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ test.describe('GET /v1/client-configuration', () => {
7272
expect(await response.json()).toEqual({
7373
statusCode: 200,
7474
clientConfiguration: {
75-
campaignId: testClients[userWithClient.clientKey!]?.campaignId,
76-
features: testClients[userWithClient.clientKey!]?.features,
75+
campaignId: testClients[userWithClient.clientKey]?.campaignId,
76+
features: testClients[userWithClient.clientKey]?.features,
7777
},
7878
});
7979
});

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
SimulatePassedValidation,
1818
} from '../helpers/use-cases';
1919
import { EmailHelper } from '../helpers/email-helper';
20+
import { testClients } from '../helpers/client/client-helper';
2021

2122
test.describe('POST /v1/template/:templateId/submit', () => {
2223
const authHelper = createAuthHelper();
@@ -512,7 +513,7 @@ test.describe('POST /v1/template/:templateId/submit', () => {
512513
expect(updated).toEqual({
513514
statusCode: 200,
514515
template: {
515-
campaignId: created.campaignId,
516+
campaignId: testClients[user1.clientKey]?.campaignId,
516517
createdAt: expect.stringMatching(isoDateRegExp),
517518
id: expect.stringMatching(uuidRegExp),
518519
message: created.template.message,
@@ -674,7 +675,7 @@ test.describe('POST /v1/template/:templateId/submit', () => {
674675
expect(updated).toEqual({
675676
statusCode: 200,
676677
template: {
677-
campaignId: created.campaignId,
678+
campaignId: testClients[user1.clientKey]?.campaignId,
678679
createdAt: expect.stringMatching(isoDateRegExp),
679680
id: expect.stringMatching(uuidRegExp),
680681
message: created.template.message,
@@ -836,7 +837,7 @@ test.describe('POST /v1/template/:templateId/submit', () => {
836837
expect(updated).toEqual({
837838
statusCode: 200,
838839
template: {
839-
campaignId: created.campaignId,
840+
campaignId: testClients[user1.clientKey]?.campaignId,
840841
createdAt: expect.stringMatching(isoDateRegExp),
841842
id: expect.stringMatching(uuidRegExp),
842843
message: created.template.message,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ test.describe('POST /v1/template/:templateId', () => {
292292
expect(updated).toEqual({
293293
statusCode: 200,
294294
template: {
295-
campaignId: testClients[user1.clientKey!]?.campaignId,
295+
campaignId: testClients[user1.clientKey]?.campaignId,
296296
createdAt: expect.stringMatching(isoDateRegExp),
297297
id: expect.stringMatching(uuidRegExp),
298298
message: updateData.message,
@@ -867,7 +867,7 @@ test.describe('POST /v1/template/:templateId', () => {
867867
expect(updated).toEqual({
868868
statusCode: 200,
869869
template: {
870-
campaignId: testClients[user1.clientKey!]?.campaignId,
870+
campaignId: testClients[user1.clientKey]?.campaignId,
871871
createdAt: expect.stringMatching(isoDateRegExp),
872872
id: expect.stringMatching(uuidRegExp),
873873
message: updateData.message,
@@ -1395,7 +1395,7 @@ test.describe('POST /v1/template/:templateId', () => {
13951395
expect(updated).toEqual({
13961396
statusCode: 200,
13971397
template: {
1398-
campaignId: testClients[user1.clientKey!]?.campaignId,
1398+
campaignId: testClients[user1.clientKey]?.campaignId,
13991399
createdAt: expect.stringMatching(isoDateRegExp),
14001400
id: expect.stringMatching(uuidRegExp),
14011401
message: updateData.message,

0 commit comments

Comments
 (0)