import BookmarkPopularityService from "../resources/bookmarkPopularity/service"; describe("BookmarkPopularityService", () => { it("should fetch a bookmark popularity given place id", () => { const fetchMock = jest.fn(() => new Promise((resolve => resolve({ "data":[ { "type":"bookmark-popularity", "relationships":{ "target":{ "links":{ "related":"/pois/381139" }, "data":{ "type":"poi", "id":"381139" } } }, "id":"2258c560-93cc-49ba-9c0d-d150d878c1ef", "attributes":{ "bookmark_count":49 } }, { "type":"bookmark-popularity", "relationships":{ "target":{ "links":{ "related":"/pois/1129175" }, "data":{ "type":"poi", "id":"1129175" } } }, "id":"c6a300f3-77ca-4b0c-9a8d-dd46905c29dd", "attributes":{ "bookmark_count":11 } } ] })))); const service = new BookmarkPopularityService("access123"); service.http = { fetch: fetchMock, }; service.findByPlaceId("12345") .then((popularity) => { expect(popularity.length).toBe(2); }) .catch((e) => console.error(e)); expect(fetchMock).toHaveBeenCalledWith("/bookmark-lists/popularity?filter[target][place_id][equals]=12345", {"headers": {"Authorization": "Bearer access123"}}); }); it("should fetch a bookmark popularity given target type", () => { const fetchMock = jest.fn(() => new Promise((resolve => resolve({ "data": [ { "type": "bookmark-popularity", "relationships": { "target": { "links": { "related": "/pois/381139" }, "data": { "type": "poi", "id": "381139" } } }, "id": "0cacc176-f4c5-4d43-adf8-fd1d3f9f3c04", "attributes": { "bookmark_count": 49 } }, { "type": "bookmark-popularity", "relationships": { "target": { "links": { "related": "/pois/366245" }, "data": { "type": "poi", "id": "366245" } } }, "id": "18cb9a9e-a863-4e41-bb69-e4c693c205d6", "attributes": { "bookmark_count": 39 } } ] })))); const service = new BookmarkPopularityService("access123"); service.http = { fetch: fetchMock, }; service.findByTargetType("poi") .then((popularity) => { expect(popularity.length).toBe(2); }) .catch((e) => console.error(e)); expect(fetchMock).toHaveBeenCalledWith("/bookmark-lists/popularity?filter[target][type][equals]=poi", {"headers": {"Authorization": "Bearer access123"}}); }); });