Skip to content

Commit

Permalink
add soukai handle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soltanireza65 committed Dec 7, 2023
1 parent 6426eb6 commit 405faaa
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
35 changes: 32 additions & 3 deletions bookmarks/vanilla/test/unit/Bookmark.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe("Bookmark", () => {
title: 'updated',
link: 'http://updated.com',
creator: 'https://michielbdejong.solidcommunity.net/profile/card#me'
}
}

const responseGet: any = {
status: 200,
Expand All @@ -212,7 +212,6 @@ describe("Bookmark", () => {
const mockSetThing = jest.spyOn(inruptClient, "setThing").mockReturnValue(JSON.parse(loadFixture("ds-with-updated.json")));

const res = await Bookmark.update(url, payload, session);
console.log("🚀 ~ file: Bookmark.test.ts:215 ~ it ~ res:", res)


expect(res?.title).toEqual(expected.title);
Expand Down Expand Up @@ -307,7 +306,37 @@ describe("Bookmark", () => {
const fetchMock = jest.spyOn(session, "fetch").mockReturnValue(Promise.resolve(responseObject));

const res = await Bookmark.get(url, session);



expect(res).toEqual(expected);
fetchMock.mockRestore();
});
it("should parse bookmarks created with soukai", async () => {
const url = 'https://fake-pod.ne/bookmarks/b93d9944-d54d-42f6-a39b-6ea3f9217763';

const expected = {
url: 'https://fake-pod.ne/bookmarks/b93d9944-d54d-42f6-a39b-6ea3f9217763',
title: 'sdf',
link: 'http://example.com',
created: '2023-11-21T12:50:32.051Z',
updated: '2023-11-21T12:50:32.051Z'
}

const responseObject: any = {
status: 200,
ok: true,
headers: {
get: (h: string) => (h == "Content-Type" ? "text/turtle" : undefined)
},
text: () => {
return Promise.resolve(loadFixture("bookmark-formats.ttl"));
}
};

const fetchMock = jest.spyOn(session, "fetch").mockReturnValue(Promise.resolve(responseObject));

const res = await Bookmark.get(url, session);


expect(res).toEqual(expected);
fetchMock.mockRestore();
Expand Down
4 changes: 3 additions & 1 deletion bookmarks/vanilla/test/unit/fixtures/allBookmarks.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ export const allBookmarksMock: IBookmark[] = [
link: 'http://example.com',
},
{
url: '/b93d9944-d54d-42f6-a39b-6ea3f9217763',
url: 'https://fake-pod.ne/bookmarks/b93d9944-d54d-42f6-a39b-6ea3f9217763',
title: 'sdf',
link: 'http://example.com',
created: "2023-11-21T12:50:32.051Z",
updated: "2023-11-21T12:50:32.051Z",
},
]
4 changes: 2 additions & 2 deletions bookmarks/vanilla/test/unit/fixtures/bookmark-formats.ttl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@prefix : <https://fake-pod.net/path/to/bookmark-formats.ttl#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix bookm: <./>.
@prefix bookm: <https://fake-pod.ne/bookmarks/>.
@prefix boo: <http://www.w3.org/2002/01/bookmark#>.
@prefix dc: <http://purl.org/dc/terms/>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix crdt: <http://soukai-solid.com/crdt>.
@prefix crdt: <http://soukai-solid.com/crdt/>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:one
Expand Down
20 changes: 20 additions & 0 deletions bookmarks/vanilla/test/unit/fixtures/bookmark-soukai.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@prefix : <https://fake-pod.net/path/to/bookmark-formats.ttl#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix bookm: <https://solid-dm.solidcommunity.net/bookmarks/>.
@prefix boo: <http://www.w3.org/2002/01/bookmark#>.
@prefix dc: <http://purl.org/dc/terms/>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix crdt: <http://soukai-solid.com/crdt/>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

bookm:b93d9944-d54d-42f6-a39b-6ea3f9217763
a boo:Bookmark;
rdfs:label "sdf";
boo:hasTopic "sdfg";
boo:id "b93d9944-d54d-42f6-a39b-6ea3f9217763";
boo:recalls <http://example.com>.
bookm:b93d9944-d54d-42f6-a39b-6ea3f9217763-metadata
a crdt:Metadata;
crdt:createdAt "2023-11-21T12:50:32.051Z"^^xsd:dateTime;
crdt:resource bookm:b93d9944-d54d-42f6-a39b-6ea3f9217763;
crdt:updatedAt "2023-11-21T12:50:32.051Z"^^xsd:dateTime.

0 comments on commit 405faaa

Please sign in to comment.