mirror of
https://git.unlock-music.dev/um/um-react.git
synced 2024-11-23 18:52:16 +00:00
test: added test for DecryptionQueue (#8)
This commit is contained in:
parent
2186a08fa5
commit
635796ad69
29
src/util/__tests__/DecryptionQueue.test.ts
Normal file
29
src/util/__tests__/DecryptionQueue.test.ts
Normal file
@ -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<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' })).resolves.toEqual({
|
||||
actionName: DECRYPTION_WORKER_ACTION_NAME.DECRYPT,
|
||||
payload: 'blob://mock-file',
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user