Skip to content

Commit

Permalink
remove need for localhost hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Essential Randomness committed Dec 26, 2023
1 parent baaa1f5 commit 295568c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
3 changes: 2 additions & 1 deletion src/lib/api/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AxiosRequestConfig, AxiosResponse } from "axios";

import axios from "axios";
import { getServerBaseUrl } from "lib/location";

export type RequestConfig<TVariables = unknown> = {
method: "get" | "put" | "patch" | "post" | "delete";
Expand All @@ -21,7 +22,7 @@ export type RequestConfig<TVariables = unknown> = {
export type ResponseConfig<TData> = AxiosResponse<TData>;

export const axiosInstance = axios.create({
baseURL: "http://localhost:4200",
baseURL: getServerBaseUrl(),
// headers: '{}' ? JSON.parse('{}') : {},
});

Expand Down
3 changes: 2 additions & 1 deletion src/lib/api/generated/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AxiosRequestConfig, AxiosResponse } from "axios";

import axios from "axios";
import { getServerBaseUrl } from "lib/location";

export type RequestConfig<TVariables = unknown> = {
method: "get" | "put" | "patch" | "post" | "delete";
Expand All @@ -21,7 +22,7 @@ export type RequestConfig<TVariables = unknown> = {
export type ResponseConfig<TData> = AxiosResponse<TData>;

export const axiosInstance = axios.create({
baseURL: "http://localhost:4200",
baseURL: getServerBaseUrl(),
// headers: '{}' ? JSON.parse('{}') : {},
});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/hooks/board-feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const useReadBoardFeed = (args: { boardSlug: string }) => {
React.useEffect(() => {
if (!isPending && isLoggedIn && boardActivityFetched && boardId) {
log(`Marking board ${boardId} as visited`);
axios.post(`http://localhost:4200/boards/${boardId}/visits`);
axios.post(`/boards/${boardId}/visits`);
}
}, [isPending, isLoggedIn, boardId, boardActivityFetched]);
};
2 changes: 1 addition & 1 deletion src/lib/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const getServerBaseUrl = (context?: NextPageContext) => {
}

if (process.env.NODE_ENV == "test") {
return "http://localhost";
return "http://localhost:3000";
}

// TODO: remove this hardcoding completely and only use the environment variables
Expand Down
2 changes: 2 additions & 0 deletions tests/UI/InvitesPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ describe("InvitesPanel", () => {
).getByDisplayValue(V0_CREATED_INVITE_NO_EMAIL.invite_url)
).toBeVisible();
});

// TODO: figure out why it doesn't return the new post in the next request
// await waitFor(() => {
// expect(
// within(
Expand Down
8 changes: 8 additions & 0 deletions tests/UI/PostOptions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ vi.mock("components/hooks/usePreventPageChange");
vi.mock("components/core/useIsChangingRoute");
vi.mock("components/hooks/useOnPageExit");
vi.spyOn(textExports, "copyText");
vi.mock("lib/api/hooks/board-feed", async () => ({
...(await vi.importActual("lib/api/hooks/board-feed")),
useReadBoardFeed: vi.fn().mockReturnValue(vi.fn()),
}));
vi.mock("lib/api/hooks/thread", async () => ({
...(await vi.importActual("lib/api/hooks/thread")),
useReadThread: vi.fn().mockReturnValue(vi.fn()),
}));

const displaysOptionInPanel = async ({
optionText,
Expand Down
31 changes: 12 additions & 19 deletions tests/server-mocks/boards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ export default [
log("fetching data for gore board");
return HttpResponse.json(BOBATAN_GORE_METADATA);
}),
http.post(
"http://localhost:4200/boards/c6d3d10e-8e49-4d73-b28a-9d652b41beec/visits",
() => {
log("marking gore board as visited");
return new HttpResponse(null, { status: 204 });
}
),
http.post("/boards/c6d3d10e-8e49-4d73-b28a-9d652b41beec/visits", () => {
log("marking gore board as visited");
return new HttpResponse(null, { status: 204 });
}),
http.post("/boards/c6d3d10e-8e49-4d73-b28a-9d652b41beec/mute", () => {
log("marking gore board as muted");

Expand Down Expand Up @@ -92,18 +89,14 @@ export default [

// Now return the created post when the board feed is called again.
server.use(
http.get(
// TODO: figure out why you need :4200 here
"http://localhost:4200/feeds/boards/c6d3d10e-8e49-4d73-b28a-9d652b41beec",
() => {
log("fetching data for gore feed with new post");
const newFeed = {
...GORE_FEED,
activity: [newThread, ...GORE_FEED.activity],
};
return HttpResponse.json(newFeed);
}
)
http.get("/feeds/boards/c6d3d10e-8e49-4d73-b28a-9d652b41beec", () => {
log("fetching data for gore feed with new post");
const newFeed = {
...GORE_FEED,
activity: [newThread, ...GORE_FEED.activity],
};
return HttpResponse.json(newFeed);
})
);
return HttpResponse.json(newThread);
}
Expand Down
11 changes: 4 additions & 7 deletions tests/server-mocks/feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import { http, HttpResponse } from "msw";
const log = debug("bobafrontend:tests:server-mocks:feeds");

export default [
http.get(
"http://localhost:4200/feeds/boards/c6d3d10e-8e49-4d73-b28a-9d652b41beec",
() => {
log("fetching data for gore feed");
return HttpResponse.json(BOBATAN_GORE_FEED);
}
),
http.get("/feeds/boards/c6d3d10e-8e49-4d73-b28a-9d652b41beec", () => {
log("fetching data for gore feed");
return HttpResponse.json(BOBATAN_GORE_FEED);
}),
];

0 comments on commit 295568c

Please sign in to comment.