feat: add simple operation handlers

This commit is contained in:
Joachim Van Herwegen
2020-06-23 10:18:46 +02:00
parent 12fd00e3b8
commit fe8749390c
6 changed files with 147 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { Operation } from '../../../../src/ldp/operations/Operation';
import { ResourceStore } from '../../../../src/storage/ResourceStore';
import { SimpleDeleteOperationHandler } from '../../../../src/ldp/operations/SimpleDeleteOperationHandler';
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
describe('A SimpleDeleteOperationHandler', (): void => {
const store = {} as unknown as ResourceStore;
const handler = new SimpleDeleteOperationHandler(store);
beforeEach(async(): Promise<void> => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
store.deleteResource = jest.fn(async(): Promise<void> => {});
});
it('only supports GET operations.', async(): Promise<void> => {
await expect(handler.canHandle({ method: 'DELETE' } as Operation)).resolves.toBeUndefined();
await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(UnsupportedHttpError);
});
it('deletes the resource from the store and returns its identifier.', async(): Promise<void> => {
await expect(handler.handle({ target: { path: 'url' }} as Operation)).resolves.toEqual({ identifier: { path: 'url' }});
expect(store.deleteResource).toHaveBeenCalledTimes(1);
expect(store.deleteResource).toHaveBeenLastCalledWith({ path: 'url' });
});
});