feat: add simple target extractor

This commit is contained in:
Joachim Van Herwegen 2020-06-10 11:42:33 +02:00
parent d4f70d9c59
commit 3c8a087615
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,15 @@
import { HttpRequest } from '../../server/HttpRequest';
import { ResourceIdentifier } from '../representation/ResourceIdentifier';
import { TargetExtractor } from './TargetExtractor';
export class SimpleTargetExtractor extends TargetExtractor {
public async canHandle(input: HttpRequest): Promise<void> {
if (!input.url) {
throw new Error('Missing URL.');
}
}
public async handle(input: HttpRequest): Promise<ResourceIdentifier> {
return { path: input.url };
}
}

View File

@ -0,0 +1,17 @@
import { SimpleTargetExtractor } from '../../../../src/ldp/http/SimpleTargetExtractor';
describe('A SimpleTargetExtractor', (): void => {
const extractor = new SimpleTargetExtractor();
it('can handle input with an URL.', async(): Promise<void> => {
await expect(extractor.canHandle({ url: 'url' } as any)).resolves.toBeUndefined();
});
it('rejects input without URL.', async(): Promise<void> => {
await expect(extractor.canHandle({ } as any)).rejects.toThrow('Missing URL.');
});
it('returns the input URL.', async(): Promise<void> => {
await expect(extractor.handle({ url: 'url' } as any)).resolves.toEqual({ path: 'url' });
});
});