Skip to content

Commit

Permalink
fix(downloader): rm not necessary
Browse files Browse the repository at this point in the history
Signed-off-by: axel7083 <[email protected]>
  • Loading branch information
axel7083 committed Mar 7, 2024
1 parent 31b8320 commit ab97e8a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
8 changes: 1 addition & 7 deletions packages/backend/src/utils/downloader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ vi.mock('node:fs', () => {
existsSync: vi.fn(),
promises: {
rename: vi.fn(),
rm: vi.fn(),
},
};
});
Expand Down Expand Up @@ -97,7 +96,6 @@ test('perform download failed', async () => {
test('perform download successfully', async () => {
const downloader = new Downloader('dummyUrl', 'dummyTarget');
vi.spyOn(promises, 'rename').mockResolvedValue(undefined);
vi.spyOn(promises, 'rm').mockResolvedValue(undefined);

const closeMock = vi.fn();
const onMock = vi.fn();
Expand All @@ -119,16 +117,12 @@ test('perform download successfully', async () => {
// perform download logic
await downloader.perform('followUpId');

expect(promises.rename).toHaveBeenCalledWith('dummyTarget.tmp', 'dummyTarget');
expect(downloader.completed).toBeTruthy();
expect(listenerMock).toHaveBeenCalledWith({
id: 'followUpId',
duration: expect.anything(),
message: expect.anything(),
status: 'completed',
});

await vi.waitFor(() => {
expect(promises.rename).toHaveBeenCalledWith('dummyTarget.tmp', 'dummyTarget');
expect(promises.rm).toHaveBeenCalledWith('dummyTarget.tmp');
});
});
6 changes: 0 additions & 6 deletions packages/backend/src/utils/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ export class Downloader {
.catch((err: unknown) => {
callback({ error: `Something went wrong while trying to rename downloaded file: ${String(err)}.` });
})

Check failure on line 133 in packages/backend/src/utils/downloader.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / windows-2022

Missing semicolon

Check failure on line 133 in packages/backend/src/utils/downloader.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / ubuntu-22.04

Missing semicolon

Check failure on line 133 in packages/backend/src/utils/downloader.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / macos-12

Missing semicolon
.finally(() => {
// Finally delete the tmp file
promises.rm(tmpFile).catch((err: unknown) => {
console.error('Something went wrong while trying to delete the temporary file', err);
});
});
});
stream.on('error', e => {
callback({
Expand Down

0 comments on commit ab97e8a

Please sign in to comment.