mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: add simple target extractor
This commit is contained in:
parent
d4f70d9c59
commit
3c8a087615
15
src/ldp/http/SimpleTargetExtractor.ts
Normal file
15
src/ldp/http/SimpleTargetExtractor.ts
Normal 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 };
|
||||
}
|
||||
}
|
17
test/unit/ldp/http/SimpleTargetExtractor.test.ts
Normal file
17
test/unit/ldp/http/SimpleTargetExtractor.test.ts
Normal 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' });
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user