From 635796ad69b367d59a6aab1a9a1ec29eaeb0faab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Thu, 18 May 2023 22:12:34 +0100 Subject: [PATCH] test: added test for DecryptionQueue (#8) --- src/util/__tests__/DecryptionQueue.test.ts | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/util/__tests__/DecryptionQueue.test.ts diff --git a/src/util/__tests__/DecryptionQueue.test.ts b/src/util/__tests__/DecryptionQueue.test.ts new file mode 100644 index 0000000..a1c89a2 --- /dev/null +++ b/src/util/__tests__/DecryptionQueue.test.ts @@ -0,0 +1,29 @@ +import { DECRYPTION_WORKER_ACTION_NAME } from '~/decrypt-worker/constants'; +import { WorkerClientBus } from '../WorkerEventBus'; +import { DecryptionQueue } from '../DecryptionQueue'; + +vi.mock('../WorkerEventBus', () => { + class MyWorkerClientBus { + request() { + throw new Error('request not mocked'); + } + } + + return { WorkerClientBus: MyWorkerClientBus }; +}); + +test('should be able to forward request to worker client bus', async () => { + // This class is mocked + const bus = new WorkerClientBus(null as never); + vi.spyOn(bus, 'request').mockImplementation( + async (actionName: DECRYPTION_WORKER_ACTION_NAME, payload: unknown): Promise => { + return { actionName, payload }; + } + ); + + const queue = new DecryptionQueue(bus, 1); + await expect(queue.add({ id: 'file://1', blobURI: 'blob://mock-file' })).resolves.toEqual({ + actionName: DECRYPTION_WORKER_ACTION_NAME.DECRYPT, + payload: 'blob://mock-file', + }); +});