/** * Test-Script für Backend-APIs * Ruft die Endpoints direkt auf ohne Browser/GUI */ import { handleConfigLoad, handleSteamRefresh } from "../server/steam-api.mjs"; // Mock Request/Response Objekte class MockRequest { constructor(method, url, body = null) { this.method = method; this.url = url; this._body = body; this._listeners = {}; } on(event, callback) { this._listeners[event] = callback; if (event === "data" && this._body) { setTimeout(() => callback(this._body), 0); } if (event === "end") { setTimeout(() => callback(), 0); } } } class MockResponse { constructor() { this.statusCode = 200; this.headers = {}; this._chunks = []; } setHeader(name, value) { this.headers[name] = value; } end(data) { if (data) this._chunks.push(data); const output = this._chunks.join(""); console.log("\n=== RESPONSE ==="); console.log("Status:", this.statusCode); console.log("Headers:", this.headers); console.log("Body:", output); // Parse JSON wenn Content-Type gesetzt ist if (this.headers["Content-Type"] === "application/json") { try { const parsed = JSON.parse(output); console.log("\nParsed JSON:"); console.log(JSON.stringify(parsed, null, 2)); } catch (e) { console.error("JSON Parse Error:", e.message); } } } } // Test 1: Config Load console.log("\n### TEST 1: Config Load ###"); const configReq = new MockRequest("GET", "/api/config/load"); const configRes = new MockResponse(); await handleConfigLoad(configReq, configRes); // Test 2: Steam Refresh (braucht config.local.json) console.log("\n\n### TEST 2: Steam Refresh ###"); const steamBody = JSON.stringify({ apiKey: "78CDB987B47DDBB9C385522E5F6D0A52", steamId: "76561197960313963", }); const steamReq = new MockRequest("POST", "/api/steam/refresh", steamBody); const steamRes = new MockResponse(); await handleSteamRefresh(steamReq, steamRes);