add test-utils getApiBaseUrl() method

This commit is contained in:
flx-sta 2024-10-07 11:49:16 -07:00
parent 17d44dd125
commit f474ec0b6b
2 changed files with 10 additions and 2 deletions

View File

@ -1,10 +1,11 @@
import type { TitleStatsResponse } from "#app/@types/PokerogueApi";
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
import { getApiBaseUrl } from "#app/test/utils/testUtils";
import { http, HttpResponse } from "msw";
import { setupServer } from "msw/node";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
const apiBase = import.meta.env.VITE_API_BASE_URL ?? "http://localhost:8001";
const apiBase = getApiBaseUrl();
const server = setupServer();
beforeAll(() => {
@ -84,7 +85,6 @@ describe("Pokerogue API", () => {
expect(success).toBe(true);
});
it("should return false and report a warning on FAILURE", async () => {
server.use(http.post(`${apiBase}/auth/google/logout`, () => new HttpResponse("", { status: 401 })));

View File

@ -21,3 +21,11 @@ export function mockI18next() {
export function arrayOfRange(start: integer, end: integer) {
return Array.from({ length: end - start }, (_v, k) => k + start);
}
/**
* Utility to get the API base URL from the environment variable (or the default/fallback).
* @returns the API base URL
*/
export function getApiBaseUrl() {
return import.meta.env.VITE_SERVER_URL ?? "http://localhost:8001";
}