import UserService from "../resources/user/userService"; import User from "../resources/user"; import UserMapper from "../resources/user/userMapper"; describe("UserService", () => { it("should update properties", () => { const fetchMock = jest.fn(() => new Promise((resolve => resolve({ data: { attributes: { first_name: "boo" }, id: 1, type: "user", }, })))); const service = new UserService("access123"); service.mapper = new UserMapper(); service.http = { fetch: fetchMock, }; service.update({ id: "1", firstName: "Guy" }) .catch((e) => console.error(e)); expect(fetchMock).toHaveBeenCalledWith("/users/1", {"body": {"data": {"attributes": {"first_name": "Guy"}, "id": "1", "type": "user"}}, "headers": {"Authorization": "Bearer access123"}, "method": "PATCH"}); }); it("should authenticate", () => { const fetchMock = jest.fn(() => new Promise((resolve => resolve({ sub: "1234", })))); const service = new UserService("access123"); service.mapper = new UserMapper(); service.http = { fetch: fetchMock, }; service.findById = jest.fn(); service.me() .catch((e) => console.error(e)) .then(() => { expect(service.findById).toHaveBeenCalledWith("1234", {}); }); }); });