Skip to content

Commit

Permalink
chore: handle case when no attachments are found in zip middleware an…
Browse files Browse the repository at this point in the history
…d display appropriate message (#668)
  • Loading branch information
janosbabik authored Jul 25, 2024
1 parent efe760a commit 730c8a2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions apps/backend/src/middlewares/factory/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ router.get(`/${ZIPType.ATTACHMENT}/:proposal_pks`, async (req, res, next) => {
if (!data) {
throw new Error('Could not get attachments');
}

const attachments = data.flatMap(({ attachments }) => attachments);
if (attachments.length === 0) {
return res.status(404).send('NO_ATTACHMENTS');
}

downloadService.callFactoryService<ProposalAttachmentData, MetaBase>(
DownloadType.ZIP,
ZIPType.ATTACHMENT,
Expand Down
6 changes: 6 additions & 0 deletions apps/e2e/cypress/e2e/proposalAdministration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ context('Proposal administration tests', () => {
'attachment'
);

cy.get('[role="alert"]').should('exist');
cy.get('[role="alert"]').contains('No attachments found');

cy.contains(proposalFixedName)
.parent()
.find('input[type="checkbox"]')
Expand All @@ -463,6 +466,9 @@ context('Proposal administration tests', () => {
cy.get('[data-cy="preparing-download-dialog-item"]').contains(
'2 selected items'
);

cy.get('[role="alert"]').should('exist');
cy.get('[role="alert"]').contains('No attachments found');
});

it('Downloaded proposal filename format is RB_SURNAME_YYYY', function () {
Expand Down
7 changes: 6 additions & 1 deletion apps/frontend/src/context/DownloadContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ export const DownloadContextProvider = ({
await promptDownload(response);
})
.catch((error) => {
if (error !== 'EXTERNAL_TOKEN_INVALID' && error.name !== 'AbortError') {
if (error === 'NO_ATTACHMENTS') {
enqueueSnackbar('No attachments found', { variant: 'info' });
} else if (
error !== 'EXTERNAL_TOKEN_INVALID' &&
error.name !== 'AbortError'
) {
enqueueSnackbar('Failed to download file', { variant: 'error' });
}
})
Expand Down

0 comments on commit 730c8a2

Please sign in to comment.