From 807692568dca4814eba0e9d425bc41b9a48db989 Mon Sep 17 00:00:00 2001 From: Reza Soltani Date: Tue, 9 Jan 2024 13:40:14 +0330 Subject: [PATCH] create container before inserting to typeIndex (#4) * create container before inserting to typeIndex * fix tests for registerInTypeIndex --- package-lock.json | 4 ++-- package.json | 2 +- src/TypeIndexHelper.ts | 15 ++++++--------- test/unit/TypeIndexHelper.test.ts | 2 ++ test/unit/fixtures/createRegisteryDS.json | 16 ++++++++++++++++ 5 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 test/unit/fixtures/createRegisteryDS.json diff --git a/package-lock.json b/package-lock.json index 1fe4e84..3ffa23d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@rezasoltani/solid-typeindex-support", - "version": "0.0.1", + "version": "0.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@rezasoltani/solid-typeindex-support", - "version": "0.0.1", + "version": "0.0.4", "license": "MIT", "dependencies": { "@inrupt/solid-client": "^1.30.2", diff --git a/package.json b/package.json index 7365596..77a3ca1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/TypeIndexHelper.ts b/src/TypeIndexHelper.ts index c6fb61d..4a13921 100644 --- a/src/TypeIndexHelper.ts +++ b/src/TypeIndexHelper.ts @@ -3,6 +3,7 @@ import { ThingPersisted, addNamedNode, buildThing, + createSolidDataset, createThing, getNamedNode, getSolidDataset, @@ -196,13 +197,9 @@ export class TypeIndexHelper { ): Promise { 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) @@ -210,9 +207,9 @@ export class TypeIndexHelper { const updatedTypeIndexDS = setThing(typeIndexDS, registeryThing); - return await saveSolidDatasetAt(typeIndex?.value, updatedTypeIndexDS, { - fetch, - }); + await saveSolidDatasetAt(registeryUrl, createSolidDataset(), { fetch }); + + return await saveSolidDatasetAt(typeIndex?.value, updatedTypeIndexDS, { fetch }); } diff --git a/test/unit/TypeIndexHelper.test.ts b/test/unit/TypeIndexHelper.test.ts index 265d2c9..1015679 100644 --- a/test/unit/TypeIndexHelper.test.ts +++ b/test/unit/TypeIndexHelper.test.ts @@ -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); @@ -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); diff --git a/test/unit/fixtures/createRegisteryDS.json b/test/unit/fixtures/createRegisteryDS.json new file mode 100644 index 0000000..8f4aa98 --- /dev/null +++ b/test/unit/fixtures/createRegisteryDS.json @@ -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": {} + } +} \ No newline at end of file