Skip to content

Commit

Permalink
fix: test UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Piccio98 committed May 13, 2023
1 parent cafe703 commit 0690bb3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe('buildings', () => {
const result = await api.buildings.fetchBuildingsByUserId(testUserId);

expect(axios.get).toHaveBeenCalledTimes(1);
expect(axios.get).toHaveBeenCalledWith(`${API_URL}/buildings/find/${testUserId}`);
expect(axios.get).toHaveBeenCalledWith(`${API_URL}/buildings/user/${testUserId}`);
expect(result).toEqual(expectedData);
});
});
Expand All @@ -264,7 +264,7 @@ describe('buildings', () => {
const expectedData = { name: 'Building 1' };
axios.get.mockResolvedValueOnce({ data: expectedData });

const result = await api.buildings.fetchBuildings(testBuildingId);
const result = await api.buildings.getBuilding(testBuildingId);

expect(axios.get).toHaveBeenCalledTimes(1);
expect(axios.get).toHaveBeenCalledWith(`${API_URL}/buildings/${testBuildingId}`);
Expand Down
10 changes: 5 additions & 5 deletions test/buildingsUtils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('handleCoords', () => {
const setOptions = vi.fn();
await handleCoords('New York', setOptions);
expect(fetch).toHaveBeenCalledWith(
'https://api.geoapify.com/v1/geocode/search?text=New York&format=json&apiKey=811f21d574e34738a95aca463b9dfd74',
'https://api.geoapify.com/v1/geocode/search?text=New York&format=json&apiKey=e92ee477e1114d5c80988f7fd2d838d6',
{ method: 'GET' }
);
expect(setOptions).toHaveBeenCalledWith([
Expand All @@ -72,10 +72,10 @@ describe('addBuilding', () => {
userId: user._id
};
api.buildings.addBuilding = vi.fn().mockResolvedValue({});
api.buildings.fetchBuildings = vi.fn().mockResolvedValue([]);
api.buildings.fetchBuildingsByUserId = vi.fn().mockResolvedValue([]);
await addBuilding('Building A', 'John Doe', 'New York', '1000', 'Office', 40.7128, -74.006, [1, 2], user, setShow, dispatch);
expect(api.buildings.addBuilding).toHaveBeenCalledWith(data);
expect(api.buildings.fetchBuildings).toHaveBeenCalledWith("1");
expect(api.buildings.fetchBuildingsByUserId).toHaveBeenCalledWith("1");
expect(setShow).toHaveBeenCalledWith(true);
expect(dispatch).toHaveBeenCalledWith(fetchBuildings([]));
});
Expand All @@ -84,11 +84,11 @@ describe('addBuilding', () => {
const setShow = vi.fn();
const dispatch = vi.fn();
api.buildings.addBuilding = vi.fn().mockResolvedValue({});
api.buildings.fetchBuildings = vi.fn().mockResolvedValue([]);
api.buildings.fetchBuildingsByUserId = vi.fn().mockResolvedValue([]);
const messageErrorSpy = vi.spyOn(message, 'error');
await addBuilding('', '', '', '', '', 0, 0, [1, 2], user, setShow, dispatch);
expect(api.buildings.addBuilding).toHaveBeenCalled();
expect(api.buildings.fetchBuildings).toHaveBeenCalled();
expect(api.buildings.fetchBuildingsByUserId).toHaveBeenCalled();
expect(setShow).toHaveBeenCalledWith(true);
expect(messageErrorSpy).toHaveBeenCalledWith('Fill the form to submit a building');
});
Expand Down

0 comments on commit 0690bb3

Please sign in to comment.