Skip to content

Commit 413277d

Browse files
committed
CCM-8572: add e2e tests
1 parent 1400d02 commit 413277d

File tree

24 files changed

+14496
-19422
lines changed

24 files changed

+14496
-19422
lines changed

infrastructure/terraform/components/sandbox/outputs.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ output "cognito_user_pool_client_id" {
1313
output "templates_table_name" {
1414
value = module.backend_api.templates_table_name
1515
}
16+
17+
output "internal_bucket_name" {
18+
value = module.backend_api.internal_bucket_name
19+
}
20+
21+
output "quarantine_bucket_name" {
22+
value = module.backend_api.quarantine_bucket_name
23+
}

infrastructure/terraform/modules/backend-api/outputs.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ output "api_base_url" {
55
output "templates_table_name" {
66
value = aws_dynamodb_table.templates.name
77
}
8+
9+
output "internal_bucket_name" {
10+
value = module.s3bucket_internal.id
11+
}
12+
13+
output "quarantine_bucket_name" {
14+
value = module.s3bucket_quarantine.id
15+
}

lambdas/backend-api/src/templates/infra/letter-upload-repository.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class LetterUploadRepository {
3939
Bucket: this.bucketName,
4040
Key: pdfKey,
4141
Body: await pdf.bytes(),
42+
ChecksumAlgorithm: 'SHA256',
4243
Metadata: this.metadata(
4344
owner,
4445
pdf.name,
@@ -58,6 +59,7 @@ export class LetterUploadRepository {
5859
Bucket: this.bucketName,
5960
Key: csvKey,
6061
Body: await csv.bytes(),
62+
ChecksumAlgorithm: 'SHA256',
6163
Metadata: this.metadata(
6264
owner,
6365
csv.name,

package-lock.json

Lines changed: 13979 additions & 19379 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import path from 'node:path';
22
import { defineConfig, devices } from '@playwright/test';
33
import baseConfig from '../playwright.config';
44

5+
const buildCommand = [
6+
'INCLUDE_AUTH_PAGES=true',
7+
'NEXT_PUBLIC_TIME_TILL_LOGOUT_SECONDS=25',
8+
'NEXT_PUBLIC_PROMPT_SECONDS_BEFORE_LOGOUT=5',
9+
'NEXT_PUBLIC_ENABLE_LETTERS=true',
10+
'npm run build && npm run start',
11+
].join(' ');
12+
513
export default defineConfig({
614
...baseConfig,
715

@@ -11,18 +19,37 @@ export default defineConfig({
1119
},
1220
projects: [
1321
{
14-
name: 'e2e-local',
22+
name: 'e2e:setup',
23+
testMatch: 'e2e.setup.ts',
24+
use: {
25+
baseURL: 'http://localhost:3000',
26+
...devices['Desktop Chrome'],
27+
headless: true,
28+
screenshot: 'only-on-failure',
29+
},
30+
},
31+
{
32+
name: 'e2e',
1533
testMatch: '*.e2e.spec.ts',
1634
use: {
35+
screenshot: 'only-on-failure',
1736
baseURL: 'http://localhost:3000',
1837
...devices['Desktop Chrome'],
38+
headless: true,
39+
storageState: path.resolve(__dirname, '../.auth/e2e/user.json'),
1940
},
41+
dependencies: ['e2e:setup'],
42+
teardown: 'e2e:teardown',
43+
},
44+
{
45+
name: 'e2e:teardown',
46+
testMatch: 'e2e.teardown.ts',
2047
},
2148
],
2249
/* Run your local dev server before starting the tests */
2350
webServer: {
2451
timeout: 2 * 60 * 1000, // 2 minutes
25-
command: 'npm run build && npm run start',
52+
command: buildCommand,
2653
cwd: path.resolve(__dirname, '../../../..'),
2754
url: 'http://localhost:3000/templates/create-and-submit-templates',
2855
reuseExistingServer: !process.env.CI,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Playwright setting up Auth -> https://playwright.dev/docs/auth
3+
*/
4+
5+
import path from 'node:path';
6+
import { test as setup } from '@playwright/test';
7+
import { BackendConfigHelper } from 'nhs-notify-web-template-management-util-backend-config';
8+
import { TemplateMgmtSignInPage } from '../../pages/templates-mgmt-login-page';
9+
import {
10+
createAuthHelper,
11+
TestUserId,
12+
} from '../../helpers/auth/cognito-auth-helper';
13+
14+
setup('e2e test setup', async ({ page }) => {
15+
const backendConfig = BackendConfigHelper.fromTerraformOutputsFile(
16+
path.join(__dirname, '..', '..', '..', '..', 'sandbox_tf_outputs.json')
17+
);
18+
19+
BackendConfigHelper.toEnv(backendConfig);
20+
21+
const auth = createAuthHelper();
22+
23+
await auth.setup();
24+
25+
const user = await auth.getTestUser(TestUserId.User1);
26+
27+
const loginPage = new TemplateMgmtSignInPage(page);
28+
29+
await loginPage.loadPage();
30+
31+
await loginPage.cognitoSignIn(user);
32+
33+
await page.waitForURL('/templates/create-and-submit-templates');
34+
35+
await page.context().storageState({
36+
path: path.resolve(__dirname, '..', '.auth', 'e2e', 'user.json'),
37+
});
38+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { test as teardown } from '@playwright/test';
2+
import { createAuthHelper } from '../../helpers/auth/cognito-auth-helper';
3+
4+
teardown('e2e test teardown', async () => {
5+
await createAuthHelper().teardown();
6+
});

tests/test-team/fixtures/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test Fixtures
2+
3+
## Custom Matchers
4+
5+
Custom playwright matchers
6+
7+
## PDF Upload
8+
9+
Files for use with letter templates.
10+
11+
For all files `password.pdf`, the password is `password`.

tests/test-team/fixtures/custom-matchers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect } from '@playwright/test';
33
expect.extend({
44
/**
55
* Asserts that a value is parsable as a date, and is roughly within the given range.
6-
* Roughly means that the received value can be be within 1 second either side of the range.
6+
* "Roughly" means that the received value can be within 1 second either side of the range.
77
* This helps deal with local machines being out of sync with remote servers
88
*/
99
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,54 @@
11
/* eslint-disable security/detect-non-literal-fs-filename */
2+
import { createHash } from 'node:crypto';
23
import { readFileSync } from 'node:fs';
34
import path from 'node:path';
45

5-
const getFile = (directory: string, filename: string) =>
6-
readFileSync(path.resolve(__dirname, directory, filename));
6+
const files = new Map<string, { data: Buffer; checksumSha256: string }>();
7+
8+
const loadFile = (filepath: string) => {
9+
const data = readFileSync(filepath);
10+
const checksumSha256 = sha256(data);
11+
const file = { data, checksumSha256 };
12+
files.set(filepath, file);
13+
return file;
14+
};
15+
16+
const sha256 = (data: Buffer) =>
17+
createHash('sha256').update(data).digest('base64');
18+
19+
const getFile = (directory: string, filename: string) => {
20+
const filepath = path.resolve(__dirname, directory, filename);
21+
22+
return {
23+
filepath,
24+
open: () => {
25+
const opened = files.get(filepath);
26+
27+
if (opened) {
28+
return opened.data;
29+
}
30+
31+
return loadFile(filepath).data;
32+
},
33+
checksumSha256: () => {
34+
const opened = files.get(filepath);
35+
if (opened) {
36+
return opened.checksumSha256;
37+
}
38+
39+
return loadFile(filepath).checksumSha256;
40+
},
41+
};
42+
};
743

844
export const pdfUploadFixtures = {
945
withPersonalisation: {
1046
pdf: getFile('with-personalisation', 'template.pdf'),
1147
csv: getFile('with-personalisation', 'test-data.csv'),
48+
passwordPdf: getFile('with-personalisation', 'password.pdf'),
1249
},
1350
noCustomPersonalisation: {
1451
pdf: getFile('no-custom-personalisation', 'template.pdf'),
52+
passwordPdf: getFile('no-custom-personalisation', 'password.pdf'),
1553
},
1654
};

0 commit comments

Comments
 (0)