Skip to content

Commit

Permalink
create container before inserting to typeIndex (#4)
Browse files Browse the repository at this point in the history
* create container before inserting to typeIndex

* fix tests for registerInTypeIndex
  • Loading branch information
soltanireza65 authored Jan 9, 2024
1 parent 206685e commit 8076925
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rezasoltani/solid-typeindex-support",
"version": "0.0.4",
"version": "0.0.5",
"description": "",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
15 changes: 6 additions & 9 deletions src/TypeIndexHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ThingPersisted,
addNamedNode,
buildThing,
createSolidDataset,
createThing,
getNamedNode,
getSolidDataset,
Expand Down Expand Up @@ -196,23 +197,19 @@ export class TypeIndexHelper {
): Promise<SolidDataset> {
const typeIndex = await this.getTypeIndex(webId, fetch, isPrivate);

const typeIndexDS = await getSolidDataset(typeIndex?.value, {
fetch,
});
const typeIndexDS = await getSolidDataset(typeIndex?.value, { fetch });

const registeryThing = buildThing(
createThing({ name: typeRegistrationTitle })
)
const registeryThing = buildThing(createThing({ name: typeRegistrationTitle }))
.addNamedNode(__forClass, namedNode(rdfClass))
.addNamedNode(isContainer ? __solid_instance_container : __solid_instance, namedNode(registeryUrl))
.addUrl(RDF.type, __solidTypeRegistration)
.build();

const updatedTypeIndexDS = setThing(typeIndexDS, registeryThing);

return await saveSolidDatasetAt(typeIndex?.value, updatedTypeIndexDS, {
fetch,
});
await saveSolidDatasetAt(registeryUrl, createSolidDataset(), { fetch });

return await saveSolidDatasetAt(typeIndex?.value, updatedTypeIndexDS, { fetch });
}


Expand Down
2 changes: 2 additions & 0 deletions test/unit/TypeIndexHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ describe("registerInTypeIndex", () => {
jest.spyOn(TypeIndexHelper, 'getTypeIndex').mockResolvedValueOnce(namedNode(privateTypeIndexPath));
jest.spyOn(inruptSOLIDClient, "getSolidDataset").mockResolvedValue(loadFixture("privateTypeIndexDS.json"));
jest.spyOn(inruptSOLIDClient, 'setThing').mockReturnValueOnce(loadFixture("privateTypeIndexDS.json"));
jest.spyOn(inruptSOLIDClient, 'saveSolidDatasetAt').mockResolvedValueOnce(loadFixture("createRegisteryDS.json"));
jest.spyOn(inruptSOLIDClient, 'saveSolidDatasetAt').mockResolvedValueOnce(loadFixture("privateTypeIndexDS.json"));

const res = await TypeIndexHelper.registerInTypeIndex(session.info.webId, "bookmarks", BOOKMARK.bookmarks, session.fetch, indexUrl, isContainer, isPrivate);
Expand All @@ -164,6 +165,7 @@ describe("registerInTypeIndex", () => {
jest.spyOn(TypeIndexHelper, 'getTypeIndex').mockResolvedValueOnce(namedNode(privateTypeIndexPath));
jest.spyOn(inruptSOLIDClient, "getSolidDataset").mockResolvedValue(loadFixture("publicTypeIndexDS.json"));
jest.spyOn(inruptSOLIDClient, 'setThing').mockReturnValueOnce(loadFixture("publicTypeIndexDS.json"));
jest.spyOn(inruptSOLIDClient, 'saveSolidDatasetAt').mockResolvedValueOnce(loadFixture("createRegisteryDS.json"));
jest.spyOn(inruptSOLIDClient, 'saveSolidDatasetAt').mockResolvedValueOnce(loadFixture("publicTypeIndexDS.json"));

const res = await TypeIndexHelper.registerInTypeIndex(session.info.webId, "bookmarks", BOOKMARK.bookmarks, session.fetch, indexUrl, isContainer, isPrivate);
Expand Down
16 changes: 16 additions & 0 deletions test/unit/fixtures/createRegisteryDS.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"type": "Dataset",
"graphs": {
"default": {}
},
"internal_changeLog": {
"additions": [],
"deletions": []
},
"internal_resourceInfo": {
"sourceIri": "https://fake-pod.net/bookmarks/",
"isRawData": false,
"contentType": "text/plain; charset=utf-8",
"linkedResources": {}
}
}

0 comments on commit 8076925

Please sign in to comment.