Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elf-pavlik committed Aug 27, 2024
1 parent 409ef72 commit f4d8c72
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 41 deletions.
99 changes: 69 additions & 30 deletions packages/application/test/application.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { randomUUID } from 'crypto';
import { vi, describe, test, expect, beforeAll, afterAll, beforeEach } from 'vitest';
import { SolidTestUtils, luka, vaporcg, inspector, shapeTree } from '@janeirodigital/css-test-utils';
import { SolidTestUtils, accounts } from '@janeirodigital/css-test-utils';
import { statelessFetch } from '@janeirodigital/interop-test-utils';
import { ReadableApplicationRegistration, DataOwner } from '@janeirodigital/interop-data-model';
import { RdfResponse } from '@janeirodigital/interop-utils';
Expand All @@ -10,7 +10,7 @@ import { Application } from '../src';

vi.setConfig({ testTimeout: 200_000, hookTimeout: 200_000 });

const stu = new SolidTestUtils(luka);
const stu = new SolidTestUtils(accounts.luka);
beforeAll(async () => stu.beforeAll());
afterAll(async () => stu.afterAll());

Expand Down Expand Up @@ -101,8 +101,8 @@ describe('describe discovery', () => {

const info = {
id: 'http://localhost:3711/corvax/x7b09z/znmqto/ibc822',
scope: shapeTree.Widget,
resourceServer: luka.data.corvax,
scope: accounts.shapeTree.Widget,
resourceServer: accounts.luka.data.corvax,
parent: 'http://localhost:3711/corvax/x7b09z/mt4xs0/lcea5v'
};

Expand All @@ -117,17 +117,23 @@ describe('describe discovery', () => {

describe('resourceOwners', () => {
test('should return set of owenrs', async () => {
const resourceOwners = new Set([luka.webId, vaporcg.webId]);
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
const resourceOwners = new Set([accounts.luka.webId, accounts.vaporcg.webId]);
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});
expect(app.resourceOwners()).toEqual(resourceOwners);
});
});

describe('resourceServers', () => {
test('should return set of resource servers', async () => {
const resourceServers = new Set(Object.values(luka.data));
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
expect(app.resourceServers(luka.webId, shapeTree.Gadget)).toEqual(resourceServers);
const resourceServers = new Set(Object.values(accounts.luka.data));
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});
expect(app.resourceServers(accounts.luka.webId, accounts.shapeTree.Gadget)).toEqual(resourceServers);
});
});

Expand All @@ -137,28 +143,37 @@ describe('describe discovery', () => {
'http://localhost:3711/corvax/x7b09z/mt4xs0/lcea5v',
'http://localhost:3711/corvax/x7b09z/mt4xs0/jey14x'
]);
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
expect(await app.resources(luka.data.corvax, shapeTree.Gadget)).toEqual(resources);
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});
expect(await app.resources(accounts.luka.data.corvax, accounts.shapeTree.Gadget)).toEqual(resources);
});
});

describe('childInfo', () => {
test('should return info for a child resource', async () => {
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});

// populate parentMap
await app.resources(info.resourceServer, shapeTree.Gadget);
await app.resources(info.resourceServer, accounts.shapeTree.Gadget);

expect(await app.childInfo(info.id, info.scope, info.parent)).toEqual(info);
});
});

describe('setChildInfo', () => {
test('should set child info in the childMap', async () => {
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});

// populate parentMap
await app.resources(info.resourceServer, shapeTree.Gadget);
await app.resources(info.resourceServer, accounts.shapeTree.Gadget);

// set child info
await app.setChildInfo(info.id, info.scope, info.parent);
Expand All @@ -170,70 +185,91 @@ describe('describe discovery', () => {

describe('canCreate', () => {
test('should check if can create new resources in the scope', async () => {
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
expect(await app.canCreate(info.resourceServer, shapeTree.Gadget)).toEqual(true);
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});
expect(await app.canCreate(info.resourceServer, accounts.shapeTree.Gadget)).toEqual(true);
});
});

describe('canCreateChild', () => {
test('should check if can create a new child for a resource', async () => {
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});

// populate parentMap
await app.resources(info.resourceServer, shapeTree.Gadget);
await app.resources(info.resourceServer, accounts.shapeTree.Gadget);

expect(app.canCreateChild(info.parent, info.scope)).toBe(true);
});
});

describe('canUpdate', () => {
test('should check if can update the resource', async () => {
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});

// populate parentMap
await app.resources(info.resourceServer, shapeTree.Gadget);
await app.resources(info.resourceServer, accounts.shapeTree.Gadget);

expect(await app.canUpdate(info.parent)).toEqual(true);
});
});

describe('canDelete', () => {
test('should check if can delete the resource', async () => {
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});

// populate parentMap
await app.resources(info.resourceServer, shapeTree.Gadget);
await app.resources(info.resourceServer, accounts.shapeTree.Gadget);

expect(await app.canDelete(info.parent)).toEqual(true);
});
});

describe('iriForNew', () => {
test('should mint correct id for new resource', async () => {
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
expect(await app.iriForNew(info.resourceServer, shapeTree.Gadget)).toMatch(
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});
expect(await app.iriForNew(info.resourceServer, accounts.shapeTree.Gadget)).toMatch(
'http://localhost:3711/corvax/x7b09z/mt4xs0/'
);
});
});

describe('iriForChild', () => {
test('should mint correct id for new child for a resource', async () => {
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});

// populate parentMap
await app.resources(info.resourceServer, shapeTree.Gadget);
await app.resources(info.resourceServer, accounts.shapeTree.Gadget);

expect(await app.iriForChild(info.parent, info.scope)).toMatch('http://localhost:3711/corvax/x7b09z/znmqto/');
});
});

