mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Rename associated resource to subject resource
This commit is contained in:
@@ -9,7 +9,7 @@ import { NotImplementedHttpError } from '../../../src/util/errors/NotImplemented
|
||||
describe('An AuxiliaryReader', (): void => {
|
||||
const suffix = '.dummy';
|
||||
const credentials = {};
|
||||
const associatedIdentifier = { path: 'http://test.com/foo' };
|
||||
const subjectIdentifier = { path: 'http://test.com/foo' };
|
||||
const auxiliaryIdentifier = { path: 'http://test.com/foo.dummy' };
|
||||
const permissionSet: PermissionSet = { [CredentialGroup.agent]: { read: true }};
|
||||
let source: jest.Mocked<PermissionReader>;
|
||||
@@ -25,20 +25,20 @@ describe('An AuxiliaryReader', (): void => {
|
||||
|
||||
strategy = {
|
||||
isAuxiliaryIdentifier: jest.fn((identifier: ResourceIdentifier): boolean => identifier.path.endsWith(suffix)),
|
||||
getAssociatedIdentifier: jest.fn((identifier: ResourceIdentifier): ResourceIdentifier =>
|
||||
getSubjectIdentifier: jest.fn((identifier: ResourceIdentifier): ResourceIdentifier =>
|
||||
({ path: identifier.path.slice(0, -suffix.length) })),
|
||||
usesOwnAuthorization: jest.fn().mockReturnValue(false),
|
||||
} as any;
|
||||
reader = new AuxiliaryReader(source, strategy);
|
||||
});
|
||||
|
||||
it('can handle auxiliary resources if the source supports the associated resource.', async(): Promise<void> => {
|
||||
it('can handle auxiliary resources if the source supports the subject resource.', async(): Promise<void> => {
|
||||
await expect(reader.canHandle({ identifier: auxiliaryIdentifier, credentials }))
|
||||
.resolves.toBeUndefined();
|
||||
expect(source.canHandle).toHaveBeenLastCalledWith(
|
||||
{ identifier: associatedIdentifier, credentials },
|
||||
{ identifier: subjectIdentifier, credentials },
|
||||
);
|
||||
await expect(reader.canHandle({ identifier: associatedIdentifier, credentials }))
|
||||
await expect(reader.canHandle({ identifier: subjectIdentifier, credentials }))
|
||||
.rejects.toThrow(NotImplementedHttpError);
|
||||
|
||||
strategy.usesOwnAuthorization.mockReturnValueOnce(true);
|
||||
@@ -54,10 +54,10 @@ describe('An AuxiliaryReader', (): void => {
|
||||
await expect(reader.handle({ identifier: auxiliaryIdentifier, credentials }))
|
||||
.resolves.toBe(permissionSet);
|
||||
expect(source.handle).toHaveBeenLastCalledWith(
|
||||
{ identifier: associatedIdentifier, credentials },
|
||||
{ identifier: subjectIdentifier, credentials },
|
||||
);
|
||||
// Safety checks are not present when calling `handle`
|
||||
await expect(reader.handle({ identifier: associatedIdentifier, credentials }))
|
||||
await expect(reader.handle({ identifier: subjectIdentifier, credentials }))
|
||||
.rejects.toThrow(NotImplementedHttpError);
|
||||
});
|
||||
|
||||
@@ -65,10 +65,10 @@ describe('An AuxiliaryReader', (): void => {
|
||||
await expect(reader.handleSafe({ identifier: auxiliaryIdentifier, credentials }))
|
||||
.resolves.toBe(permissionSet);
|
||||
expect(source.handleSafe).toHaveBeenLastCalledWith(
|
||||
{ identifier: associatedIdentifier, credentials },
|
||||
{ identifier: subjectIdentifier, credentials },
|
||||
);
|
||||
|
||||
await expect(reader.handleSafe({ identifier: associatedIdentifier, credentials }))
|
||||
await expect(reader.handleSafe({ identifier: subjectIdentifier, credentials }))
|
||||
.rejects.toThrow(NotImplementedHttpError);
|
||||
|
||||
strategy.usesOwnAuthorization.mockReturnValueOnce(true);
|
||||
|
||||
@@ -25,7 +25,7 @@ describe('A WebAclReader', (): void => {
|
||||
const aclStrategy: AuxiliaryIdentifierStrategy = {
|
||||
getAuxiliaryIdentifier: (id: ResourceIdentifier): ResourceIdentifier => ({ path: `${id.path}.acl` }),
|
||||
isAuxiliaryIdentifier: (id: ResourceIdentifier): boolean => id.path.endsWith('.acl'),
|
||||
getAssociatedIdentifier: (id: ResourceIdentifier): ResourceIdentifier => ({ path: id.path.slice(0, -4) }),
|
||||
getSubjectIdentifier: (id: ResourceIdentifier): ResourceIdentifier => ({ path: id.path.slice(0, -4) }),
|
||||
} as any;
|
||||
let store: jest.Mocked<ResourceStore>;
|
||||
const identifierStrategy = new SingleRootIdentifierStrategy('http://test.com/');
|
||||
|
||||
Reference in New Issue
Block a user