Skip to content

MPP-4282: (bugfix) Removed Hardcoded Domain in PROD #5730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/apiMocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export function getHandlers(
});

handlers.push(
http.post("https://basket-mock.com/news/subscribe/", (_info) => {
http.post("http://localhost/mock/news/subscribe", (_info) => {
return HttpResponse.json({ status: "ok" }, { status: 200 });
}),
);
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/apiMocks/initialise.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { initialiseWorker } from "./browser";
import { initialiseServer } from "./server";

export async function initialiseApiMocks() {
if (typeof window === "undefined") {
const { initialiseServer } = await import("./server");
const server = initialiseServer();
await server.listen();
} else {
const { initialiseWorker } = await import("./browser");
const worker = initialiseWorker();
await worker.start({
// This custom handler supresses the default warnings about not mocking expected requests:
// This custom handler suppresses the default warnings about not mocking expected requests:
onUnhandledRequest: (req, print) => {
const requestUrl = new URL(req.url);
if (
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/apiMocks/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export const mockIds = ["demo", "empty", "onboarding", "some", "full"] as const;

// This is the same for all mock users, at this time:
export const mockedRuntimeData: RuntimeData = {
FXA_ORIGIN: "https://fxa-mock.com",
BASKET_ORIGIN: "https://basket-mock.com",
// not sure if this is the mock url we want to use
FXA_ORIGIN: "http://localhost/mock/fxa",
BASKET_ORIGIN: "http://localhost/mock/basket",
GOOGLE_ANALYTICS_ID: "UA-123456789-0",
GA4_MEASUREMENT_ID: "G-YXT33S87LT",
PERIODICAL_PREMIUM_PRODUCT_ID: "prod_123456789",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RelayNumberPicker } from "../onboarding/RelayNumberPicker";
import { OverlayProvider } from "react-aria";
import { useL10n } from "../../../hooks/l10n";
import * as relayNumberHooks from "../../../hooks/api/relayNumber";
import { formatPhone } from "../../../functions/formatPhone";

jest.mock("../../../hooks/l10n", () => ({
useL10n: jest.fn(),
Expand Down Expand Up @@ -165,7 +166,8 @@ describe("RelayNumberPicker", () => {
expect(relayNumberHooks.search).toHaveBeenCalledWith("999");
});

const label = screen.getByLabelText("(999) 888 - 7777");
const formatted = formatPhone("+19998887777");
const label = await screen.findByLabelText(formatted);
expect(label).toBeInTheDocument();
});

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/functions/getPlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe("Megabundle Tests", () => {
);

const expectedLink =
"https://fxa-mock.com/subscriptions/products/prod_123456789?plan=price_1RMAopKb9q6OnNsLSGe1vLtt";
"http://localhost/mock/fxa/subscriptions/products/prod_123456789?plan=price_1RMAopKb9q6OnNsLSGe1vLtt";

expect(link).toBe(expectedLink);
});
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/pages/_app.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import ReactGa from "react-ga";
import { getL10n } from "../functions/getL10n";
import { AddonDataContext, useAddonElementWatcher } from "../hooks/addon";
import { ReactAriaI18nProvider } from "../components/ReactAriaI18nProvider";
import { initialiseApiMocks } from "../apiMocks/initialise";
import { mockIds } from "../apiMocks/mockData";
import { useIsLoggedIn } from "../hooks/session";
import { useMetrics } from "../hooks/metrics";
import {
Expand Down Expand Up @@ -60,6 +58,9 @@ function MyApp({ Component, pageProps }: AppProps) {
return;
}
(async () => {
const { initialiseApiMocks } = await import("../apiMocks/initialise");
const { mockIds } = await import("../apiMocks/mockData");

await initialiseApiMocks();

if (
Expand Down
18 changes: 10 additions & 8 deletions frontend/src/pages/mock/login.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import styles from "./mockSession.module.scss";
import { getRuntimeConfig } from "../../config";
import { apiFetch } from "../../hooks/api/api";
import { UsersData } from "../../hooks/api/user";
import { mockIds } from "../../apiMocks/mockData";

type UsedToken = {
token: string;
Expand All @@ -20,15 +19,18 @@ const MockLogin: NextPage = () => {

useEffect(() => {
if (process.env.NEXT_PUBLIC_MOCK_API === "true") {
// When the API is mocked out, the API tokens are fake as well:
const mockIdsAsTokens: UsedToken[] = mockIds.map((id) => ({
lastUsed: 0,
token: id,
user: `${id}@example.com`,
}));
setUsedTokens(mockIdsAsTokens);
(async () => {
const { mockIds } = await import("../../apiMocks/mockData");
const mockIdsAsTokens: UsedToken[] = mockIds.map((id) => ({
lastUsed: 0,
token: id,
user: `${id}@example.com`,
}));
setUsedTokens(mockIdsAsTokens);
})();
return;
}

const usedTokensString = localStorage.getItem("usedTokens") ?? "[]";
setUsedTokens(JSON.parse(usedTokensString).sort(byUseDate));
}, []);
Expand Down