Skip to content

Commit 1e7ec5f

Browse files
committed
api tests
1 parent 8fd08a5 commit 1e7ec5f

File tree

50 files changed

+961
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+961
-413
lines changed

lambdas/backend-api/src/__tests__/templates/api/process-proof.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ test.each([
4141
'calls dependencies as expected for a %s virus scan',
4242
async (scanResultStatus, virusScanStatus, s3Expectation) => {
4343
const templateRepository = mockDeep<TemplateRepository>({
44-
getOwner: jest
44+
getClientId: jest
4545
.fn()
46-
.mockReturnValue({ owner: 'template-owner', clientOwned: true }),
46+
.mockReturnValue({ clientId: 'template-owner', clientOwned: true }),
4747
});
4848
const letterFileRepository = mockDeep<LetterFileRepository>();
4949

@@ -63,14 +63,18 @@ test.each([
6363
},
6464
});
6565

66-
expect(templateRepository.getOwner).toHaveBeenCalledWith('template-id');
66+
expect(templateRepository.getClientId).toHaveBeenCalledWith('template-id');
6767

6868
s3Expectation(letterFileRepository);
6969

7070
expect(
7171
templateRepository.setLetterFileVirusScanStatusForProof
7272
).toHaveBeenCalledWith(
73-
{ owner: 'template-owner', id: 'template-id', clientOwned: true },
73+
{
74+
clientId: 'template-owner',
75+
templateId: 'template-id',
76+
clientOwned: true,
77+
},
7478
'proof.pdf',
7579
virusScanStatus,
7680
'supplier'

lambdas/backend-api/src/__tests__/templates/api/set-letter-upload-virus-scan-status.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ it('sets the virus scan status on pdf uploads identified by file metadata', asyn
2929
},
3030
});
3131

32-
mocks.templateRepository.getOwner.mockResolvedValueOnce({
33-
owner: 'template-owner',
32+
mocks.templateRepository.getClientId.mockResolvedValueOnce({
33+
clientId: 'template-owner',
3434
clientOwned: true,
3535
});
3636

@@ -39,7 +39,7 @@ it('sets the virus scan status on pdf uploads identified by file metadata', asyn
3939
expect(
4040
mocks.templateRepository.setLetterFileVirusScanStatusForUpload
4141
).toHaveBeenCalledWith(
42-
{ id: 'template-id', owner: 'template-owner', clientOwned: true },
42+
{ templateId: 'template-id', clientId: 'template-owner', clientOwned: true },
4343
'pdf-template',
4444
'template-version',
4545
'PASSED'
@@ -60,8 +60,8 @@ it('sets the virus scan status on csv files identified by file metadata', async
6060
},
6161
});
6262

63-
mocks.templateRepository.getOwner.mockResolvedValueOnce({
64-
owner: 'template-owner',
63+
mocks.templateRepository.getClientId.mockResolvedValueOnce({
64+
clientId: 'template-owner',
6565
clientOwned: true,
6666
});
6767

@@ -70,7 +70,7 @@ it('sets the virus scan status on csv files identified by file metadata', async
7070
expect(
7171
mocks.templateRepository.setLetterFileVirusScanStatusForUpload
7272
).toHaveBeenCalledWith(
73-
{ id: 'template-id', owner: 'template-owner', clientOwned: true },
73+
{ templateId: 'template-id', clientId: 'template-owner', clientOwned: true },
7474
'test-data',
7575
'template-version',
7676
'PASSED'
@@ -94,8 +94,8 @@ it.each($GuardDutyMalwareScanStatusFailed.options)(
9494
},
9595
});
9696

97-
mocks.templateRepository.getOwner.mockResolvedValueOnce({
98-
owner: 'template-owner',
97+
mocks.templateRepository.getClientId.mockResolvedValueOnce({
98+
clientId: 'template-owner',
9999
clientOwned: true,
100100
});
101101

@@ -104,7 +104,7 @@ it.each($GuardDutyMalwareScanStatusFailed.options)(
104104
expect(
105105
mocks.templateRepository.setLetterFileVirusScanStatusForUpload
106106
).toHaveBeenCalledWith(
107-
{ id: 'template-id', owner: 'template-owner', clientOwned: true },
107+
{ templateId: 'template-id', clientId: 'template-owner', clientOwned: true },
108108
'pdf-template',
109109
'template-version',
110110
'FAILED'
@@ -187,8 +187,8 @@ it('errors if status update fails', async () => {
187187
},
188188
});
189189

190-
mocks.templateRepository.getOwner.mockResolvedValueOnce({
191-
owner: 'template-owner',
190+
mocks.templateRepository.getClientId.mockResolvedValueOnce({
191+
clientId: 'template-owner',
192192
clientOwned: true,
193193
});
194194

@@ -215,8 +215,8 @@ it('errors if owner from database does not match s3 path', async () => {
215215
},
216216
});
217217

218-
mocks.templateRepository.getOwner.mockResolvedValueOnce({
219-
owner: 'someone-else',
218+
mocks.templateRepository.getClientId.mockResolvedValueOnce({
219+
clientId: 'someone-else',
220220
clientOwned: true,
221221
});
222222

lambdas/backend-api/src/__tests__/templates/api/validate-letter-template-files.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('guard duty handler', () => {
124124
);
125125

126126
expect(mocks.TemplatePdf).toHaveBeenCalledWith(
127-
{ id: templateId, owner: userId, clientOwned: false },
127+
{ templateId, clientId: userId, clientOwned: false },
128128
pdfData
129129
);
130130
expect(mocks.TestDataCsv).toHaveBeenCalledWith(csvData);
@@ -137,7 +137,7 @@ describe('guard duty handler', () => {
137137
expect(
138138
mocks.templateRepository.setLetterValidationResult
139139
).toHaveBeenCalledWith(
140-
{ id: templateId, owner: userId, clientOwned: false },
140+
{ templateId, clientId: userId, clientOwned: false },
141141
versionId,
142142
true,
143143
pdf.personalisationParameters,
@@ -206,7 +206,7 @@ describe('guard duty handler', () => {
206206
);
207207

208208
expect(mocks.TemplatePdf).toHaveBeenCalledWith(
209-
{ id: templateId, owner: clientId, clientOwned: true },
209+
{ templateId, clientId, clientOwned: true },
210210
pdfData
211211
);
212212

@@ -220,7 +220,7 @@ describe('guard duty handler', () => {
220220
expect(
221221
mocks.templateRepository.setLetterValidationResult
222222
).toHaveBeenCalledWith(
223-
{ id: templateId, owner: clientId, clientOwned: true },
223+
{ templateId, clientId, clientOwned: true },
224224
versionId,
225225
true,
226226
pdf.personalisationParameters,
@@ -295,7 +295,7 @@ describe('guard duty handler', () => {
295295

296296
// assert
297297
expect(mocks.TemplatePdf).toHaveBeenCalledWith(
298-
{ id: templateId, owner: userId, clientOwned: false },
298+
{ templateId, clientId: userId, clientOwned: false },
299299
pdfData
300300
);
301301
expect(mocks.TestDataCsv).toHaveBeenCalledWith(csvData);
@@ -305,7 +305,7 @@ describe('guard duty handler', () => {
305305
expect(
306306
mocks.templateRepository.setLetterValidationResult
307307
).toHaveBeenCalledWith(
308-
{ id: templateId, owner: userId, clientOwned: false },
308+
{ templateId, clientId: userId, clientOwned: false },
309309
versionId,
310310
true,
311311
['firstName', 'parameter_1', 'unknown_parameter'],
@@ -385,7 +385,7 @@ describe('guard duty handler', () => {
385385
expect(
386386
mocks.templateRepository.setLetterValidationResult
387387
).toHaveBeenCalledWith(
388-
{ id: templateId, owner: userId, clientOwned: false },
388+
{ templateId, clientId: userId, clientOwned: false },
389389
versionId,
390390
false,
391391
['firstName', 'parameter_1', 'unknown_parameter'],
@@ -453,7 +453,7 @@ describe('guard duty handler', () => {
453453
);
454454

455455
expect(mocks.TemplatePdf).toHaveBeenCalledWith(
456-
{ id: templateId, owner: userId, clientOwned: false },
456+
{ templateId, clientId: userId, clientOwned: false },
457457
pdfData
458458
);
459459
expect(mocks.TestDataCsv).not.toHaveBeenCalled();
@@ -468,7 +468,7 @@ describe('guard duty handler', () => {
468468
expect(
469469
mocks.templateRepository.setLetterValidationResult
470470
).toHaveBeenCalledWith(
471-
{ id: templateId, owner: userId, clientOwned: false },
471+
{ templateId, clientId: userId, clientOwned: false },
472472
versionId,
473473
true,
474474
pdf.personalisationParameters,
@@ -1157,7 +1157,7 @@ describe('guard duty handler', () => {
11571157
expect(
11581158
mocks.templateRepository.setLetterValidationResult
11591159
).toHaveBeenCalledWith(
1160-
{ id: templateId, owner: userId, clientOwned: false },
1160+
{ templateId, clientId: userId, clientOwned: false },
11611161
versionId,
11621162
false,
11631163
[],
@@ -1221,7 +1221,7 @@ describe('guard duty handler', () => {
12211221
expect(
12221222
mocks.templateRepository.setLetterValidationResult
12231223
).toHaveBeenCalledWith(
1224-
{ id: templateId, owner: userId, clientOwned: false },
1224+
{ templateId, clientId: userId, clientOwned: false },
12251225
versionId,
12261226
false,
12271227
[],
@@ -1285,7 +1285,7 @@ describe('guard duty handler', () => {
12851285
expect(
12861286
mocks.templateRepository.setLetterValidationResult
12871287
).toHaveBeenCalledWith(
1288-
{ id: templateId, owner: userId, clientOwned: false },
1288+
{ templateId, clientId: userId, clientOwned: false },
12891289
versionId,
12901290
false,
12911291
pdf.personalisationParameters,

lambdas/backend-api/src/__tests__/templates/domain/template-pdf.test.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,28 @@ import { TemplatePdf } from '@backend-api/templates/domain/template-pdf';
66

77
test('has the given key attributes', () => {
88
const pdf = new TemplatePdf(
9-
{ id: 'template-id', owner: 'template-owner', clientOwned: true },
9+
{
10+
templateId: 'template-id',
11+
clientId: 'template-owner',
12+
clientOwned: true,
13+
},
1014
Buffer.from('')
1115
);
1216

1317
expect(pdf.templateId).toBe('template-id');
14-
expect(pdf.owner).toBe('template-owner');
18+
expect(pdf.clientId).toBe('template-owner');
1519
});
1620

1721
test('parse with no custom personalisation', async () => {
1822
const file = fs.readFileSync(
1923
path.resolve(__dirname, '../fixtures/no-custom-personalisation.pdf')
2024
);
2125
const pdf = new TemplatePdf(
22-
{ id: 'template-id', owner: 'template-owner', clientOwned: true },
26+
{
27+
templateId: 'template-id',
28+
clientId: 'template-owner',
29+
clientOwned: true,
30+
},
2331
file
2432
);
2533
await pdf.parse();
@@ -66,7 +74,11 @@ test('parse with custom personalisation', async () => {
6674
path.resolve(__dirname, '../fixtures/custom-personalisation.pdf')
6775
);
6876
const pdf = new TemplatePdf(
69-
{ id: 'template-id', owner: 'template-owner', clientOwned: true },
77+
{
78+
templateId: 'template-id',
79+
clientId: 'template-owner',
80+
clientOwned: true,
81+
},
7082
file
7183
);
7284
await pdf.parse();
@@ -124,7 +136,11 @@ test('errors if parse is not called before reading personalisation', () => {
124136
path.resolve(__dirname, '../fixtures/no-custom-personalisation.pdf')
125137
);
126138
const pdf = new TemplatePdf(
127-
{ id: 'template-id', owner: 'template-owner', clientOwned: true },
139+
{
140+
templateId: 'template-id',
141+
clientId: 'template-owner',
142+
clientOwned: true,
143+
},
128144
file
129145
);
130146

@@ -148,7 +164,11 @@ test('errors if file cannot be parsed', async () => {
148164
);
149165

150166
const pdf = new TemplatePdf(
151-
{ id: 'template-id', owner: 'template-owner', clientOwned: true },
167+
{
168+
templateId: 'template-id',
169+
clientId: 'template-owner',
170+
clientOwned: true,
171+
},
152172
file
153173
);
154174

@@ -161,7 +181,11 @@ test('errors if file cannot be opened', async () => {
161181
);
162182

163183
const pdf = new TemplatePdf(
164-
{ id: 'template-id', owner: 'template-owner', clientOwned: true },
184+
{
185+
templateId: 'template-id',
186+
clientId: 'template-owner',
187+
clientOwned: true,
188+
},
165189
file
166190
);
167191

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('LetterUploadRepository', () => {
6262
Key: `pdf-template/${clientId}/${templateId}/${versionId}.pdf`,
6363
Body: new Uint8Array(await pdfBytes.arrayBuffer()),
6464
Metadata: {
65-
owner: clientId,
65+
'client-id': clientId,
6666
'file-type': 'pdf-template',
6767
'template-id': templateId,
6868
'version-id': versionId,
@@ -74,7 +74,7 @@ describe('LetterUploadRepository', () => {
7474
Key: `test-data/${clientId}/${templateId}/${versionId}.csv`,
7575
Body: new Uint8Array(await csvBytes.arrayBuffer()),
7676
Metadata: {
77-
owner: clientId,
77+
'client-id': clientId,
7878
'file-type': 'test-data',
7979
'template-id': templateId,
8080
'version-id': versionId,
@@ -98,7 +98,7 @@ describe('LetterUploadRepository', () => {
9898
Key: `pdf-template/${clientId}/${templateId}/${versionId}.pdf`,
9999
Body: new Uint8Array(await pdfBytes.arrayBuffer()),
100100
Metadata: {
101-
owner: clientId,
101+
'client-id': clientId,
102102
'file-type': 'pdf-template',
103103
'template-id': templateId,
104104
'version-id': versionId,
@@ -200,7 +200,7 @@ describe('LetterUploadRepository', () => {
200200
)
201201
).toEqual({
202202
'file-type': 'pdf-template',
203-
owner: 'owner-id',
203+
'client-id': 'owner-id',
204204
'template-id': 'template-id',
205205
'version-id': 'version-id',
206206
});
@@ -213,7 +213,7 @@ describe('LetterUploadRepository', () => {
213213
)
214214
).toEqual({
215215
'file-type': 'test-data',
216-
owner: 'owner-id',
216+
'client-id': 'owner-id',
217217
'template-id': 'template-id',
218218
'version-id': 'version-id',
219219
});

0 commit comments

Comments
 (0)