mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Create SubdomainIdentifierStrategy
This strategy interprets all subdomains of the base to also be root containers.
This commit is contained in:
31
test/unit/util/identifiers/BaseIdentifierStrategy.test.ts
Normal file
31
test/unit/util/identifiers/BaseIdentifierStrategy.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { BaseIdentifierStrategy } from '../../../../src/util/identifiers/BaseIdentifierStrategy';
|
||||
|
||||
class DummyStrategy extends BaseIdentifierStrategy {
|
||||
public supportsIdentifier(identifier: ResourceIdentifier): boolean {
|
||||
return !identifier.path.endsWith('unsupported');
|
||||
}
|
||||
|
||||
public isRootContainer(identifier: ResourceIdentifier): boolean {
|
||||
return identifier.path.endsWith('root');
|
||||
}
|
||||
}
|
||||
|
||||
describe('A BaseIdentifierStrategy', (): void => {
|
||||
const strategy = new DummyStrategy();
|
||||
|
||||
it('returns the parent identifier.', async(): Promise<void> => {
|
||||
expect(strategy.getParentContainer({ path: 'http://test.com/foo/bar' })).toEqual({ path: 'http://test.com/foo/' });
|
||||
expect(strategy.getParentContainer({ path: 'http://test.com/foo/bar/' })).toEqual({ path: 'http://test.com/foo/' });
|
||||
});
|
||||
|
||||
it('errors when attempting to get the parent of an unsupported identifier.', async(): Promise<void> => {
|
||||
expect((): any => strategy.getParentContainer({ path: '/unsupported' }))
|
||||
.toThrow('/unsupported is not supported');
|
||||
});
|
||||
|
||||
it('errors when attempting to get the parent of a root container.', async(): Promise<void> => {
|
||||
expect((): any => strategy.getParentContainer({ path: 'http://test.com/root' }))
|
||||
.toThrow('http://test.com/root is a root container and has no parent');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user