Files
um-react/src/util/__tests__/DecryptionQueue.test.ts
2023-11-29 23:45:56 +00:00

36 lines
1.1 KiB
TypeScript

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<DECRYPTION_WORKER_ACTION_NAME>(null as never);
vi.spyOn(bus, 'request').mockImplementation(
async (actionName: DECRYPTION_WORKER_ACTION_NAME, payload: unknown): Promise<unknown> => {
return { actionName, payload };
},
);
const queue = new DecryptionQueue(bus, 1);
await expect(
queue.add({ id: 'file://1', blobURI: 'blob://mock-file', options: { fileName: 'test.bin' } }),
).resolves.toEqual({
actionName: DECRYPTION_WORKER_ACTION_NAME.DECRYPT,
payload: {
blobURI: 'blob://mock-file',
id: 'file://1',
options: { fileName: 'test.bin' },
},
});
});