mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
change: Support all PUT operations, error later
This commit is contained in:
parent
4965b476c9
commit
385e1a4cdf
@ -20,13 +20,13 @@ export class PutOperationHandler extends OperationHandler {
|
|||||||
if (input.method !== 'PUT') {
|
if (input.method !== 'PUT') {
|
||||||
throw new UnsupportedHttpError('This handler only supports PUT operations.');
|
throw new UnsupportedHttpError('This handler only supports PUT operations.');
|
||||||
}
|
}
|
||||||
if (typeof input.body !== 'object') {
|
|
||||||
throw new UnsupportedHttpError('PUT operations require a body.');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async handle(input: Operation): Promise<ResponseDescription> {
|
public async handle(input: Operation): Promise<ResponseDescription> {
|
||||||
await this.store.setRepresentation(input.target, input.body!);
|
if (typeof input.body !== 'object') {
|
||||||
|
throw new UnsupportedHttpError('PUT operations require a body.');
|
||||||
|
}
|
||||||
|
await this.store.setRepresentation(input.target, input.body);
|
||||||
return { identifier: input.target };
|
return { identifier: input.target };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,9 @@ describe('A PutOperationHandler', (): void => {
|
|||||||
store.setRepresentation = jest.fn(async(): Promise<void> => {});
|
store.setRepresentation = jest.fn(async(): Promise<void> => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('only supports PUT operations with a body.', async(): Promise<void> => {
|
it('only supports PUT operations.', async(): Promise<void> => {
|
||||||
await expect(handler.canHandle({ method: 'PUT' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
|
||||||
await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||||
await expect(handler.canHandle({ method: 'PUT', body: { dataType: 'test' }} as Operation)).resolves.toBeUndefined();
|
await expect(handler.canHandle({ method: 'PUT' } as Operation)).resolves.toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets the representation in the store and returns its identifier.', async(): Promise<void> => {
|
it('sets the representation in the store and returns its identifier.', async(): Promise<void> => {
|
||||||
@ -23,4 +22,8 @@ describe('A PutOperationHandler', (): void => {
|
|||||||
expect(store.setRepresentation).toHaveBeenCalledTimes(1);
|
expect(store.setRepresentation).toHaveBeenCalledTimes(1);
|
||||||
expect(store.setRepresentation).toHaveBeenLastCalledWith({ path: 'url' }, { dataType: 'test' });
|
expect(store.setRepresentation).toHaveBeenLastCalledWith({ path: 'url' }, { dataType: 'test' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('errors when there is no body.', async(): Promise<void> => {
|
||||||
|
await expect(handler.handle({ method: 'PUT' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user