Skip to content

Commit b9d0b51

Browse files
committed
CCM-10048: update event assertions to reduce duplication. Add a temporary script to create and env, run tests then delete env.
1 parent d6b1fe7 commit b9d0b51

File tree

5 files changed

+113
-42
lines changed

5 files changed

+113
-42
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ lambdas/backend-api/src/email/email-template.json
9090

9191
# vscode
9292
.vscode/settings.local.json
93+
94+
test-runs

run-e2e.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
#### DELETE once finished... ####
4+
5+
# Colors for output
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
NC='\033[0m' # No Color
10+
11+
# Function to print colored output
12+
print_status() {
13+
echo -e "${GREEN}[INFO]${NC} $1"
14+
}
15+
16+
print_warning() {
17+
echo -e "${YELLOW}[WARN]${NC} $1"
18+
}
19+
20+
print_error() {
21+
echo -e "${RED}[ERROR]${NC} $1"
22+
}
23+
24+
RANDOM_DIGITS=0056
25+
ENVIRONMENT_NAME="${RANDOM_DIGITS}flaky"
26+
TOTAL_RUNS=1
27+
export CI=1
28+
export SKIP_SANDBOX_INSTALL=1
29+
30+
31+
print_status "Starting automated E2E test suite - $TOTAL_RUNS iterations"
32+
echo "========================================================"
33+
34+
for i in $(seq 1 $TOTAL_RUNS); do
35+
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
36+
RUN_DIR="test-runs/$TIMESTAMP"
37+
38+
# Create run directory
39+
mkdir -p "$RUN_DIR"
40+
41+
print_status "Generated environment name: $ENVIRONMENT_NAME"
42+
43+
# Create backend sandbox
44+
print_status "Creating backend sandbox environment..."
45+
if ./scripts/create_backend_sandbox.sh "$ENVIRONMENT_NAME"; then
46+
print_status "Backend sandbox created successfully"
47+
else
48+
print_error "Failed to create backend sandbox"
49+
exit 1
50+
fi
51+
52+
# Run E2E tests
53+
print_status "Running E2E tests..."
54+
if npm run test:e2e --workspace tests/test-team; then
55+
print_status "E2E tests completed successfuly"
56+
else
57+
print_error "E2E tests failed"
58+
print_warning "Environment '$ENVIRONMENT_NAME' may still be running"
59+
fi
60+
61+
print_status "Moving test-report to test runs"
62+
if [ -d "tests/test-team/playwright-report" ]; then
63+
print_status "Copying Playwright report files..."
64+
cp -r tests/test-team/playwright-report/* "$RUN_DIR/" 2>/dev/null || true
65+
fi
66+
67+
# Destory environment
68+
print_status "Destorying $ENVIRONMENT_NAME env... "
69+
if ./scripts/destroy_backend_sandbox.sh "$ENVIRONMENT_NAME"; then
70+
print_status "Environment destroyed successfully"
71+
else
72+
print_warning "Could not automagically destroy environment. You may need to clean up manually."
73+
print_warning "Environment name: $ENVIRONMENT_NAME"
74+
fi
75+
done
76+
77+
print_status "Script completed"

tests/test-team/template-mgmt-e2e-tests/template-mgmt-letter-file-validation.e2e.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,10 +706,7 @@ test.describe('letter file validation', () => {
706706
});
707707

708708
await expect(async () => {
709-
const template = await templateStorageHelper.getTemplate({
710-
id: templateId,
711-
owner: user.userId,
712-
});
709+
const template = await templateStorageHelper.getTemplate(key);
713710

714711
expect(template.files?.pdfTemplate?.virusScanStatus).toBe('PASSED');
715712
expect(template.files?.testDataCsv?.virusScanStatus).toBe('PASSED');

tests/test-team/template-mgmt-e2e-tests/template-mgmt-letter-full.e2e.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ import {
2020

2121
const lambdaClient = new LambdaClient({ region: 'eu-west-2' });
2222

23-
const getProofRandomSegment = (value?: string) =>
24-
value?.replaceAll('-', '').slice(0, 27);
25-
2623
// eslint-disable-next-line playwright/no-skipped-test
2724
test.describe('letter complete e2e journey', () => {
2825
const templateStorageHelper = new TemplateStorageHelper();
@@ -162,22 +159,24 @@ test.describe('letter complete e2e journey', () => {
162159

163160
const template = await templateStorageHelper.getTemplate(key);
164161

162+
const batchId = `${key.id}-0000000000000_${template.files?.pdfTemplate?.currentVersion.replaceAll('-', '').slice(0, 27)}`;
163+
165164
await assertProofGuardDutyEvent({
166165
key,
167166
scanResult: 'NO_THREATS_FOUND',
168-
fileName: `${key.id}-0000000000000_${getProofRandomSegment(template.files?.pdfTemplate?.currentVersion)}_proof_1.pdf`,
167+
fileName: `${batchId}_proof_1.pdf`,
169168
});
170169

171170
await assertProofGuardDutyEvent({
172171
key,
173172
scanResult: 'NO_THREATS_FOUND',
174-
fileName: `${key.id}-0000000000000_${getProofRandomSegment(template.files?.pdfTemplate?.currentVersion)}_proof_2.pdf`,
173+
fileName: `${batchId}_proof_2.pdf`,
175174
});
176175

177176
await assertProofGuardDutyEvent({
178177
key,
179178
scanResult: 'NO_THREATS_FOUND',
180-
fileName: `${key.id}-0000000000000_${getProofRandomSegment(template.files?.pdfTemplate?.currentVersion)}_proof_3.pdf`,
179+
fileName: `${batchId}_proof_3.pdf`,
181180
});
182181

183182
await expect(async () => {

tests/test-team/template-mgmt-e2e-tests/template-mgmt-letter-guardduty.steps.ts

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ import { GuardDutyScanResult } from '../helpers/eventbridge/eventbridge-helper';
44
import { TemplateStorageHelper } from '../helpers/db/template-storage-helper';
55
import { Template, TemplateFile } from '../helpers/types';
66

7-
type AssertConfig = {
7+
type EventConfig = {
88
key: { id: string; owner: string };
99
scanResult: GuardDutyScanResult;
10-
timeout?: number;
1110
};
1211

1312
type FileConfig = {
1413
pathPrefix: 'pdf-template' | 'test-data' | 'proofs';
15-
extension: '.pdf' | '.csv';
1614
getFile: (template: Template) => TemplateFile | undefined;
15+
getPath: (template: Template, file?: TemplateFile) => string;
1716
};
1817

18+
const guardDutyScan = new SimulateGuardDutyScan();
19+
const templateStorageHelper = new TemplateStorageHelper();
20+
1921
function assertGuardDutyEventForFile(
20-
{ key, scanResult, timeout = 60_000 }: AssertConfig,
21-
{ pathPrefix, extension, getFile }: FileConfig
22+
event: EventConfig,
23+
fileConfig: FileConfig
2224
) {
23-
const guardDutyScan = new SimulateGuardDutyScan();
24-
const templateStorageHelper = new TemplateStorageHelper();
25+
const { key, scanResult } = event;
26+
const { pathPrefix, getFile, getPath } = fileConfig;
2527

2628
return test.step(`when user uploads ${pathPrefix} file, then guardduty triggers ${scanResult}`, async () => {
2729
await expect(async () => {
@@ -33,54 +35,48 @@ function assertGuardDutyEventForFile(
3335
return true;
3436
}
3537

38+
const path = getPath(template, file);
39+
3640
const published = await guardDutyScan.publish({
3741
type: scanResult,
38-
path: `${pathPrefix}/${template.owner}/${template.id}/${file?.currentVersion}${extension}`,
42+
path,
3943
});
4044

4145
expect(published).toEqual(true);
42-
}).toPass({ timeout });
46+
}).toPass({ timeout: 60_000 });
4347
});
4448
}
4549

46-
export function assertPdfTemplateGuardDutyEvent(props: AssertConfig) {
50+
export function assertPdfTemplateGuardDutyEvent(props: EventConfig) {
4751
return assertGuardDutyEventForFile(props, {
4852
pathPrefix: 'pdf-template',
49-
extension: '.pdf',
5053
getFile: (template) => template.files?.pdfTemplate,
54+
getPath: (template, file) =>
55+
`pdf-template/${template.owner}/${template.id}/${file?.currentVersion}.pdf`,
5156
});
5257
}
5358

54-
export function assertTestDataGuardDutyEvent(props: AssertConfig) {
59+
export function assertTestDataGuardDutyEvent(props: EventConfig) {
5560
return assertGuardDutyEventForFile(props, {
5661
pathPrefix: 'test-data',
57-
extension: '.csv',
5862
getFile: (template) => template.files?.testDataCsv,
63+
getPath: (template, file) =>
64+
`test-data/${template.owner}/${template.id}/${file?.currentVersion}.csv`,
5965
});
6066
}
6167

6268
export function assertProofGuardDutyEvent(
63-
props: AssertConfig & { fileName: string }
69+
props: EventConfig & { fileName: string }
6470
) {
65-
const guardDutyScan = new SimulateGuardDutyScan();
66-
const templateStorageHelper = new TemplateStorageHelper();
67-
68-
return test.step(`when user receives proof file, then guardduty triggers ${props.scanResult}`, async () => {
69-
await expect(async () => {
70-
const template = await templateStorageHelper.getTemplate(props.key);
71-
72-
const proof = template.files?.proofs?.[props.fileName];
71+
return assertGuardDutyEventForFile(props, {
72+
pathPrefix: 'proofs',
73+
getFile: (template) => {
74+
const file = template.files?.proofs?.[props.fileName];
7375

74-
if (proof && proof.virusScanStatus !== 'PENDING') {
75-
return true;
76+
if (file) {
77+
return { ...file, currentVersion: 'unknown' };
7678
}
77-
78-
const published = await guardDutyScan.publish({
79-
type: props.scanResult,
80-
path: `proofs/${props.key.id}/${props.fileName}`,
81-
});
82-
83-
expect(published).toEqual(true);
84-
}).toPass({ timeout: 60_000 });
79+
},
80+
getPath: () => `proofs/${props.key.id}/${props.fileName}`,
8581
});
8682
}

0 commit comments

Comments
 (0)