Skip to content

Commit 9c06f79

Browse files
committed
CCM-11353: configure event e2e tests to run in pipeline
1 parent 2803dec commit 9c06f79

File tree

6 files changed

+223
-1
lines changed

6 files changed

+223
-1
lines changed

.github/actions/test-types.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"accessibility",
33
"ui-component",
44
"ui-e2e",
5-
"api"
5+
"api",
6+
"event"
67
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { defineConfig } from '@playwright/test';
2+
import baseConfig from '../playwright.config';
3+
4+
export default defineConfig({
5+
...baseConfig,
6+
7+
timeout: 10_000,
8+
workers: 1,
9+
projects: [
10+
{
11+
name: 'event:setup',
12+
testMatch: 'event.setup.ts',
13+
},
14+
{
15+
name: 'event',
16+
testMatch: '*.event.spec.ts',
17+
dependencies: ['event:setup'],
18+
teardown: 'event:teardown',
19+
},
20+
{
21+
name: 'event:teardown',
22+
testMatch: 'event.teardown.ts',
23+
},
24+
],
25+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import path from 'node:path';
2+
import { test as setup } from '@playwright/test';
3+
import { BackendConfigHelper } from 'nhs-notify-web-template-management-util-backend-config';
4+
import { createAuthHelper } from '../../helpers/auth/cognito-auth-helper';
5+
6+
setup('event test setup', async () => {
7+
const backendConfig = BackendConfigHelper.fromTerraformOutputsFile(
8+
path.join(__dirname, '..', '..', '..', '..', 'sandbox_tf_outputs.json')
9+
);
10+
11+
BackendConfigHelper.toEnv(backendConfig);
12+
13+
await createAuthHelper().setup();
14+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { test as setup } from '@playwright/test';
2+
import { createAuthHelper } from '../../helpers/auth/cognito-auth-helper';
3+
4+
setup('event test teardown', async () => {
5+
await createAuthHelper().teardown();
6+
});

tests/test-team/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"lint": "eslint .",
2929
"lint:fix": "npm run lint -- --fix",
3030
"test:api": "playwright test --project api -c config/api/api.config.ts",
31+
"test:event": "playwright test -c config/event/event.config.ts",
3132
"test:e2e": "playwright test --project e2e -c config/e2e/e2e.config.ts",
3233
"test:local-ui": "playwright test -c config/component/component.config.ts",
3334
"test:unit": "echo \"Unit tests not required\"",
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
import { test, expect } from '@playwright/test';
2+
import {
3+
createAuthHelper,
4+
type TestUser,
5+
testUsers,
6+
} from '../helpers/auth/cognito-auth-helper';
7+
import { TemplateStorageHelper } from '../helpers/db/template-storage-helper';
8+
import {
9+
isoDateRegExp,
10+
uuidRegExp,
11+
} from 'nhs-notify-web-template-management-test-helper-utils';
12+
import { TemplateAPIPayloadFactory } from '../helpers/factories/template-api-payload-factory';
13+
import { testClients } from '../helpers/client/client-helper';
14+
15+
test.describe('POST /v1/template', () => {
16+
const authHelper = createAuthHelper();
17+
const templateStorageHelper = new TemplateStorageHelper();
18+
let user1: TestUser;
19+
20+
test.beforeAll(async () => {
21+
user1 = await authHelper.getTestUser(testUsers.User1.userId);
22+
});
23+
24+
test.afterAll(async () => {
25+
await templateStorageHelper.deleteAdHocTemplates();
26+
});
27+
28+
test.describe('NHS_APP templates', () => {
29+
test('returns 201 if template is valid', async ({ request }) => {
30+
const template = TemplateAPIPayloadFactory.getCreateTemplatePayload({
31+
templateType: 'NHS_APP',
32+
});
33+
34+
const start = new Date();
35+
36+
const response = await request.post(
37+
`${process.env.API_BASE_URL}/v1/template`,
38+
{
39+
headers: {
40+
Authorization: await user1.getAccessToken(),
41+
},
42+
data: template,
43+
}
44+
);
45+
46+
expect(response.status()).toBe(201);
47+
48+
const created = await response.json();
49+
50+
templateStorageHelper.addAdHocTemplateKey({
51+
id: created.template.id,
52+
owner: user1.userId,
53+
});
54+
55+
expect(created).toEqual({
56+
statusCode: 201,
57+
template: {
58+
campaignId: testClients[user1.clientKey]?.campaignId,
59+
createdAt: expect.stringMatching(isoDateRegExp),
60+
id: expect.stringMatching(uuidRegExp),
61+
message: template.message,
62+
name: template.name,
63+
templateStatus: 'NOT_YET_SUBMITTED',
64+
templateType: template.templateType,
65+
updatedAt: expect.stringMatching(isoDateRegExp),
66+
},
67+
});
68+
69+
expect(created.template.createdAt).toBeDateRoughlyBetween([
70+
start,
71+
new Date(),
72+
]);
73+
expect(created.template.createdAt).toEqual(created.template.updatedAt);
74+
});
75+
});
76+
77+
test.describe('SMS templates', () => {
78+
test('returns 201 if template is valid', async ({ request }) => {
79+
const template = TemplateAPIPayloadFactory.getCreateTemplatePayload({
80+
templateType: 'SMS',
81+
});
82+
83+
const start = new Date();
84+
85+
const response = await request.post(
86+
`${process.env.API_BASE_URL}/v1/template`,
87+
{
88+
headers: {
89+
Authorization: await user1.getAccessToken(),
90+
},
91+
data: template,
92+
}
93+
);
94+
95+
expect(response.status()).toBe(201);
96+
97+
const created = await response.json();
98+
99+
templateStorageHelper.addAdHocTemplateKey({
100+
id: created.template.id,
101+
owner: user1.userId,
102+
});
103+
104+
expect(created).toEqual({
105+
statusCode: 201,
106+
template: {
107+
campaignId: testClients[user1.clientKey]?.campaignId,
108+
createdAt: expect.stringMatching(isoDateRegExp),
109+
id: expect.stringMatching(uuidRegExp),
110+
message: template.message,
111+
name: template.name,
112+
templateStatus: 'NOT_YET_SUBMITTED',
113+
templateType: template.templateType,
114+
updatedAt: expect.stringMatching(isoDateRegExp),
115+
},
116+
});
117+
118+
expect(created.template.createdAt).toBeDateRoughlyBetween([
119+
start,
120+
new Date(),
121+
]);
122+
expect(created.template.createdAt).toEqual(created.template.updatedAt);
123+
});
124+
});
125+
126+
test.describe('EMAIL templates', () => {
127+
test('returns 201 if template is valid', async ({ request }) => {
128+
const template = TemplateAPIPayloadFactory.getCreateTemplatePayload({
129+
templateType: 'EMAIL',
130+
});
131+
132+
const start = new Date();
133+
134+
const response = await request.post(
135+
`${process.env.API_BASE_URL}/v1/template`,
136+
{
137+
headers: {
138+
Authorization: await user1.getAccessToken(),
139+
},
140+
data: template,
141+
}
142+
);
143+
144+
expect(response.status()).toBe(201);
145+
146+
const created = await response.json();
147+
148+
templateStorageHelper.addAdHocTemplateKey({
149+
id: created.template.id,
150+
owner: user1.userId,
151+
});
152+
153+
expect(created).toEqual({
154+
statusCode: 201,
155+
template: {
156+
campaignId: testClients[user1.clientKey]?.campaignId,
157+
createdAt: expect.stringMatching(isoDateRegExp),
158+
id: expect.stringMatching(uuidRegExp),
159+
message: template.message,
160+
name: template.name,
161+
subject: template.subject,
162+
templateStatus: 'NOT_YET_SUBMITTED',
163+
templateType: template.templateType,
164+
updatedAt: expect.stringMatching(isoDateRegExp),
165+
},
166+
});
167+
168+
expect(created.template.createdAt).toBeDateRoughlyBetween([
169+
start,
170+
new Date(),
171+
]);
172+
expect(created.template.createdAt).toEqual(created.template.updatedAt);
173+
});
174+
});
175+
});

0 commit comments

Comments
 (0)