diff --git a/pages/api/gisStationsMeasurements.test.js b/pages/api/gisStationsMeasurements.test.js index cbe30cbda..a876dc24c 100644 --- a/pages/api/gisStationsMeasurements.test.js +++ b/pages/api/gisStationsMeasurements.test.js @@ -1,7 +1,21 @@ import axios from "axios"; +import os from "os"; // Modul zum Ermitteln der IP-Adresse -// Basis-URL des Servers -const BASE_URL = "http://10.10.0.70:3000/api/gisStationsMeasurements"; +// Dynamische Ermittlung der IP-Adresse des Rechners +function getLocalIPAddress() { + const interfaces = os.networkInterfaces(); + for (const name of Object.keys(interfaces)) { + for (const iface of interfaces[name]) { + if (iface.family === "IPv4" && !iface.internal) { + return iface.address; // Rückgabe der IPv4-Adresse + } + } + } + return "localhost"; // Fallback zu localhost +} + +// Basis-URL dynamisch erstellen +const BASE_URL = `http://${getLocalIPAddress()}:3000/api/gisStationsMeasurements`; describe("Echte API-Integrationstests für gisStationsMeasurements", () => { // Test 1: Erfolgreiche Anfrage mit gültigen Parametern diff --git a/pages/api/gisStationsStaticDistrict.test.js b/pages/api/gisStationsStaticDistrict.test.js index 912c02688..5ec512ae7 100644 --- a/pages/api/gisStationsStaticDistrict.test.js +++ b/pages/api/gisStationsStaticDistrict.test.js @@ -1,7 +1,21 @@ import axios from "axios"; +import os from "os"; // Modul zum Ermitteln der IP-Adresse -// Basis-URL des Servers -const BASE_URL = "http://10.10.0.70:3000/api/gisStationsStaticDistrict"; +// Dynamische Ermittlung der IP-Adresse des Rechners +function getLocalIPAddress() { + const interfaces = os.networkInterfaces(); + for (const name of Object.keys(interfaces)) { + for (const iface of interfaces[name]) { + if (iface.family === "IPv4" && !iface.internal) { + return iface.address; // Rückgabe der IPv4-Adresse + } + } + } + return "localhost"; // Fallback zu localhost +} + +// Basis-URL dynamisch erstellen +const BASE_URL = `http://${getLocalIPAddress()}:3000/api/gisStationsStaticDistrict`; describe("Echte API-Integrationstests für gisStationsStaticDistrict", () => { // Test 1: Erfolgreiche Anfrage mit gültigen Parametern diff --git a/pages/api/gisStationsStatusDistrict.test.js b/pages/api/gisStationsStatusDistrict.test.js index 08a7eeef0..3d4505054 100644 --- a/pages/api/gisStationsStatusDistrict.test.js +++ b/pages/api/gisStationsStatusDistrict.test.js @@ -1,19 +1,34 @@ import axios from "axios"; +import os from "os"; // Modul zum Ermitteln der IP-Adresse -// Basis-URL des Servers -const BASE_URL = "http://10.10.0.70:3000/api/gisStationsStatusDistrict"; +// Dynamische Ermittlung der IP-Adresse des Rechners +function getLocalIPAddress() { + const interfaces = os.networkInterfaces(); + for (const name of Object.keys(interfaces)) { + for (const iface of interfaces[name]) { + if (iface.family === "IPv4" && !iface.internal) { + return iface.address; // Rückgabe der IPv4-Adresse + } + } + } + return "localhost"; // Fallback zu localhost +} -describe("Echte API-Integrationstests", () => { +// Basis-URL dynamisch erstellen +const BASE_URL = `http://${getLocalIPAddress()}:3000/api/gisStationsStatusDistrict`; + +describe("Echte API-Integrationstests für gisStationsStatusDistrict", () => { + // Test 1: Erfolgreiche Anfrage mit gültigen Parametern it("gibt JSON-Daten zurück, wenn gültige Parameter übergeben werden", async () => { const params = { - m: "12", - u: "484", + m: "12", // Beispiel für idMap + u: "484", // Beispiel für idUser }; // Echte Anfrage an den Server senden const response = await axios.get(BASE_URL, { params }); - // Antwortstatus prüfen + // Statuscode prüfen expect(response.status).toBe(200); // Antwortdaten prüfen @@ -31,6 +46,7 @@ describe("Echte API-Integrationstests", () => { expect(item).toHaveProperty("Icon"); }); + // Test 2: Fehler bei fehlenden Parametern it("gibt einen Fehler zurück, wenn Parameter fehlen", async () => { try { // Anfrage ohne Parameter @@ -42,11 +58,12 @@ describe("Echte API-Integrationstests", () => { } }); + // Test 3: Fehler bei ungültigen Parametern it("gibt einen Serverfehler zurück, wenn ungültige Parameter verwendet werden", async () => { try { const params = { - m: "invalid", - u: "invalid", + m: "invalid", // Ungültige idMap + u: "invalid", // Ungültige idUser }; await axios.get(BASE_URL, { params }); diff --git a/pages/api/gisSystemStatic.test.js b/pages/api/gisSystemStatic.test.js index 3a8169b18..539dc80b7 100644 --- a/pages/api/gisSystemStatic.test.js +++ b/pages/api/gisSystemStatic.test.js @@ -1,8 +1,22 @@ import axios from "axios"; +import os from "os"; -// Basis-URL des Servers -const BASE_URL = "http://10.10.0.70:3000/api/gisSystemStatic"; +// Dynamische IP-Adresse ermitteln +function getLocalIPAddress() { + const interfaces = os.networkInterfaces(); + for (const name of Object.keys(interfaces)) { + for (const iface of interfaces[name]) { + if (iface.family === "IPv4" && !iface.internal) { + return iface.address; // IPv4-Adresse zurückgeben + } + } + } + return "localhost"; // Fallback zu localhost +} +// Dynamische Basis-URL +const BASE_URL = `http://${getLocalIPAddress()}:3000/api/gisSystemStatic`; +//http://localhost:3000/api/gisSystemStatic describe("Echte API-Integrationstests für gisSystemStatic", () => { // Test 1: Erfolgreiche Anfrage mit gültigen Parametern it("gibt JSON-Daten zurück, wenn gültige Parameter übergeben werden", async () => { @@ -14,8 +28,8 @@ describe("Echte API-Integrationstests für gisSystemStatic", () => { // Echte Anfrage an den Server senden const response = await axios.get(BASE_URL, { params }); - // Debugging der Header - console.log(response.headers); + // Header sicher loggen + console.log("Content-Type:", response.headers["content-type"]); // Statuscode prüfen expect(response.status).toBe(200); diff --git a/reports/junit/junit.xml b/reports/junit/junit.xml index 0d3e866e3..ed984f867 100644 --- a/reports/junit/junit.xml +++ b/reports/junit/junit.xml @@ -1,35 +1,35 @@ - - - + + + - + - + - - + + - + - + - - + + - + - + - - + + - + - + \ No newline at end of file