Skip to content

Commit

Permalink
Merge pull request #2784 from bcgov/NDT-96-Prepare-downloads-with-1-c…
Browse files Browse the repository at this point in the history
…rashes-application-pod

fix: prepare download crashed when passed -1 as intake id
  • Loading branch information
RRanath authored Dec 29, 2023
2 parents 1259efd + 9953c35 commit 8ccaebc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
13 changes: 8 additions & 5 deletions app/backend/lib/s3admin-archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,26 @@ s3adminArchive.get('/api/analyst/admin-archive/:intake', async (req, res) => {
};
}
let { intake } = req.params;
if (intake === '-1') {
intake = await getLastIntakeId(req);
} else {
intake = await getIntakeId(req);
}
if (intake === '-1') {
throw new Error('Wrong intake id');
}
const s3Key = `Intake_${intake}_attachments`;
const s3params = {
Bucket: AWS_S3_BUCKET,
Key: `${s3Key}.zip`,
};
if (intake === '-1') intake = await getLastIntakeId(req);
if (intake === '-1') {
throw new Error('Wrong intake id');
}
const alreadyExists = await checkFileExists(s3params);
if (alreadyExists) {
await getFileFromS3(s3params.Key, s3params.Key, res);
return res.status(200).end();
}
// turn ccbc intake number into intake id
// as some intakes had id which did not match their intake number
intake = await getIntakeId(req);

const attachments = await getAttachmentList(
parseInt(intake as string, 10),
Expand Down
12 changes: 5 additions & 7 deletions app/tests/backend/lib/requestArchive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ jest.mock('../../../backend/lib/s3client', () => {
};
});

jest.mock('../../../backend/lib/intakeId', () => {
return {
__esModule: true,
default: jest.fn().mockReturnValue('1'),
};
});

describe('The attachments archive', () => {
let app;

Expand Down Expand Up @@ -74,6 +67,11 @@ describe('The attachments archive', () => {
};
});

jest
// eslint-disable-next-line global-require
.spyOn(require('../../../backend/lib/intakeId'), 'default')
.mockImplementation(async () => '1');

mocked(performQuery).mockImplementation(async () => {
return {
data: {
Expand Down

0 comments on commit 8ccaebc

Please sign in to comment.