From 621ab9fddfc700eff4a96296210ca8f8457736dd Mon Sep 17 00:00:00 2001 From: Reza Soltani Date: Fri, 22 Dec 2023 19:27:32 +0330 Subject: [PATCH] fix tests --- src/TypeIndexHelper.ts | 18 +++++++++--------- test/unit/TypeIndexHelper.test.ts | 28 +++++++--------------------- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/src/TypeIndexHelper.ts b/src/TypeIndexHelper.ts index 0f8c2cb..1ae0121 100644 --- a/src/TypeIndexHelper.ts +++ b/src/TypeIndexHelper.ts @@ -39,7 +39,7 @@ export class TypeIndexHelper { webId: string, fetch: any ): Promise { - const profileDS = await getSolidDataset(webId, { fetch: fetch }); + const profileDS = await getSolidDataset(webId, { fetch }); let profileMe = getThing(profileDS, webId); @@ -54,7 +54,7 @@ export class TypeIndexHelper { const updatedProfileDS = await saveSolidDatasetAt( webId!, updatedProfile, - { fetch: fetch } + { fetch } ); profileMe = getThing(updatedProfileDS, webId); @@ -98,7 +98,7 @@ export class TypeIndexHelper { const updatedTypeIndexDS = setThing(typeIndexDS!, updatedProfileMe); await saveSolidDatasetAt(typeIndexUrl, updatedTypeIndexDS, { - fetch: fetch, + fetch, }); return namedNode(typeIndexUrl); @@ -114,7 +114,7 @@ export class TypeIndexHelper { const updatedProfileDS = setThing(profileDS, profileMeThing); - await saveSolidDatasetAt(webId, updatedProfileDS, { fetch: fetch }); + await saveSolidDatasetAt(webId, updatedProfileDS, { fetch }); return namedNode(typeIndexUrl); } @@ -132,7 +132,7 @@ export class TypeIndexHelper { public static async getFromTypeIndex(webId: string, rdfClass: string, fetch: any, isPrivate: boolean): Promise { const typeIndex = await this.getTypeIndex(webId, fetch, isPrivate); - const typeIndexDS = await getSolidDataset(typeIndex?.value, { fetch: fetch }); + const typeIndexDS = await getSolidDataset(typeIndex?.value, { fetch }); const allRegisteries = getThingAll(typeIndexDS); @@ -155,7 +155,7 @@ export class TypeIndexHelper { const instanceContainersPromises = instanceContainers.map(async (instanceContainer) => { - const instanceContainerDS = await getSolidDataset(instanceContainer, { fetch: fetch }) + const instanceContainerDS = await getSolidDataset(instanceContainer, { fetch }) const all = getThingAll(instanceContainerDS); // all files under the instanceContainer @@ -192,7 +192,7 @@ export class TypeIndexHelper { const typeIndex = await this.getTypeIndex(webId, fetch, isPrivate); const typeIndexDS = await getSolidDataset(typeIndex?.value, { - fetch: fetch, + fetch, }); const registeryThing = buildThing( @@ -206,7 +206,7 @@ export class TypeIndexHelper { const updatedTypeIndexDS = setThing(typeIndexDS, registeryThing); return await saveSolidDatasetAt(typeIndex?.value, updatedTypeIndexDS, { - fetch: fetch, + fetch, }); } @@ -232,7 +232,7 @@ export class TypeIndexHelper { body: `@prefix solid: .\n\n<> a solid:TypeIndex, solid:UnlistedDocument.`, }); - return await getSolidDataset(typeIndexUrl, { fetch: fetch }); + return await getSolidDataset(typeIndexUrl, { fetch }); } catch (error) { } } diff --git a/test/unit/TypeIndexHelper.test.ts b/test/unit/TypeIndexHelper.test.ts index 3df9e82..3e0a0af 100644 --- a/test/unit/TypeIndexHelper.test.ts +++ b/test/unit/TypeIndexHelper.test.ts @@ -216,23 +216,11 @@ describe('createTypeIndex', () => { }); }) - -describe('getTypeIndexFileName', () => { - it('should return "privateTypeIndex" if isPrivate is true', () => { - const result = TypeIndexHelper.getTypeIndexFileName(true); - expect(result).toBe("privateTypeIndex"); - }); - - it('should return "publicTypeIndex" if isPrivate is false', () => { - const result = TypeIndexHelper.getTypeIndexFileName(false); - expect(result).toBe("publicTypeIndex"); - }); -}); - describe("getTypeIndexPredicate", () => { it("returns __privateTypeIndex if isPrivate is true", () => { const isPrivate = true; const result = TypeIndexHelper.getTypeIndexPredicate(isPrivate); + console.log("🚀 ~ file: TypeIndexHelper.test.ts:223 ~ it ~ result:", result) expect(result).toBe(__privateTypeIndex); }); @@ -244,23 +232,21 @@ describe("getTypeIndexPredicate", () => { }); -describe("getTypeIndexURL", () => { - it("should return the correct URL when given a valid webId and typeIndexFileName", () => { +describe("getDefaultTypeIndexURL", () => { + it("should return the correct URL when given a valid webId and ", () => { const webId = "https://example.com/profile/user123"; - const typeIndexFileName = "typeIndex"; - const expectedURL = "https://example.com/settings/typeIndex.ttl"; + const expectedURL = "https://example.com/settings/privateTypeIndex.ttl"; - const result = TypeIndexHelper.getTypeIndexURL(webId, typeIndexFileName); + const result = TypeIndexHelper.getDefaultTypeIndexURL(webId, true); expect(result).toEqual(expectedURL); }); it("should return the correct URL when given a webId with a trailing slash and typeIndexFileName", () => { const webId = "https://example.com/profile/user123/"; - const typeIndexFileName = "typeIndex"; - const expectedURL = "https://example.com/settings/typeIndex.ttl"; + const expectedURL = "https://example.com/settings/privateTypeIndex.ttl"; - const result = TypeIndexHelper.getTypeIndexURL(webId, typeIndexFileName); + const result = TypeIndexHelper.getDefaultTypeIndexURL(webId, true); expect(result).toEqual(expectedURL); });