mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Create router rule based on matching the base URL
This commit is contained in:
39
test/unit/storage/routing/BaseUrlRouterRule.test.ts
Normal file
39
test/unit/storage/routing/BaseUrlRouterRule.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import type { KeyValueStorage } from '../../../../src/storage/keyvalue/KeyValueStorage';
|
||||
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { BaseUrlRouterRule } from '../../../../src/storage/routing/BaseUrlRouterRule';
|
||||
import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError';
|
||||
|
||||
describe('A BaseUrlRouterRule', (): void => {
|
||||
let stores: KeyValueStorage<ResourceIdentifier, ResourceStore>;
|
||||
const baseStore = 'baseStore!' as any;
|
||||
const aliceIdentifier = { path: 'http://alice.test.com/' };
|
||||
const aliceStore = 'aliceStore!' as any;
|
||||
let rule: BaseUrlRouterRule;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
const map = new Map([[ aliceIdentifier.path, aliceStore ]]);
|
||||
stores = {
|
||||
* entries(): any {
|
||||
for (const [ path, val ] of map.entries()) {
|
||||
yield [{ path }, val ];
|
||||
}
|
||||
},
|
||||
} as any;
|
||||
|
||||
rule = new BaseUrlRouterRule(stores, baseStore);
|
||||
});
|
||||
|
||||
it('returns the matching store if the request contains the correct identifier.', async(): Promise<void> => {
|
||||
await expect(rule.handle({ identifier: { path: 'http://alice.test.com/foo' }})).resolves.toEqual(aliceStore);
|
||||
});
|
||||
|
||||
it('returns the base store if there is no matching identifier.', async(): Promise<void> => {
|
||||
await expect(rule.handle({ identifier: { path: 'http://bob.test.com/foo' }})).resolves.toEqual(baseStore);
|
||||
});
|
||||
|
||||
it('errors if there is no match and no base store.', async(): Promise<void> => {
|
||||
rule = new BaseUrlRouterRule(stores);
|
||||
await expect(rule.handle({ identifier: { path: 'http://bob.test.com/foo' }})).rejects.toThrow(NotFoundHttpError);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user