Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soltanireza65 committed Dec 22, 2023
1 parent e164580 commit 621ab9f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
18 changes: 9 additions & 9 deletions src/TypeIndexHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class TypeIndexHelper {
webId: string,
fetch: any
): Promise<ThingPersisted | null> {
const profileDS = await getSolidDataset(webId, { fetch: fetch });
const profileDS = await getSolidDataset(webId, { fetch });

let profileMe = getThing(profileDS, webId);

Expand All @@ -54,7 +54,7 @@ export class TypeIndexHelper {
const updatedProfileDS = await saveSolidDatasetAt(
webId!,
updatedProfile,
{ fetch: fetch }
{ fetch }
);

profileMe = getThing(updatedProfileDS, webId);
Expand Down Expand Up @@ -98,7 +98,7 @@ export class TypeIndexHelper {
const updatedTypeIndexDS = setThing(typeIndexDS!, updatedProfileMe);

await saveSolidDatasetAt(typeIndexUrl, updatedTypeIndexDS, {
fetch: fetch,
fetch,
});

return namedNode(typeIndexUrl);
Expand All @@ -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);
}
Expand All @@ -132,7 +132,7 @@ export class TypeIndexHelper {
public static async getFromTypeIndex(webId: string, rdfClass: string, fetch: any, isPrivate: boolean): Promise<string[]> {
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);

Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand All @@ -206,7 +206,7 @@ export class TypeIndexHelper {
const updatedTypeIndexDS = setThing(typeIndexDS, registeryThing);

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

Expand All @@ -232,7 +232,7 @@ export class TypeIndexHelper {
body: `@prefix solid: <http://www.w3.org/ns/solid/terms#>.\n\n<> a solid:TypeIndex, solid:UnlistedDocument.`,
});

return await getSolidDataset(typeIndexUrl, { fetch: fetch });
return await getSolidDataset(typeIndexUrl, { fetch });
} catch (error) { }
}

Expand Down
28 changes: 7 additions & 21 deletions test/unit/TypeIndexHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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);
});
Expand Down

0 comments on commit 621ab9f

Please sign in to comment.