Skip to content

Commit 8e16fdb

Browse files
committed
add send proof request test back
1 parent 861a59f commit 8e16fdb

File tree

8 files changed

+195
-21
lines changed

8 files changed

+195
-21
lines changed

data-migration/user-transfer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# UserWithOptionalClient Transfer Data Migration
1+
# User Transfer Data Migration
22

33
The purpose of this tool is to transfer templates stored in DynamoDB from one owner to another. It does not transfer ownership of any files in S3, this would need to be done separately.
44

lambdas/sftp-letters/src/app/request-proof.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ export class App {
4343
const { sftpClient: sftp, baseUploadDir } =
4444
await this.sftpSupplierClientRepository.getClient(supplier);
4545

46-
const batchId = this.batch.getId(templateId, pdfVersionId);
47-
4846
const expandedTemplateId = this.getExpandedTemplateId({
4947
clientId: user.clientId,
5048
campaignId,
@@ -53,6 +51,8 @@ export class App {
5351
templateId,
5452
});
5553

54+
const batchId = this.batch.getId(expandedTemplateId, pdfVersionId);
55+
5656
const templateLogger = this.logger.child({
5757
batchId,
5858
expandedTemplateId,

tests/test-team/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ declare global {
88
NEXT_PUBLIC_ENABLE_PROOFING: string;
99
PLAYWRIGHT_RUN_ID: string;
1010
REQUEST_PROOF_QUEUE_URL: string;
11+
SEND_PROOF_QUEUE_URL: string;
1112
SFTP_ENVIRONMENT: string;
1213
SFTP_MOCK_CREDENTIAL_PATH: string;
1314
TEMPLATES_TABLE_NAME: string;

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TestUser } from '../auth/cognito-auth-helper';
2+
import { testClients } from '../client/client-helper';
23
import { Template } from '../types';
34
import { randomUUID } from 'node:crypto';
45

@@ -9,35 +10,38 @@ export const TemplateFactory = {
910
name: string = 'test'
1011
): Template => {
1112
return TemplateFactory.create({
13+
campaignId: testClients[user.clientKey]?.campaignId,
1214
clientId: user.clientId,
1315
id,
14-
owner: user.userId,
15-
name,
16-
templateType: 'EMAIL',
1716
message: 'test-message',
17+
name,
18+
owner: user.userId,
1819
subject: 'test-subject',
20+
templateType: 'EMAIL',
1921
});
2022
},
2123

2224
createSmsTemplate: (id: string, user: TestUser): Template => {
2325
return TemplateFactory.create({
26+
campaignId: testClients[user.clientKey]?.campaignId,
2427
clientId: user.clientId,
2528
id,
26-
owner: user.userId,
29+
message: 'test-message',
2730
name: 'test',
31+
owner: user.userId,
2832
templateType: 'SMS',
29-
message: 'test-message',
3033
});
3134
},
3235

3336
createNhsAppTemplate: (id: string, user: TestUser): Template => {
3437
return TemplateFactory.create({
38+
campaignId: testClients[user.clientKey]?.campaignId,
3539
clientId: user.clientId,
3640
id,
37-
owner: user.userId,
41+
message: 'test-message',
3842
name: 'test-name',
43+
owner: user.userId,
3944
templateType: 'NHS_APP',
40-
message: 'test-message',
4145
});
4246
},
4347

@@ -49,14 +53,8 @@ export const TemplateFactory = {
4953
virusScanStatus = 'PASSED'
5054
): Template => {
5155
return TemplateFactory.create({
56+
campaignId: testClients[user.clientKey]?.campaignId,
5257
clientId: user.clientId,
53-
id,
54-
owner: user.userId,
55-
name,
56-
templateStatus,
57-
templateType: 'LETTER',
58-
letterType: 'x0',
59-
language: 'en',
6058
files: {
6159
pdfTemplate: {
6260
fileName: 'file.pdf',
@@ -70,6 +68,13 @@ export const TemplateFactory = {
7068
},
7169
proofs: {},
7270
},
71+
id,
72+
language: 'en',
73+
letterType: 'x0',
74+
name,
75+
owner: user.userId,
76+
templateStatus,
77+
templateType: 'LETTER',
7378
});
7479
},
7580

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ export class SftpHelper {
3333
return sftpMockCredentials;
3434
}
3535

36+
public end = this.client.end.bind(this.client);
3637
public get = this.client.get.bind(this.client);
3738
public mkdir = this.client.mkdir.bind(this.client);
38-
public end = this.client.end.bind(this.client);
3939
public put = this.client.put.bind(this.client);
40+
public stat = this.client.stat.bind(this.client);
4041
}

tests/test-team/template-mgmt-e2e-tests/template-mgmt-proofing.e2e.spec.ts renamed to tests/test-team/template-mgmt-e2e-tests/template-mgmt-proof-polling.e2e.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const authHelper = createAuthHelper();
1515
const sftpHelper = new SftpHelper();
1616
const lambdaClient = new LambdaClient({ region: 'eu-west-2' });
1717

18-
test.describe('Letter Proofing', () => {
18+
test.describe('Letter Proof Polling', () => {
1919
test.beforeAll(async () => {
2020
await sftpHelper.connect();
2121
});
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
import { test, expect } from '@playwright/test';
2+
import { TemplateStorageHelper } from '../helpers/db/template-storage-helper';
3+
import {
4+
createAuthHelper,
5+
testUsers,
6+
type TestUser,
7+
} from '../helpers/auth/cognito-auth-helper';
8+
import { pdfUploadFixtures } from '../fixtures/pdf-upload/multipart-pdf-letter-fixtures';
9+
import { TemplateFactory } from '../helpers/factories/template-factory';
10+
import path from 'node:path';
11+
import { randomUUID } from 'node:crypto';
12+
import { SftpHelper } from '../helpers/sftp/sftp-helper';
13+
import { SqsHelper } from '../helpers/sqs/sqs-helper';
14+
import { testClients } from '../helpers/client/client-helper';
15+
16+
const MOCK_LETTER_SUPPLIER = 'WTMMOCK';
17+
18+
const sqsHelper = new SqsHelper();
19+
const sftpHelper = new SftpHelper();
20+
21+
test.describe('SFTP proof request send', () => {
22+
const templateStorageHelper = new TemplateStorageHelper();
23+
let user: TestUser;
24+
25+
test.beforeAll(async () => {
26+
user = await createAuthHelper().getTestUser(testUsers.User1.userId);
27+
});
28+
29+
test.afterAll(async () => {
30+
await templateStorageHelper.deleteAdHocTemplates();
31+
await sftpHelper.end();
32+
});
33+
34+
test('Sends PDF and test batch to SFTP, updates template', async () => {
35+
const templateId = randomUUID();
36+
37+
const personalisationParameters = [
38+
'date',
39+
'nhsNumber',
40+
'fullName',
41+
'address_line_1',
42+
'address_line_2',
43+
'address_line_3',
44+
'address_line_4',
45+
'address_line_5',
46+
'address_line_6',
47+
'address_line_7',
48+
'appointment_date',
49+
'appointment_time',
50+
'appointment_location',
51+
'contact_telephone_number',
52+
];
53+
54+
const template = {
55+
...TemplateFactory.createLetterTemplate(
56+
templateId,
57+
user,
58+
'send-proof-letter',
59+
'PENDING_PROOF_REQUEST'
60+
),
61+
// the template's 'personalisationParameters' have no effect on the test
62+
// the sender lambda does not read the template
63+
personalisationParameters,
64+
};
65+
66+
const key = {
67+
id: templateId,
68+
owner: user.userId,
69+
};
70+
71+
const pdfVersionId = template.files?.pdfTemplate?.currentVersion;
72+
const csvVersionId = template.files?.testDataCsv?.currentVersion;
73+
74+
const campaignId = testClients[user.clientKey]?.campaignId;
75+
76+
expect(pdfVersionId).toBeDefined();
77+
expect(csvVersionId).toBeDefined();
78+
79+
const pdf = pdfUploadFixtures.withPersonalisation.pdf.open();
80+
const csv = pdfUploadFixtures.withPersonalisation.csv.open();
81+
82+
await Promise.all([
83+
templateStorageHelper.seedTemplateData([template]),
84+
templateStorageHelper.putScannedPdfTemplateFile(key, pdfVersionId!, pdf),
85+
templateStorageHelper.putScannedCsvTestDataFile(key, csvVersionId!, csv),
86+
]);
87+
88+
templateStorageHelper.addAdHocTemplateKey(key);
89+
90+
const proofRequest = {
91+
campaignId,
92+
language: template.language,
93+
letterType: template.letterType,
94+
pdfVersionId,
95+
personalisationParameters,
96+
supplier: MOCK_LETTER_SUPPLIER,
97+
templateId: templateId,
98+
templateName: template.name,
99+
testDataVersionId: csvVersionId,
100+
user: { userId: user.userId, clientId: user.clientId },
101+
};
102+
103+
await sqsHelper.sendMessage(
104+
process.env.REQUEST_PROOF_QUEUE_URL,
105+
proofRequest
106+
);
107+
108+
await expect(async () => {
109+
const updatedTemplate = await templateStorageHelper.getTemplate(key);
110+
const debugUpdated = JSON.stringify(updatedTemplate);
111+
112+
expect(updatedTemplate.updatedAt, debugUpdated).not.toBe(
113+
template.updatedAt
114+
);
115+
}).toPass({ timeout: 5000 });
116+
117+
const sftpCredentials = await sftpHelper.connect();
118+
119+
const sftpBase = path.join(
120+
sftpCredentials.baseUploadDir,
121+
process.env.SFTP_ENVIRONMENT
122+
);
123+
124+
const expandedTemplateId = [
125+
user.clientId,
126+
campaignId,
127+
templateId,
128+
template.language,
129+
template.letterType,
130+
].join('_');
131+
132+
const pdfLocation = path.join(
133+
sftpBase,
134+
'templates',
135+
expandedTemplateId,
136+
`${expandedTemplateId}.pdf`
137+
);
138+
139+
const batchId = `${expandedTemplateId}-0000000000000_${pdfVersionId!.replaceAll('-', '').slice(0, 27)}`;
140+
141+
const batchLocation = path.join(
142+
sftpBase,
143+
'batches',
144+
expandedTemplateId,
145+
`${batchId}.csv`
146+
);
147+
148+
const manifestLocation = path.join(
149+
sftpBase,
150+
'batches',
151+
expandedTemplateId,
152+
`${batchId}_MANIFEST.csv`
153+
);
154+
155+
await expect(async () => {
156+
const locations = [pdfLocation, batchLocation, manifestLocation];
157+
158+
const files = await Promise.all(
159+
locations.map((location) => sftpHelper.stat(location))
160+
);
161+
162+
for (const [i, file] of files.entries()) {
163+
const dbg = locations[i];
164+
expect(file.isFile, dbg).toBeTruthy();
165+
expect(file.size, dbg).toBeGreaterThan(0);
166+
}
167+
}).toPass({ timeout: 10_000 });
168+
});
169+
});

utils/backend-config/src/backend-config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import fs from 'node:fs';
55
export type BackendConfig = {
66
apiBaseUrl: string;
77
clientSsmPathPrefix: string;
8-
sendProofQueueUrl: string;
98
requestProofQueueUrl: string;
109
sftpEnvironment: string;
1110
sftpPollLambdaName: string;
@@ -26,7 +25,6 @@ export const BackendConfigHelper = {
2625
return {
2726
apiBaseUrl: process.env.API_BASE_URL ?? '',
2827
clientSsmPathPrefix: process.env.CLIENT_SSM_PATH_PREFIX ?? '',
29-
sendProofQueueUrl: process.env.SEND_PROOF_QUEUE_URL ?? '',
3028
requestProofQueueUrl: process.env.REQUEST_PROOF_QUEUE_URL ?? '',
3129
sftpEnvironment: process.env.SFTP_ENVIRONMENT ?? '',
3230
sftpMockCredentialPath: process.env.SFTP_MOCK_CREDENTIAL_PATH ?? '',

0 commit comments

Comments
 (0)