import { DeleteOperationHandler } from '../../../../src/ldp/operations/DeleteOperationHandler'; import type { Operation } from '../../../../src/ldp/operations/Operation'; import type { ResourceStore } from '../../../../src/storage/ResourceStore'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A DeleteOperationHandler', (): void => { const store = {} as unknown as ResourceStore; const handler = new DeleteOperationHandler(store); beforeEach(async(): Promise => { store.deleteResource = jest.fn(async(): Promise => undefined); }); it('only supports DELETE operations.', async(): Promise => { 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 the correct response.', async(): Promise => { const result = await handler.handle({ target: { path: 'url' }} as Operation); expect(store.deleteResource).toHaveBeenCalledTimes(1); expect(store.deleteResource).toHaveBeenLastCalledWith({ path: 'url' }); expect(result.statusCode).toBe(205); expect(result.metadata).toBeUndefined(); expect(result.data).toBeUndefined(); }); });