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 => { // eslint-disable-next-line @typescript-eslint/no-empty-function store.deleteResource = jest.fn(async(): Promise => {}); }); 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 its identifier.', async(): Promise => { 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' }); }); });