diff --git a/packages/api-messages/test/requests.-test.ts b/packages/api-messages/test/requests.-test.ts index 78570052..a5dc24c5 100644 --- a/packages/api-messages/test/requests.-test.ts +++ b/packages/api-messages/test/requests.-test.ts @@ -57,10 +57,12 @@ describe('Request has proper message type', () => { test('DataRegistriesRequest', () => { const lang = 'en'; + const agentId = 'https://bob.example'; - const request = new DataRegistriesRequest(lang); + const request = new DataRegistriesRequest(agentId, lang); const expected = { type: RequestMessageTypes.DATA_REGISTRIES_REQUEST, + agentId, lang }; expect(JSON.parse(request.stringify())).toEqual(expected); @@ -80,10 +82,12 @@ describe('Request has proper message type', () => { test('ListDataInstancesRequest', () => { const registrationId = 'https://home.alice.example/data/projects'; + const agentId = 'https://bob.example'; - const request = new ListDataInstancesRequest(registrationId); + const request = new ListDataInstancesRequest(agentId, registrationId); const expected = { type: RequestMessageTypes.LIST_DATA_INSTANCES_REQUEST, + agentId, registrationId }; expect(JSON.parse(request.stringify())).toEqual(expected); diff --git a/packages/data-model/test/readable/all-from-registry-data-grant-test.ts b/packages/data-model/test/readable/all-from-registry-data-grant-test.ts index 8c317c98..0583877e 100644 --- a/packages/data-model/test/readable/all-from-registry-data-grant-test.ts +++ b/packages/data-model/test/readable/all-from-registry-data-grant-test.ts @@ -36,6 +36,12 @@ test('should set hasDataRegistration', async () => { expect(dataGrant.hasDataRegistration).toBe(dataRegistrationIri); }); +// depends on slash semantics +test('should provide dataRegistryIri', async () => { + const dataGrant = (await factory.readable.dataGrant(snippetIri)) as AllFromRegistryDataGrant; + expect(dataGrant.dataRegistryIri).toBe('https://'); +}); + test('should provide data instance iterator', async () => { const dataGrant = await factory.readable.dataGrant(snippetIri); let count = 0; diff --git a/packages/data-model/test/readable/inherited-data-grant-test.ts b/packages/data-model/test/readable/inherited-data-grant-test.ts index b2502eb9..7c182f02 100644 --- a/packages/data-model/test/readable/inherited-data-grant-test.ts +++ b/packages/data-model/test/readable/inherited-data-grant-test.ts @@ -55,9 +55,19 @@ test('should set inheritsFromGrant', async () => { const dataGrant = (await factory.readable.dataGrant(inheritsFromSelectedFromRegistryIri)) as InheritedDataGrant; expect(dataGrant.inheritsFromGrant).toBeInstanceOf(AbstractDataGrant); }); +test('should set inheritsFromGrant', async () => { + const dataGrant = (await factory.readable.dataGrant(inheritsFromSelectedFromRegistryIri)) as InheritedDataGrant; + expect(dataGrant.inheritsFromGrant).toBeInstanceOf(AbstractDataGrant); +}); + +// depends on slash semantics +test('should provide dataRegistryIri', async () => { + const dataGrant = (await factory.readable.dataGrant(inheritsFromSelectedFromRegistryIri)) as InheritedDataGrant; + expect(dataGrant.dataRegistryIri).toBe('https://'); +}); test('should provide data instance iterator for Inherited of AllFromRegistry', async () => { - const inheritingGrant = accessGrant.hasDataGrant.find((grant) => grant.iri === inheritsFromAllFromRegistryIri); + const inheritingGrant = accessGrant.hasDataGrant.find((grant) => grant.iri === inheritsFromAllFromRegistryIri)!; let count = 0; for await (const instance of inheritingGrant.getDataInstanceIterator()) { expect(instance).toBeInstanceOf(DataInstance); @@ -67,7 +77,7 @@ test('should provide data instance iterator for Inherited of AllFromRegistry', a }); test('should provide data instance iterator for Inherited of SelectedFromRegistry', async () => { - const inheritingGrant = accessGrant.hasDataGrant.find((grant) => grant.iri === inheritsFromSelectedFromRegistryIri); + const inheritingGrant = accessGrant.hasDataGrant.find((grant) => grant.iri === inheritsFromSelectedFromRegistryIri)!; let count = 0; for await (const instance of inheritingGrant.getDataInstanceIterator()) { expect(instance).toBeInstanceOf(DataInstance); diff --git a/packages/service/test/unit/handlers/api-handler-test.ts b/packages/service/test/unit/handlers/api-handler-test.ts index 5f31bffe..22618cab 100644 --- a/packages/service/test/unit/handlers/api-handler-test.ts +++ b/packages/service/test/unit/handlers/api-handler-test.ts @@ -41,10 +41,10 @@ let apiHandler: ApiHandler; let queue: MockedQueue; let saiSession: AuthorizationAgent; -const aliceWebId = 'https://alice.example'; +const webId = 'https://alice.example'; const authn = { - webId: aliceWebId, + webId, clientId: 'https://frontend.example' }; @@ -268,6 +268,7 @@ describe('listDataInstances', () => { headers, body: { type: RequestMessageTypes.LIST_DATA_INSTANCES_REQUEST, + agentId: 'https://bob.example', registrationId: 'https://hr.acme.example/data/projects/' } } as unknown as HttpHandlerRequest; @@ -282,7 +283,7 @@ describe('listDataInstances', () => { expect(response.body.type).toBe(ResponseMessageTypes.LIST_DATA_INSTANCES_RESPONSE); expect(response.body.payload).toBe(dataInstances); - expect(mocked.listDataInstances).toBeCalledWith(request.body.registrationId, saiSession); + expect(mocked.listDataInstances).toBeCalledWith(request.body.agentId, request.body.registrationId, saiSession); done(); } }); diff --git a/packages/service/test/unit/services/data-registries-test.ts b/packages/service/test/unit/services/data-registries-test.ts index 24944167..d85ea33b 100644 --- a/packages/service/test/unit/services/data-registries-test.ts +++ b/packages/service/test/unit/services/data-registries-test.ts @@ -1,16 +1,19 @@ -import { AuthorizationAgent } from '@janeirodigital/interop-authorization-agent'; +// eslint-disable-next-line import/no-extraneous-dependencies import { jest } from '@jest/globals'; +import { AuthorizationAgent } from '@janeirodigital/interop-authorization-agent'; import { getDataRegistries } from '../../../src/services/data-registries'; +const webId = 'https://alice.example'; + const saiSession = { + webId, factory: { readable: { shapeTree: jest.fn((iri: string) => { if (iri.includes('Project')) { return { descriptions: { en: { label: 'Projects' } } }; - } else { - return { descriptions: { en: { label: 'Tasks' } } }; } + return { descriptions: { en: { label: 'Tasks' } } }; }) } }, @@ -51,7 +54,7 @@ const saiSession = { } as unknown as AuthorizationAgent; test('gets well formated data registries', async () => { - const result = await getDataRegistries(saiSession, 'en'); + const result = await getDataRegistries(webId, 'en', saiSession); expect(result).toEqual([ { id: 'https://rnd.acme.example/data/', diff --git a/packages/service/test/unit/services/descriptions-test.ts b/packages/service/test/unit/services/descriptions-test.ts index 96dc4e3d..4fa433f5 100644 --- a/packages/service/test/unit/services/descriptions-test.ts +++ b/packages/service/test/unit/services/descriptions-test.ts @@ -16,9 +16,9 @@ import { getDescriptions, recordAuthorization, listDataInstances } from '../../. jest.setTimeout(30000); const projectShapeTree = 'https://solidshapes.example/trees/Project'; +const webId = 'https://alice.example'; describe('getDescriptions', () => { - const webId = 'https://alice.example'; const applicationIri = 'https://projectron.example'; const lang = 'en'; @@ -215,6 +215,7 @@ describe('getDescriptions', () => { describe('listDataInstances', () => { const saiSession = jest.mocked({ + webId, factory: { readable: { dataRegistration: jest.fn(), @@ -238,7 +239,7 @@ describe('listDataInstances', () => { contains: new Array(count) } as unknown as ReadableDataRegistration); saiSession.factory.readable.dataInstance.mockResolvedValue(template); - const result = await listDataInstances(registrationId, saiSession); + const result = await listDataInstances(webId, registrationId, saiSession); expect(saiSession.factory.readable.dataRegistration).toBeCalledWith(registrationId); expect(saiSession.factory.readable.dataInstance).toHaveBeenCalledTimes(count); for (const instance of result) {