mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00

These were added when setting TypeScript settings to strict, but should not be needed due to how AsyncHandlers should be used.
41 lines
1.7 KiB
TypeScript
41 lines
1.7 KiB
TypeScript
import { BodyParser } from '../../../../src/ldp/http/BodyParser';
|
|
import { PreferenceParser } from '../../../../src/ldp/http/PreferenceParser';
|
|
import { SimpleRequestParser } from '../../../../src/ldp/http/SimpleRequestParser';
|
|
import { StaticAsyncHandler } from '../../../util/StaticAsyncHandler';
|
|
import { TargetExtractor } from '../../../../src/ldp/http/TargetExtractor';
|
|
|
|
describe('A SimpleRequestParser', (): void => {
|
|
let targetExtractor: TargetExtractor;
|
|
let bodyParser: BodyParser;
|
|
let preferenceParser: PreferenceParser;
|
|
let requestParser: SimpleRequestParser;
|
|
|
|
beforeEach(async(): Promise<void> => {
|
|
targetExtractor = new StaticAsyncHandler(true, 'target' as any);
|
|
bodyParser = new StaticAsyncHandler(true, 'body' as any);
|
|
preferenceParser = new StaticAsyncHandler(true, 'preference' as any);
|
|
requestParser = new SimpleRequestParser({ 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('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('returns the output of all input parsers after calling handle.', async(): Promise<void> => {
|
|
await expect(requestParser.handle({ url: 'url', method: 'GET' } as any)).resolves.toEqual({
|
|
method: 'GET',
|
|
target: 'target',
|
|
preferences: 'preference',
|
|
body: 'body',
|
|
});
|
|
});
|
|
});
|