mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Verify conditions in DataAccessorBasedStore
This commit is contained in:
@@ -2,6 +2,7 @@ import type { Patch } from '../../../src/ldp/http/Patch';
|
||||
import type { PatchHandler } from '../../../src/storage/patch/PatchHandler';
|
||||
import { PatchingStore } from '../../../src/storage/PatchingStore';
|
||||
import type { ResourceStore } from '../../../src/storage/ResourceStore';
|
||||
import { NotImplementedHttpError } from '../../../src/util/errors/NotImplementedHttpError';
|
||||
|
||||
describe('A PatchingStore', (): void => {
|
||||
let store: PatchingStore;
|
||||
@@ -26,15 +27,25 @@ describe('A PatchingStore', (): void => {
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith({ path: 'modifyPath' }, {}, undefined);
|
||||
});
|
||||
|
||||
it('calls its patcher if modifyResource failed.', async(): Promise<void> => {
|
||||
it('calls its patcher if modifyResource is not implemented.', async(): Promise<void> => {
|
||||
source.modifyResource = jest.fn(async(): Promise<any> => {
|
||||
throw new Error('dummy');
|
||||
throw new NotImplementedHttpError();
|
||||
});
|
||||
await expect(store.modifyResource({ path: 'modifyPath' }, {} as Patch)).resolves.toBe('patcher');
|
||||
expect(source.modifyResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith({ path: 'modifyPath' }, {}, undefined);
|
||||
await expect((source.modifyResource as jest.Mock).mock.results[0].value).rejects.toThrow('dummy');
|
||||
await expect((source.modifyResource as jest.Mock).mock.results[0].value).rejects.toThrow(NotImplementedHttpError);
|
||||
expect(handleSafeFn).toHaveBeenCalledTimes(1);
|
||||
expect(handleSafeFn).toHaveBeenLastCalledWith({ source, identifier: { path: 'modifyPath' }, patch: {}});
|
||||
});
|
||||
|
||||
it('rethrows source modifyResource errors.', async(): Promise<void> => {
|
||||
source.modifyResource = jest.fn(async(): Promise<any> => {
|
||||
throw new Error('dummy');
|
||||
});
|
||||
await expect(store.modifyResource({ path: 'modifyPath' }, {} as Patch)).rejects.toThrow('dummy');
|
||||
expect(source.modifyResource).toHaveBeenCalledTimes(1);
|
||||
expect(source.modifyResource).toHaveBeenLastCalledWith({ path: 'modifyPath' }, {}, undefined);
|
||||
expect(handleSafeFn).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user