mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Create an ArrayUnionHandler which flattens the sources results
This commit is contained in:
30
test/unit/util/handlers/ArrayUnionHandler.test.ts
Normal file
30
test/unit/util/handlers/ArrayUnionHandler.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { ArrayUnionHandler } from '../../../../src/util/handlers/ArrayUnionHandler';
|
||||
import type { AsyncHandler } from '../../../../src/util/handlers/AsyncHandler';
|
||||
|
||||
describe('An ArrayUnionHandler', (): void => {
|
||||
let handlers: jest.Mocked<AsyncHandler<string, number[]>>[];
|
||||
let handler: ArrayUnionHandler<AsyncHandler<string, number[]>>;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
handlers = [
|
||||
{
|
||||
canHandle: jest.fn(),
|
||||
handle: jest.fn().mockResolvedValue([ 1, 2 ]),
|
||||
} as any,
|
||||
{
|
||||
canHandle: jest.fn(),
|
||||
handle: jest.fn().mockResolvedValue([ 3, 4 ]),
|
||||
} as any,
|
||||
];
|
||||
|
||||
handler = new ArrayUnionHandler(handlers);
|
||||
});
|
||||
|
||||
it('merges the array results.', async(): Promise<void> => {
|
||||
await expect(handler.handle('input')).resolves.toEqual([ 1, 2, 3, 4 ]);
|
||||
expect(handlers[0].handle).toHaveBeenCalledTimes(1);
|
||||
expect(handlers[0].handle).toHaveBeenLastCalledWith('input');
|
||||
expect(handlers[1].handle).toHaveBeenCalledTimes(1);
|
||||
expect(handlers[1].handle).toHaveBeenLastCalledWith('input');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user