import AvailabilityService from "../resources/availability/service"; import AvailabilityMapper from "../resources/availability/mapper"; describe("AvailabilityService", () => { it("should check the availability of a given lodging based on dates ", (done) => { const fetchMock = jest.fn(() => new Promise((resolve => resolve({ data: [{ attributes: { title: "Poland", offerings: [{ maxOccupancy: "1", cost: {}, description: "desc", }], }, id: "1", type: "availability", }], })))); const fakeId = "1"; const fakeDates = { fromDate: "1-13-1986", toDate: "1-15-1986", }; const service = new AvailabilityService("token123"); service.mapper = new AvailabilityMapper(); service.http = { fetch: fetchMock, }; service.checkDates(fakeId, fakeDates) .then((payload) => { expect(payload[0].id).toBe("1"); expect(payload[0].type).toBe("availability"); done(); }) .catch((e) => console.error(e)); expect(fetchMock).toHaveBeenCalledWith( `/lodgings/availability?filter[availability][available][from]=1-13-1986&filter[availability][available][to]=1-15-1986&filter[lodgings][equals]=1`, { "headers": { "Authorization": "Bearer token123" } } ); }); });