mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: add simple operation handlers
This commit is contained in:
22
test/unit/ldp/operations/SimplePostOperationHandler.test.ts
Normal file
22
test/unit/ldp/operations/SimplePostOperationHandler.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { SimplePostOperationHandler } from '../../../../src/ldp/operations/SimplePostOperationHandler';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A SimplePostOperationHandler', (): void => {
|
||||
const store = {
|
||||
addResource: async(): Promise<ResourceIdentifier> => ({ path: 'newPath' } as ResourceIdentifier),
|
||||
} as unknown as ResourceStore;
|
||||
const handler = new SimplePostOperationHandler(store);
|
||||
|
||||
it('only supports POST operations with a body.', async(): Promise<void> => {
|
||||
await expect(handler.canHandle({ method: 'POST', body: { dataType: 'test' }} as Operation)).resolves.toBeUndefined();
|
||||
await expect(handler.canHandle({ method: 'GET', body: { dataType: 'test' }} as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(handler.canHandle({ method: 'POST' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
});
|
||||
|
||||
it('adds the given representation to the store and returns the new identifier.', async(): Promise<void> => {
|
||||
await expect(handler.handle({ method: 'POST', body: { dataType: 'test' }} as Operation)).resolves.toEqual({ identifier: { path: 'newPath' }});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user