fix: Have AsyncHandlers only check what is necessary

This commit is contained in:
Joachim Van Herwegen
2020-10-05 10:56:35 +02:00
parent 10723bb6b8
commit 4d34cdd12f
11 changed files with 45 additions and 55 deletions

View File

@@ -17,16 +17,12 @@ describe('A BasicRequestParser', (): void => {
requestParser = new BasicRequestParser({ targetExtractor, bodyParser, preferenceParser });
});
it('can handle input with both a URL and a method.', async(): Promise<void> => {
await expect(requestParser.canHandle({ url: 'url', method: 'GET' } as any)).resolves.toBeUndefined();
it('can handle any input.', async(): Promise<void> => {
await expect(requestParser.canHandle()).resolves.toBeUndefined();
});
it('rejects input with no URL.', async(): Promise<void> => {
await expect(requestParser.canHandle({ method: 'GET' } as any)).rejects.toThrow('Missing URL.');
});
it('rejects input with no method.', async(): Promise<void> => {
await expect(requestParser.canHandle({ url: 'url' } as any)).rejects.toThrow('Missing method.');
it('errors if there is no input.', async(): Promise<void> => {
await expect(requestParser.handle({ url: 'url' } as any)).rejects.toThrow('Missing method.');
});
it('returns the output of all input parsers after calling handle.', async(): Promise<void> => {

View File

@@ -3,16 +3,16 @@ import { BasicTargetExtractor } from '../../../../src/ldp/http/BasicTargetExtrac
describe('A BasicTargetExtractor', (): void => {
const extractor = new BasicTargetExtractor();
it('can handle input with an URL and host.', async(): Promise<void> => {
await expect(extractor.canHandle({ url: 'url', headers: { host: 'test.com' }} as any)).resolves.toBeUndefined();
it('can handle any input.', async(): Promise<void> => {
await expect(extractor.canHandle()).resolves.toBeUndefined();
});
it('rejects input without URL.', async(): Promise<void> => {
await expect(extractor.canHandle({ headers: { host: 'test.com' }} as any)).rejects.toThrow('Missing URL.');
it('errors if there is no URL.', async(): Promise<void> => {
await expect(extractor.handle({ headers: { host: 'test.com' }} as any)).rejects.toThrow('Missing URL.');
});
it('rejects input without host.', async(): Promise<void> => {
await expect(extractor.canHandle({ url: 'url', headers: {}} as any)).rejects.toThrow('Missing host.');
it('errors if there is no host.', async(): Promise<void> => {
await expect(extractor.handle({ url: 'url', headers: {}} as any)).rejects.toThrow('Missing host.');
});
it('returns the input URL.', async(): Promise<void> => {

View File

@@ -10,12 +10,15 @@ describe('A PostOperationHandler', (): void => {
} as unknown as ResourceStore;
const handler = new PostOperationHandler(store);
it('only supports POST operations with a body.', async(): Promise<void> => {
it('only supports POST operations.', async(): Promise<void> => {
await expect(handler.canHandle({ method: 'POST', body: { }} as Operation))
.resolves.toBeUndefined();
await expect(handler.canHandle({ method: 'GET', body: { }} as Operation))
.rejects.toThrow(UnsupportedHttpError);
await expect(handler.canHandle({ method: 'POST' } as Operation)).rejects.toThrow(UnsupportedHttpError);
});
it('errors if there is no body.', async(): Promise<void> => {
await expect(handler.handle({ method: 'POST' } as Operation)).rejects.toThrow(UnsupportedHttpError);
});
it('adds the given representation to the store and returns the new identifier.', async(): Promise<void> => {