From d0814d67f1dfe21f50dc1ff0db169477ef098a2b Mon Sep 17 00:00:00 2001 From: Kasra Bigdeli Date: Mon, 21 Sep 2026 21:51:19 -0700 Subject: [PATCH] test: cover one-time backup download failures --- tests/DownloadRouter.test.ts | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/DownloadRouter.test.ts diff --git a/tests/DownloadRouter.test.ts b/tests/DownloadRouter.test.ts new file mode 100644 index 00000000..a7435050 --- /dev/null +++ b/tests/DownloadRouter.test.ts @@ -0,0 +1,46 @@ +import { handleDownloadCompletion } from '../src/routes/download/DownloadRouter' + +describe('backup download completion', () => { + test('returns 404 when the one-time backup file is already gone', () => { + const sendStatus = jest.fn() + const next = jest.fn() + const response = { + headersSent: false, + sendStatus, + } + + const error = Object.assign(new Error('missing backup'), { + code: 'ENOENT', + }) + + handleDownloadCompletion( + error, + '/tmp/missing-caprover-backup.tar', + response as any, + next + ) + + expect(sendStatus).toHaveBeenCalledWith(404) + expect(next).not.toHaveBeenCalled() + }) + + test('delegates other transfer errors', () => { + const sendStatus = jest.fn() + const next = jest.fn() + const response = { + headersSent: false, + sendStatus, + } + const error = new Error('transfer failed') + + handleDownloadCompletion( + error, + '/tmp/missing-caprover-backup.tar', + response as any, + next + ) + + expect(sendStatus).not.toHaveBeenCalled() + expect(next).toHaveBeenCalledWith(error) + }) +})