Skip to content

Commit

Permalink
chore: updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elf-pavlik committed Oct 26, 2023
1 parent b2bf526 commit cb210ad
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
8 changes: 6 additions & 2 deletions packages/api-messages/test/requests.-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 12 additions & 2 deletions packages/data-model/test/readable/inherited-data-grant-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions packages/service/test/unit/handlers/api-handler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};

Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
});
Expand Down
11 changes: 7 additions & 4 deletions packages/service/test/unit/services/data-registries-test.ts
Original file line number Diff line number Diff line change
@@ -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' } } };
})
}
},
Expand Down Expand Up @@ -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/',
Expand Down
5 changes: 3 additions & 2 deletions packages/service/test/unit/services/descriptions-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -215,6 +215,7 @@ describe('getDescriptions', () => {

describe('listDataInstances', () => {
const saiSession = jest.mocked({
webId,
factory: {
readable: {
dataRegistration: jest.fn(),
Expand All @@ -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) {
Expand Down

0 comments on commit cb210ad

Please sign in to comment.