Skip to content

Commit

Permalink
Try again to fix backend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasalisbury committed Mar 11, 2021
1 parent 9369bd5 commit 786fde9
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/routes/files/handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ describe('File Upload', () => {
});

describe('File Upload Handlers happy path', () => {
beforeEach(async () => {
beforeEach(() => {
uploadFile.mockReset();
getPresignedURL.mockReset();
});
it('tests a file upload', async () => {
ActivityReportPolicy.mockImplementation(() => ({
canUpdate: () => true,
}));
Expand All @@ -94,16 +96,9 @@ describe('File Upload', () => {
.expect(200)
.then((res) => {
fileId = res.body.id;
expect(uploadFile).toHaveBeenCalled();
});
});
it('tests a file upload', async () => {
expect(uploadFile).toHaveBeenCalled();
expect(mockAddToScanQueue).toHaveBeenCalled();
});
it('checks the metadata was uploaded to the database', async () => {
ActivityReportPolicy.mockImplementation(() => ({
canUpdate: () => true,
}));
const file = await File.findOne({ where: { id: fileId } });
const uuid = file.dataValues.key.slice(0, -4);
expect(file.dataValues.id).toBe(fileId);
Expand All @@ -117,20 +112,26 @@ describe('File Upload', () => {
canUpdate: () => false,
}));
await request(app)
.delete(`/api/files/${report.dataValues.id}/${fileId}`)
.delete(`/api/files/${report.dataValues.id}/1`)
.expect(403)
.then(() => expect(deleteFileFromS3).not.toHaveBeenCalled());
});
it('deletes a file', async () => {
ActivityReportPolicy.mockImplementation(() => ({
canUpdate: () => true,
}));
const file = await File.findOne({ where: { id: fileId } });
const file = await File.create({
activityReportId: report.dataValues.id,
originalFileName: 'name',
key: 'key',
status: 'UPLOADING',
fileSize: 0,
});
await request(app)
.delete(`/api/files/${report.dataValues.id}/${fileId}`)
.delete(`/api/files/${report.dataValues.id}/${file.id}`)
.expect(204);
expect(deleteFileFromS3).toHaveBeenCalledWith(file.dataValues.key);
const noFile = await File.findOne({ where: { id: fileId } });
const noFile = await File.findOne({ where: { id: file.id } });
expect(noFile).toBe(null);
});
});
Expand Down

0 comments on commit 786fde9

Please sign in to comment.