refactoring-backend #3

Merged
lukas.pupkalipinski merged 403 commits from refactoring-backend into main 2026-05-20 20:23:46 +02:00
2 changed files with 27 additions and 42 deletions
Showing only changes of commit b6303cff72 - Show all commits

View File

@@ -100,20 +100,3 @@ export function useMapData(
};
}
/**
* Test helper: returns arguments most recently used to call `useMapData`.
*
* This helper is only intended for test use with a mock implementation.
*/
export function getLastArgs(): { range: string; origin: string } {
throw new Error("getLastArgs is only available in tests with a mocked useMapData");
}
/**
* Test helper: mutates mocked map data state.
*
* This helper is only intended for test use with a mock implementation.
*/
export function setMapData(_: Partial<UseMapDataResult>): void {
throw new Error("setMapData is only available in tests with a mocked useMapData");
}

View File

@@ -2,35 +2,37 @@ import { describe, expect, it, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { FluentProvider, webLightTheme } from "@fluentui/react-components";
import { getLastArgs, setMapData } from "../../hooks/useMapData";
import { MapPage } from "../MapPage";
import type { UseMapDataResult } from "../../hooks/useMapData";
vi.mock("../../hooks/useMapData", () => {
let lastArgs: { range: string; origin: string } = { range: "", origin: "" };
let dataState = {
countries: {},
countryNames: {},
bans: [],
total: 0,
loading: false,
error: null,
refresh: () => {},
};
let lastArgs: { range: string; origin: string } = { range: "", origin: "" };
let dataState: UseMapDataResult = {
countries: {},
countryNames: {},
bans: [],
total: 0,
loading: false,
error: null,
refresh: () => {},
};
return {
useMapData: (range: string, origin: string) => {
lastArgs = { range, origin };
return { ...dataState };
},
setMapData: (newState: Partial<typeof dataState>) => {
dataState = { ...dataState, ...newState };
},
getLastArgs: () => lastArgs,
};
});
function getLastArgs(): { range: string; origin: string } {
return lastArgs;
}
function setMapData(newState: Partial<typeof dataState>): void {
dataState = { ...dataState, ...newState };
}
vi.mock("../../hooks/useMapData", () => ({
useMapData: (range: string, origin: string) => {
lastArgs = { range, origin };
return { ...dataState };
},
}));
vi.mock("../../api/config", () => ({
fetchMapColorThresholds: vi.fn(async () => ({
fetchMapColorThresholds: vi.fn(() => ({
threshold_low: 10,
threshold_medium: 50,
threshold_high: 100,
@@ -65,7 +67,7 @@ describe("MapPage", () => {
const user = userEvent.setup();
const bans: import("../../types/map").MapBanItem[] = Array.from({ length: 120 }, (_, index) => ({
ip: `192.0.2.${index}`,
ip: "192.0.2." + String(index),
jail: "ssh",
banned_at: new Date(Date.now() - index * 1000).toISOString(),
service: null,