Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
soltanireza65 committed Dec 12, 2023
1 parent 175c5ed commit 6092f1a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/TypeIndexHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class TypeIndexHelper {
* @param {true} isPrivate - Indicates if the instances are private.
* @return {Promise<string[]>} - A promise that resolves to an array of instance URLs.
*/
public static async getFromTypeIndex(webId: string, fetch: any, rdfClass: string, isPrivate: boolean): Promise<string[]> {
public static async getFromTypeIndex(webId: string, rdfClass: string, fetch: any, isPrivate: true): Promise<string[]> {
const typeIndex = await this.getTypeIndex(webId, fetch, isPrivate);

const typeIndexDS = await getSolidDataset(typeIndex?.value, { fetch: fetch });
Expand Down Expand Up @@ -156,18 +156,18 @@ export class TypeIndexHelper {
* @param {boolean} isPrivate - Flag indicating if the typeIndex is private.
* @return {Promise<SolidDataset>} The updated typeIndex dataset.
*/
public static async registerInTypeIndex(webId: string, registeryTitle: string, rdfClass: string, fetch: any, indexUrl: string, isPrivate: boolean): Promise<SolidDataset> {
public static async registerInTypeIndex(webId: string, typeRegistrationTitle: string, rdfClass: string, fetch: any, indexUrl: string, isPrivate: boolean): Promise<SolidDataset> {
const typeIndex = await this.getTypeIndex(webId, fetch, isPrivate);

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

const registery = buildThing(createThing({ name: registeryTitle }))
const registeryThing = buildThing(createThing({ name: typeRegistrationTitle }))
.addNamedNode(__forClass, namedNode(rdfClass))
.addNamedNode(__solid_instance, namedNode(indexUrl))
.addUrl(RDF.type, __solidTypeRegistration)
.build();

const updatedTypeIndexDS = setThing(typeIndexDS, registery);
const updatedTypeIndexDS = setThing(typeIndexDS, registeryThing);

return await saveSolidDatasetAt(typeIndex?.value, updatedTypeIndexDS, { fetch: fetch });
}
Expand Down
8 changes: 4 additions & 4 deletions test/unit/TypeIndexHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('getFromTypeIndex', () => {
jest.spyOn(TypeIndexHelper, 'getTypeIndex').mockResolvedValueOnce(namedNode(emptyTypeIndexPath));
jest.spyOn(session, "fetch").mockReturnValue(Promise.resolve(fetchResponse("emptyTypeIndex.ttl")));

const result = await TypeIndexHelper.getFromTypeIndex(session.info.webId, session.fetch, isPrivate);
const result = await TypeIndexHelper.getFromTypeIndex(session.info.webId, BOOKMARK.Bookmark, session.fetch, isPrivate);

expect(result).toEqual([]);
});
Expand All @@ -126,7 +126,7 @@ describe('getFromTypeIndex', () => {
jest.spyOn(TypeIndexHelper, 'getTypeIndex').mockResolvedValueOnce(namedNode(privateTypeIndexPath));
jest.spyOn(session, "fetch").mockReturnValue(Promise.resolve(fetchResponse("privateTypeIndex.ttl")));

const result = await TypeIndexHelper.getFromTypeIndex(session.info.webId, session.fetch, isPrivate);
const result = await TypeIndexHelper.getFromTypeIndex(session.info.webId, BOOKMARK.Bookmark, session.fetch, isPrivate);

expect(result.length).toBeGreaterThan(0);
});
Expand All @@ -145,7 +145,7 @@ describe("registerInTypeIndex", () => {
jest.spyOn(inruptSOLIDClient, 'setThing').mockReturnValueOnce(loadFixture("privateTypeIndexDS.json"));
jest.spyOn(inruptSOLIDClient, 'saveSolidDatasetAt').mockResolvedValueOnce(loadFixture("privateTypeIndexDS.json"));

const res = await TypeIndexHelper.registerInTypeIndex(session.info.webId, session.fetch, indexUrl, isPrivate);
const res = await TypeIndexHelper.registerInTypeIndex(session.info.webId, "bookmarks", BOOKMARK.bookmarks, session.fetch, indexUrl, isPrivate);

expect(res).toEqual(loadFixture("privateTypeIndexDS.json"));
expect(TypeIndexHelper.getTypeIndex).toHaveBeenCalledWith(session.info.webId, session.fetch, isPrivate);
Expand All @@ -162,7 +162,7 @@ describe("registerInTypeIndex", () => {
jest.spyOn(inruptSOLIDClient, 'setThing').mockReturnValueOnce(loadFixture("publicTypeIndexDS.json"));
jest.spyOn(inruptSOLIDClient, 'saveSolidDatasetAt').mockResolvedValueOnce(loadFixture("publicTypeIndexDS.json"));

const res = await TypeIndexHelper.registerInTypeIndex(session.info.webId, session.fetch, indexUrl, isPrivate);
const res = await TypeIndexHelper.registerInTypeIndex(session.info.webId, "bookmarks", BOOKMARK.bookmarks, session.fetch, indexUrl, isPrivate);

expect(res).toEqual(loadFixture("publicTypeIndexDS.json"));
expect(TypeIndexHelper.getTypeIndex).toHaveBeenCalledWith(session.info.webId, session.fetch, isPrivate);
Expand Down

0 comments on commit 6092f1a

Please sign in to comment.