mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2024-12-03 20:27:09 +00:00
add test-utils getApiBaseUrl()
method
This commit is contained in:
parent
17d44dd125
commit
f474ec0b6b
@ -1,10 +1,11 @@
|
|||||||
import type { TitleStatsResponse } from "#app/@types/PokerogueApi";
|
import type { TitleStatsResponse } from "#app/@types/PokerogueApi";
|
||||||
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
||||||
|
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
||||||
import { http, HttpResponse } from "msw";
|
import { http, HttpResponse } from "msw";
|
||||||
import { setupServer } from "msw/node";
|
import { setupServer } from "msw/node";
|
||||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
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();
|
const server = setupServer();
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
@ -84,7 +85,6 @@ describe("Pokerogue API", () => {
|
|||||||
expect(success).toBe(true);
|
expect(success).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("should return false and report a warning on FAILURE", async () => {
|
it("should return false and report a warning on FAILURE", async () => {
|
||||||
server.use(http.post(`${apiBase}/auth/google/logout`, () => new HttpResponse("", { status: 401 })));
|
server.use(http.post(`${apiBase}/auth/google/logout`, () => new HttpResponse("", { status: 401 })));
|
||||||
|
|
||||||
|
@ -21,3 +21,11 @@ export function mockI18next() {
|
|||||||
export function arrayOfRange(start: integer, end: integer) {
|
export function arrayOfRange(start: integer, end: integer) {
|
||||||
return Array.from({ length: end - start }, (_v, k) => k + start);
|
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";
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user