mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add contains function to IdentifierStrategy
This commit is contained in:
@@ -14,20 +14,45 @@ class DummyStrategy extends BaseIdentifierStrategy {
|
||||
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/' });
|
||||
describe('getParentContainer', (): void => {
|
||||
it('returns the parent identifier.', async(): Promise<void> => {
|
||||
expect(strategy.getParentContainer({ path: 'http://example.com/foo/bar' })).toEqual({ path: 'http://example.com/foo/' });
|
||||
expect(strategy.getParentContainer({ path: 'http://example.com/foo/bar/' })).toEqual({ path: 'http://example.com/foo/' });
|
||||
});
|
||||
|
||||
it('errors when attempting to get the parent of an unsupported identifier.', async(): Promise<void> => {
|
||||
expect((): any => strategy.getParentContainer({ path: '/unsupported' }))
|
||||
.toThrow('The identifier /unsupported is outside the configured identifier space.');
|
||||
expect((): any => strategy.getParentContainer({ path: '/unsupported' }))
|
||||
.toThrow(expect.objectContaining({ errorCode: 'E0001', details: { path: '/unsupported' }}));
|
||||
});
|
||||
|
||||
it('errors when attempting to get the parent of a root container.', async(): Promise<void> => {
|
||||
expect((): any => strategy.getParentContainer({ path: 'http://example.com/root' }))
|
||||
.toThrow('Cannot obtain the parent of http://example.com/root because it is a root container.');
|
||||
});
|
||||
});
|
||||
|
||||
it('errors when attempting to get the parent of an unsupported identifier.', async(): Promise<void> => {
|
||||
expect((): any => strategy.getParentContainer({ path: '/unsupported' }))
|
||||
.toThrow('The identifier /unsupported is outside the configured identifier space.');
|
||||
expect((): any => strategy.getParentContainer({ path: '/unsupported' }))
|
||||
.toThrow(expect.objectContaining({ errorCode: 'E0001', details: { path: '/unsupported' }}));
|
||||
});
|
||||
describe('contains', (): void => {
|
||||
it('returns false if container parameter is not a container identifier.', async(): Promise<void> => {
|
||||
expect(strategy.contains({ path: 'http://example.com' }, { path: 'http://example.com/foo' }, false)).toBe(false);
|
||||
});
|
||||
|
||||
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('Cannot obtain the parent of http://test.com/root because it is a root container.');
|
||||
it('returns false if container parameter is longer.', async(): Promise<void> => {
|
||||
expect(strategy.contains({ path: 'http://example.com/foo/' }, { path: 'http://example.com' }, false)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false if container parameter is not the direct container.', async(): Promise<void> => {
|
||||
expect(strategy.contains({ path: 'http://example.com/' }, { path: 'http://example.com/foo/bar' }, false)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true if the container parameter is the direct container.', async(): Promise<void> => {
|
||||
expect(strategy.contains({ path: 'http://example.com/' }, { path: 'http://example.com/foo/' }, false)).toBe(true);
|
||||
expect(strategy.contains({ path: 'http://example.com/' }, { path: 'http://example.com/foo' }, false)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for transtive calls if container parameter is a grandparent.', async(): Promise<void> => {
|
||||
expect(strategy.contains({ path: 'http://example.com/' }, { path: 'http://example.com/foo/bar' }, true)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user