Skip to content

Commit 8574ecd

Browse files
committed
CCM-10387: fix unit tests
1 parent 68417e6 commit 8574ecd

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jest.mocked(logger).child.mockReturnThis();
2828
const versionId = 'template-version-id';
2929
const templateId = 'template-id';
3030
const userId = 'template-owner';
31+
const clientId = 'client-id';
3132

3233
function setup() {
3334
const mocks = {
@@ -148,8 +149,6 @@ describe('guard duty handler', () => {
148149
test('validates a client-owned template', async () => {
149150
const { handler, mocks } = setup();
150151

151-
const clientId = 'clientid';
152-
153152
const event = makeGuardDutyMalwareScanResultNotificationEvent({
154153
detail: {
155154
s3ObjectDetails: {
@@ -221,7 +220,7 @@ describe('guard duty handler', () => {
221220
expect(
222221
mocks.templateRepository.setLetterValidationResult
223222
).toHaveBeenCalledWith(
224-
{ id: templateId, owner: `CLIENT#${clientId}`, clientOwned: true },
223+
{ id: templateId, owner: clientId, clientOwned: true },
225224
versionId,
226225
true,
227226
pdf.personalisationParameters,
@@ -1018,7 +1017,7 @@ describe('guard duty handler', () => {
10181017
detail: {
10191018
s3ObjectDetails: {
10201019
bucketName: 'quarantine-bucket',
1021-
objectKey: `pdf-template/${userId}/${templateId}/${versionId}.pdf`,
1020+
objectKey: `pdf-template/${clientId}/${templateId}/${versionId}.pdf`,
10221021
},
10231022
scanResultDetails: {
10241023
scanResultStatus: 'NO_THREATS_FOUND',
@@ -1066,7 +1065,7 @@ describe('guard duty handler', () => {
10661065
detail: {
10671066
s3ObjectDetails: {
10681067
bucketName: 'quarantine-bucket',
1069-
objectKey: `pdf-template/${userId}/${templateId}/${versionId}.pdf`,
1068+
objectKey: `pdf-template/${clientId}/${templateId}/${versionId}.pdf`,
10701069
},
10711070
scanResultDetails: {
10721071
scanResultStatus: 'NO_THREATS_FOUND',

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class ValidateLetterTemplateFilesLambda {
4545
return { batchItemFailures };
4646
};
4747

48+
// eslint-disable-next-line sonarjs/cognitive-complexity
4849
guardDutyHandler = async (event: unknown) => {
4950
const { detail } = guardDutyEventValidator('PASSED').parse(event);
5051

@@ -127,13 +128,6 @@ export class ValidateLetterTemplateFilesLambda {
127128
}
128129

129130
const clientOwned = template.owner.startsWith('CLIENT#');
130-
const ownerFromDb = clientOwned ? template.owner.slice(7) : template.owner;
131-
132-
if (owner !== ownerFromDb) {
133-
throw new Error(
134-
'Unexpected mismatch between s3 path and database owner field'
135-
);
136-
}
137131

138132
const downloads = [
139133
this.letterUploadRepository.download(

0 commit comments

Comments
 (0)