import BookmarkListService from "../resources/bookmarkList/service"; import BookmarkList from "../resources/bookmarkList"; describe("BookmarkListService", () => { it("should fetch a bookmark list", () => { const fetchMock = jest.fn(() => new Promise((resolve => resolve({ data: { attributes: { "entries_count": 1, "name": "California Trip", "source": "dotcom", "visibility": "public" }, id: "1", type: "bookmkark-list", relationships: { entries: { data: [{ id: "2", type: "bookmark-entry" }] } } }, included: [{ type: "bookmark-entry", id: "2", attributes: { "checked": false, "created_at": "2016-06-04T04:58:15.003Z", "note": "Great wines recommended by my friend.", "order_number": 3 }, relationships: { target: { data: { id: "1234", type: "poi" } } } }] })))); const service = new BookmarkListService("access123"); service.http = { fetch: fetchMock, }; service.findByUserId("1") .then((list) => { expect(list.entries.length).toBe(1); }) .catch((e) => console.error(e)); expect(fetchMock).toHaveBeenCalledWith("/users/1/bookmark-lists?include=entries,entries.target&nocache=true", {"headers": {"Authorization": "Bearer access123"}}); }); it("should fetch a bookmark list with an object as the entries relationship", () => { const fetchMock = jest.fn(() => new Promise((resolve => resolve({ data: { attributes: { "entries_count": 1, "name": "California Trip", "source": "dotcom", "visibility": "public" }, id: "1", type: "bookmkark-list", relationships: { entries: { data: { id: "2", type: "bookmark-entry" } } } }, included: [{ type: "bookmark-entry", id: "2", attributes: { "checked": false, "created_at": "2016-06-04T04:58:15.003Z", "note": "Great wines recommended by my friend.", "order_number": 3 }, relationships: { target: { data: { id: "1234", type: "poi" } } } }] })))); const service = new BookmarkListService("access123"); service.http = { fetch: fetchMock, }; service.findByUserId("1") .then((list) => { expect(list.entries.length).toBe(1); }) .catch((e) => console.error(e)); expect(fetchMock).toHaveBeenCalledWith("/users/1/bookmark-lists?include=entries,entries.target&nocache=true", {"headers": {"Authorization": "Bearer access123"}}); }); });