mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Restructure source code folder
This way the location of certain classes should make more sense
This commit is contained in:
48
test/unit/http/input/BasicRequestParser.test.ts
Normal file
48
test/unit/http/input/BasicRequestParser.test.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { BasicRequestParser } from '../../../../src/http/input/BasicRequestParser';
|
||||
import type { BodyParser } from '../../../../src/http/input/body/BodyParser';
|
||||
import type { ConditionsParser } from '../../../../src/http/input/conditions/ConditionsParser';
|
||||
import type { TargetExtractor } from '../../../../src/http/input/identifier/TargetExtractor';
|
||||
import type { MetadataParser } from '../../../../src/http/input/metadata/MetadataParser';
|
||||
import type { PreferenceParser } from '../../../../src/http/input/preferences/PreferenceParser';
|
||||
import { RepresentationMetadata } from '../../../../src/http/representation/RepresentationMetadata';
|
||||
import { StaticAsyncHandler } from '../../../util/StaticAsyncHandler';
|
||||
|
||||
describe('A BasicRequestParser', (): void => {
|
||||
let targetExtractor: TargetExtractor;
|
||||
let preferenceParser: PreferenceParser;
|
||||
let metadataParser: MetadataParser;
|
||||
let conditionsParser: ConditionsParser;
|
||||
let bodyParser: BodyParser;
|
||||
let requestParser: BasicRequestParser;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
targetExtractor = new StaticAsyncHandler(true, 'target' as any);
|
||||
preferenceParser = new StaticAsyncHandler(true, 'preference' as any);
|
||||
metadataParser = new StaticAsyncHandler(true, undefined);
|
||||
conditionsParser = new StaticAsyncHandler(true, 'conditions' as any);
|
||||
bodyParser = new StaticAsyncHandler(true, 'body' as any);
|
||||
requestParser = new BasicRequestParser(
|
||||
{ targetExtractor, preferenceParser, metadataParser, conditionsParser, bodyParser },
|
||||
);
|
||||
});
|
||||
|
||||
it('can handle any input.', async(): Promise<void> => {
|
||||
await expect(requestParser.canHandle({} as any)).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('errors if there is no input.', async(): Promise<void> => {
|
||||
await expect(requestParser.handle({ url: 'url' } as any))
|
||||
.rejects.toThrow('No method specified on the HTTP request');
|
||||
});
|
||||
|
||||
it('returns the output of all input parsers after calling handle.', async(): Promise<void> => {
|
||||
bodyParser.handle = ({ metadata }): any => ({ data: 'body', metadata });
|
||||
await expect(requestParser.handle({ url: 'url', method: 'GET' } as any)).resolves.toEqual({
|
||||
method: 'GET',
|
||||
target: 'target',
|
||||
preferences: 'preference',
|
||||
conditions: 'conditions',
|
||||
body: { data: 'body', metadata: new RepresentationMetadata('target') },
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user