describe('findParent', () => {
test('should find parent resource given a child resource', async () => {
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});

// populate parentMap
await app.resources(info.resourceServer, shapeTree.Gadget);
await app.resources(info.resourceServer, accounts.shapeTree.Gadget);

// set child info
await app.setChildInfo(info.id, info.scope, info.parent);
Expand All @@ -245,7 +281,10 @@ describe('describe discovery', () => {
describe('discoverDescription', () => {
test.skip('should find auxiliary description resource', async () => {
const id = 'https://alice-work.pod.docker/dataRegistry/images/cat';
const app = await Application.build(luka.webId, inspector.clientId, { fetch: stu.authFetch, randomUUID });
const app = await Application.build(accounts.luka.webId, accounts.inspector.clientId, {
fetch: stu.authFetch,
randomUUID
});
expect(await app.discoverDescription(id)).toEqual('https://alice-work.pod.docker/dataRegistry/images/cat.meta');
});
});
Expand Down
5 changes: 3 additions & 2 deletions packages/data-model/test/crud/agent-registration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, test } from 'vitest';
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import { DataFactory } from 'n3';
import { SKOS, INTEROP } from '@janeirodigital/interop-utils';
import { SKOS, INTEROP, RDF } from '@janeirodigital/interop-utils';
import { expect } from '../expect';
import { CRUDSocialAgentRegistration, AuthorizationAgentFactory, SocialAgentRegistrationData } from '../../src';

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

test('should set dataset if data passed', async () => {
const quads = [
DataFactory.quad(DataFactory.namedNode(newSnippetIri), RDF.type, INTEROP.SocialAgentRegistration),
DataFactory.quad(
DataFactory.namedNode(newSnippetIri),
INTEROP.registeredAgent,
Expand All @@ -44,7 +45,7 @@ describe('build', () => {
DataFactory.quad(DataFactory.namedNode(newSnippetIri), SKOS.prefLabel, DataFactory.literal(data.prefLabel))
];
const agentRegistration = await CRUDSocialAgentRegistration.build(newSnippetIri, factory, false, data);
expect(agentRegistration.dataset.size).toBe(3);
expect(agentRegistration.dataset.size).toBe(4);
expect(agentRegistration.dataset).toBeRdfDatasetContaining(...quads);
});

Expand Down
13 changes: 9 additions & 4 deletions packages/data-model/test/crud/data-registration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, test } from 'vitest';
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import { DataFactory } from 'n3';
import { INTEROP } from '@janeirodigital/interop-utils';
import { INTEROP, RDF } from '@janeirodigital/interop-utils';
import { expect } from '../expect';
import { AuthorizationAgentFactory, CRUDDataRegistration } from '../../src';

Expand All @@ -13,7 +13,7 @@ const snippetIri = 'https://pro.alice.example/773605f0-b5bf-4d46-878d-5c167eac8b
const newSnippetIri = 'https://auth.alice.example/bd2bb0a3-e95a-4981-a30b-5b6a7358435c';

const data = {
shapeTree: 'https://solidshapes.example/tree/Other'
registeredShapeTree: 'https://solidshapes.example/tree/Other'
};

describe('build', () => {
Expand All @@ -29,10 +29,15 @@ describe('build', () => {

test('should set dataset if data passed', async () => {
const quads = [
DataFactory.quad(DataFactory.namedNode(newSnippetIri), INTEROP.shapeTree, DataFactory.namedNode(data.shapeTree))
DataFactory.quad(DataFactory.namedNode(newSnippetIri), RDF.type, INTEROP.DataRegistration),
DataFactory.quad(
DataFactory.namedNode(newSnippetIri),
INTEROP.registeredShapeTree,
DataFactory.namedNode(data.registeredShapeTree)
)
];
const dataRegistration = await CRUDDataRegistration.build(newSnippetIri, factory, data);
expect(dataRegistration.dataset.size).toBe(1);
expect(dataRegistration.dataset.size).toBe(2);
expect(dataRegistration.dataset).toBeRdfDatasetContaining(...quads);
});
});
10 changes: 5 additions & 5 deletions packages/data-model/test/crud/data-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ describe('createRegistration', () => {
expect(registration).toBeInstanceOf(CRUDDataRegistration);
});

test('should udpate created data registration', async () => {
test('should create data registration', async () => {
const localFactory = new AuthorizationAgentFactory(webId, agentId, { fetch, randomUUID });
const updateMock = vi.fn();
const createMock = vi.fn();
localFactory.crud.dataRegistration = vi.fn(
() => ({ update: updateMock }) as unknown as Promise<CRUDDataRegistration>
() => ({ create: createMock }) as unknown as Promise<CRUDDataRegistration>
);

const otherShapeTree = 'https://solidshapes.example/tree/Other';
const dataRegistry = await localFactory.crud.dataRegistry(snippetIri);
await dataRegistry.createRegistration(otherShapeTree);

expect(updateMock).toBeCalled();
expect(createMock).toBeCalled();
});

test('should link to new data registration and update itself', async () => {
const otherShapeTree = 'https://solidshapes.example/tree/Other';
const dataRegistry = await factory.crud.dataRegistry(snippetIri);
const dataRegistryUpdateSpy = vi.spyOn(dataRegistry, 'update');
const dataRegistryUpdateSpy = vi.spyOn(dataRegistry, 'addStatement');
const registration = await dataRegistry.createRegistration(otherShapeTree);
const expectedQuads = [
DataFactory.quad(
Expand Down

0 comments on commit f4d8c72

Please sign in to comment.