mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: add simple request parser
This commit is contained in:
40
test/unit/ldp/http/SimpleRequestParser.test.ts
Normal file
40
test/unit/ldp/http/SimpleRequestParser.test.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user