From 3a21abd4bb1de815e77941571710909c7855f6f4 Mon Sep 17 00:00:00 2001 From: ISA Date: Wed, 5 Mar 2025 09:48:02 +0100 Subject: [PATCH] Test Datei entfernt --- components/MapComponent.js | 9 ++- config/appVersion.js | 2 +- hooks/useFetchUserRights.js | 14 +--- pages/api/gisStationsMeasurements.test.js | 81 ------------------- pages/api/gisStationsStaticDistrict.test.js | 80 ------------------ pages/api/gisStationsStatusDistrict.test.js | 75 ----------------- pages/api/gisSystemStatic.test.js | 81 ------------------- pages/api/linesColorApi.js | 64 --------------- services/{ => api}/checkInternet.js | 0 services/{ => api}/fetchDeviceNameById.js | 0 .../{ => api}/fetchGisStationsMeasurements.js | 0 .../fetchGisStationsStaticDistrict.js | 0 .../fetchGisStationsStatusDistrict.js | 0 services/{ => api}/fetchGisStatusStations.js | 0 services/{ => api}/fetchGisSystemStatic.js | 0 services/{ => api}/fetchPoiData.js | 0 services/{ => api}/fetchUserRights.js | 0 services/{ => api}/fetchWithTimeout.js | 0 .../{ => api}/updateLocationInDatabase.js | 0 utils/setupPOIs.js | 2 +- 20 files changed, 12 insertions(+), 396 deletions(-) delete mode 100644 pages/api/gisStationsMeasurements.test.js delete mode 100644 pages/api/gisStationsStaticDistrict.test.js delete mode 100644 pages/api/gisStationsStatusDistrict.test.js delete mode 100644 pages/api/gisSystemStatic.test.js delete mode 100644 pages/api/linesColorApi.js rename services/{ => api}/checkInternet.js (100%) rename services/{ => api}/fetchDeviceNameById.js (100%) rename services/{ => api}/fetchGisStationsMeasurements.js (100%) rename services/{ => api}/fetchGisStationsStaticDistrict.js (100%) rename services/{ => api}/fetchGisStationsStatusDistrict.js (100%) rename services/{ => api}/fetchGisStatusStations.js (100%) rename services/{ => api}/fetchGisSystemStatic.js (100%) rename services/{ => api}/fetchPoiData.js (100%) rename services/{ => api}/fetchUserRights.js (100%) rename services/{ => api}/fetchWithTimeout.js (100%) rename services/{ => api}/updateLocationInDatabase.js (100%) diff --git a/components/MapComponent.js b/components/MapComponent.js index 708c8e898..86443cddc 100644 --- a/components/MapComponent.js +++ b/components/MapComponent.js @@ -17,7 +17,6 @@ import { ToastContainer, toast } from "react-toastify"; import plusRoundIcon from "./PlusRoundIcon.js"; import { createAndSetDevices } from "../utils/createAndSetDevices.js"; import { restoreMapSettings, checkOverlappingMarkers } from "../utils/mapUtils.js"; -import { fetchPoiData, fetchUserRights } from "../services/apiService.js"; import { APP_VERSION } from "../config/appVersion"; import * as layers from "../config/layers.js"; import { initializeMap } from "../utils/initializeMap.js"; @@ -25,7 +24,6 @@ import addItemsToMapContextMenu from "./useMapContextMenu.js"; import useGmaMarkersLayer from "../hooks/layers/useGmaMarkersLayer.js"; // Import the custom hook import useSmsfunkmodemMarkersLayer from "../hooks/layers/useSmsfunkmodemMarkersLayer.js"; import useBereicheMarkersLayer from "../hooks/layers/useBereicheMarkersLayer.js"; -import { fetchGisStationsStaticDistrict, fetchGisStationsStatusDistrict, fetchGisStationsMeasurements, fetchGisSystemStatic } from "../services/fetchData.js"; import { setupPolylines } from "../utils/setupPolylines.js"; import { setupPOIs } from "../utils/setupPOIs.js"; import VersionInfoModal from "./VersionInfoModal.js"; @@ -60,6 +58,13 @@ import { selectCurrentPoi, setCurrentPoi, clearCurrentPoi } from "../redux/slice import CoordinateInput from "./CoordinateInput"; import CoordinateModal from "./CoordinateModal"; import CoordinatePopup from "./CoordinatePopup"; +//------------------------Daten aus API-------------------- +import { fetchUserRights } from "../services/api/fetchUserRights.js"; +import { fetchPoiData } from "../services/api/fetchPoiData.js"; +import { fetchGisStationsStaticDistrict } from "../services/api/fetchGisStationsStaticDistrict.js"; +import { fetchGisStationsStatusDistrict } from "../services/api/fetchGisStationsStatusDistrict.js"; +import { fetchGisStationsMeasurements } from "../services/api/fetchGisStationsMeasurements.js"; +import { fetchGisSystemStatic } from "../services/api/fetchGisSystemStatic.js"; const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { const dispatch = useDispatch(); diff --git a/config/appVersion.js b/config/appVersion.js index 49cc696f5..b85b6ac37 100644 --- a/config/appVersion.js +++ b/config/appVersion.js @@ -1,2 +1,2 @@ // /config/appVersion -export const APP_VERSION = "1.1.4"; +export const APP_VERSION = "1.1.5"; diff --git a/hooks/useFetchUserRights.js b/hooks/useFetchUserRights.js index 44cc43004..67a09aa7f 100644 --- a/hooks/useFetchUserRights.js +++ b/hooks/useFetchUserRights.js @@ -1,11 +1,7 @@ import { useEffect } from "react"; -import { fetchUserRights } from "../services/apiService"; +import { fetchUserRights } from "../services/api/fetchUserRights.js"; -export const useFetchUserRights = ( - setUserRights, - setIsRightsLoaded, - setHasRights -) => { +export const useFetchUserRights = (setUserRights, setIsRightsLoaded, setHasRights) => { useEffect(() => { const fetchAndSetUserRights = async () => { try { @@ -14,11 +10,7 @@ export const useFetchUserRights = ( setIsRightsLoaded(true); // Sicherstellen, dass `rights` ein Array ist, bevor `.includes()` aufgerufen wird - setHasRights( - localStorage.getItem("editMode") && - Array.isArray(rights) && - rights.includes(56) - ); + setHasRights(localStorage.getItem("editMode") && Array.isArray(rights) && rights.includes(56)); } catch (error) { console.error("Fehler beim Abrufen der Benutzerrechte:", error); } diff --git a/pages/api/gisStationsMeasurements.test.js b/pages/api/gisStationsMeasurements.test.js deleted file mode 100644 index a876dc24c..000000000 --- a/pages/api/gisStationsMeasurements.test.js +++ /dev/null @@ -1,81 +0,0 @@ -import axios from "axios"; -import os from "os"; // Modul zum Ermitteln der IP-Adresse - -// 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 - it("gibt JSON-Daten zurück, wenn gültige Parameter übergeben werden", async () => { - const params = { - m: "12", // Beispiel für idMap - }; - - // Echte Anfrage an den Server senden - const response = await axios.get(BASE_URL, { params }); - - // Debugging der Header - console.log(response.headers); - - // Statuscode prüfen - expect(response.status).toBe(200); - - // Überprüfen, ob die Antwort die erwarteten JSON-Daten enthält - expect(response.data).toHaveProperty("Name"); - expect(response.data).toHaveProperty("Zeitstempel"); - expect(response.data).toHaveProperty("IdMap"); - expect(response.data).toHaveProperty("Statis"); - expect(response.data.Statis).toBeInstanceOf(Array); - - const item = response.data.Statis[0]; - expect(item).toHaveProperty("IdLD"); - expect(item).toHaveProperty("IdL"); - expect(item).toHaveProperty("IdDP"); - expect(item).toHaveProperty("Na"); - expect(item).toHaveProperty("Val"); - expect(item).toHaveProperty("Unit"); - expect(item).toHaveProperty("Gr"); - expect(item).toHaveProperty("Area_Name"); - }); - - // Test 2: Fehler bei fehlenden Parametern - it("gibt einen Fehler zurück, wenn Parameter fehlen", async () => { - try { - // Anfrage ohne Parameter - await axios.get(BASE_URL); - } catch (error) { - expect(error.response.status).toBe(400); - expect(error.response.data).toHaveProperty("error"); - - // Flexibler auf Fehlernachricht prüfen - expect(error.response.data.message).toMatch(/Fehlender Parameter|erforderlich/); - } - }); - - // 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", // Ungültige idMap - }; - - await axios.get(BASE_URL, { params }); - } catch (error) { - expect(error.response.status).toBe(500); - expect(error.response.data).toHaveProperty("error"); - } - }); -}); diff --git a/pages/api/gisStationsStaticDistrict.test.js b/pages/api/gisStationsStaticDistrict.test.js deleted file mode 100644 index 5ec512ae7..000000000 --- a/pages/api/gisStationsStaticDistrict.test.js +++ /dev/null @@ -1,80 +0,0 @@ -import axios from "axios"; -import os from "os"; // Modul zum Ermitteln der IP-Adresse - -// 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 - it("gibt JSON-Daten zurück, wenn gültige Parameter übergeben werden", async () => { - const params = { - 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 }); - - // Debugging der Header - console.log(response.headers); - - // Statuscode prüfen - expect(response.status).toBe(200); - - // Überprüfen, ob die Antwort die erwarteten Daten enthält - expect(response.data).toHaveProperty("Name"); - expect(response.data).toHaveProperty("Points"); - expect(response.data.Points).toBeInstanceOf(Array); - - const item = response.data.Points[0]; - expect(item).toHaveProperty("LD_Name"); - expect(item).toHaveProperty("Device"); - expect(item).toHaveProperty("Link"); - expect(item).toHaveProperty("Location_Name"); - expect(item).toHaveProperty("X"); - expect(item).toHaveProperty("Y"); - expect(item).toHaveProperty("Icon"); - }); - - // Test 2: Fehler bei fehlenden Parametern - it("gibt einen Fehler zurück, wenn Parameter fehlen", async () => { - try { - // Anfrage ohne Parameter - await axios.get(BASE_URL); - } catch (error) { - expect(error.response.status).toBe(400); - expect(error.response.data).toHaveProperty("error"); - - // Flexibler auf Fehlernachricht prüfen - expect(error.response.data.message).toMatch(/Fehlende Parameter|erforderlich/); - } - }); - - // 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", // Ungültige idMap - u: "invalid", // Ungültige idUser - }; - - await axios.get(BASE_URL, { params }); - } catch (error) { - expect(error.response.status).toBe(500); - expect(error.response.data).toHaveProperty("error"); - } - }); -}); diff --git a/pages/api/gisStationsStatusDistrict.test.js b/pages/api/gisStationsStatusDistrict.test.js deleted file mode 100644 index 3d4505054..000000000 --- a/pages/api/gisStationsStatusDistrict.test.js +++ /dev/null @@ -1,75 +0,0 @@ -import axios from "axios"; -import os from "os"; // Modul zum Ermitteln der IP-Adresse - -// 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/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", // Beispiel für idMap - u: "484", // Beispiel für idUser - }; - - // Echte Anfrage an den Server senden - const response = await axios.get(BASE_URL, { params }); - - // Statuscode prüfen - expect(response.status).toBe(200); - - // Antwortdaten prüfen - expect(response.data).toHaveProperty("Name"); - expect(response.data).toHaveProperty("Statis"); - expect(response.data.Statis).toBeInstanceOf(Array); - - const item = response.data.Statis[0]; - expect(item).toHaveProperty("IdLD"); - expect(item).toHaveProperty("Na"); - expect(item).toHaveProperty("Le"); - expect(item).toHaveProperty("Co"); - expect(item).toHaveProperty("Me"); - expect(item).toHaveProperty("Feld"); - expect(item).toHaveProperty("Icon"); - }); - - // Test 2: Fehler bei fehlenden Parametern - it("gibt einen Fehler zurück, wenn Parameter fehlen", async () => { - try { - // Anfrage ohne Parameter - await axios.get(BASE_URL); - } catch (error) { - expect(error.response.status).toBe(400); - expect(error.response.data).toHaveProperty("error"); - expect(error.response.data).toHaveProperty("message"); - } - }); - - // 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", // Ungültige idMap - u: "invalid", // Ungültige idUser - }; - - await axios.get(BASE_URL, { params }); - } catch (error) { - expect(error.response.status).toBe(500); - expect(error.response.data).toHaveProperty("error"); - } - }); -}); diff --git a/pages/api/gisSystemStatic.test.js b/pages/api/gisSystemStatic.test.js deleted file mode 100644 index 539dc80b7..000000000 --- a/pages/api/gisSystemStatic.test.js +++ /dev/null @@ -1,81 +0,0 @@ -import axios from "axios"; -import os from "os"; - -// 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 () => { - const params = { - 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 }); - - // Header sicher loggen - console.log("Content-Type:", response.headers["content-type"]); - - // Statuscode prüfen - expect(response.status).toBe(200); - - // Überprüfen, ob die Antwort die erwarteten JSON-Daten enthält - expect(response.data).toHaveProperty("Name"); - expect(response.data).toHaveProperty("Zeitstempel"); - expect(response.data).toHaveProperty("IdMap"); - expect(response.data).toHaveProperty("Systems"); - expect(response.data.Systems).toBeInstanceOf(Array); - - // Erster Eintrag prüfen - const item = response.data.Systems[0]; - expect(item).toHaveProperty("IdSystem"); - expect(item).toHaveProperty("Name"); - expect(item).toHaveProperty("Longname"); - expect(item).toHaveProperty("Allow"); - expect(item).toHaveProperty("Icon"); - }); - - // Test 2: Fehler bei fehlenden Parametern - it("gibt einen Fehler zurück, wenn Parameter fehlen", async () => { - try { - // Anfrage ohne Parameter - await axios.get(BASE_URL); - } catch (error) { - expect(error.response.status).toBe(400); - expect(error.response.data).toHaveProperty("error"); - - // Flexibler auf Fehlernachricht prüfen - expect(error.response.data.message).toMatch(/Fehlende Parameter|erforderlich/); - } - }); - - // 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", // Ungültige idMap - u: "invalid", // Ungültige idUser - }; - - await axios.get(BASE_URL, { params }); - } catch (error) { - expect(error.response.status).toBe(500); - expect(error.response.data).toHaveProperty("error"); - } - }); -}); diff --git a/pages/api/linesColorApi.js b/pages/api/linesColorApi.js deleted file mode 100644 index 57ee59262..000000000 --- a/pages/api/linesColorApi.js +++ /dev/null @@ -1,64 +0,0 @@ -// /pages/api/linesColorApi.js -// http://10.10.0.13/talas5/ClientData/WebServiceMap.asmx/GisStationsStatusDistrict -//In DB gis_lines idLD und idModul anpassen entsprechend - -// /pages/api/linesColorApi.js -import NextCors from "nextjs-cors"; - -export default async function handler(req, res) { - // Run the cors middleware - await NextCors(req, res, { - // Options - methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"], - origin: "*", // Erlauben Sie alle Ursprünge, oder geben Sie spezifische Ursprünge an - optionsSuccessStatus: 200, // Legacy-Browser-Unterstützung für 204 - }); - - const response = { - Name: "Liste aller Statis der Linien", - Zeitstempel: new Date().toISOString(), // Aktuellen Zeitstempel hinzufügen - IdMap: "10", - Statis: [ - /* { - IdLD: 50922, - Modul: 1, - DpName: "KUE01_Ausfall", - ModulName: "42 Wippershain Sender", - // ModulTyp: "nicht vorhanden", - ModulTyp: "KÜ705-FO", - Message: "KUEG 01: 42 Wippershain Sender Messwerkausfall kommend", - Level: 4, - PrioColor: "#FFFF00", - PrioName: "system", - Value: "10 MOhm", - }, - { - IdLD: 25440, - Modul: 3, - DpName: "KUE03_Ausfall", - ModulName: "42 Solz Sender", - //ModulTyp: "nicht vorhanden", - ModulTyp: "KÜSS V2", - Message: "KUEG 03: 42 Solz Sender Messwerkausfall kommend", - Level: 4, - PrioColor: "#FF0000", - PrioName: "system", - Value: "10 MOhm", - }, - { - IdLD: 25440, - Modul: 4, - DpName: "KUE04_Ausfall", - ModulName: "42/13 Bad Hersfeld Gaswerk", - ModulTyp: "Kue705-FO", - Message: "KUEG 04: 42/13 Bad Hersfeld Gaswerk Messwerkausfall kommend", - Level: 4, - PrioColor: "#FF00FF", - PrioName: "system", - Value: "10 MOhm", - }, */ - ], - }; - - res.status(200).json(response); -} diff --git a/services/checkInternet.js b/services/api/checkInternet.js similarity index 100% rename from services/checkInternet.js rename to services/api/checkInternet.js diff --git a/services/fetchDeviceNameById.js b/services/api/fetchDeviceNameById.js similarity index 100% rename from services/fetchDeviceNameById.js rename to services/api/fetchDeviceNameById.js diff --git a/services/fetchGisStationsMeasurements.js b/services/api/fetchGisStationsMeasurements.js similarity index 100% rename from services/fetchGisStationsMeasurements.js rename to services/api/fetchGisStationsMeasurements.js diff --git a/services/fetchGisStationsStaticDistrict.js b/services/api/fetchGisStationsStaticDistrict.js similarity index 100% rename from services/fetchGisStationsStaticDistrict.js rename to services/api/fetchGisStationsStaticDistrict.js diff --git a/services/fetchGisStationsStatusDistrict.js b/services/api/fetchGisStationsStatusDistrict.js similarity index 100% rename from services/fetchGisStationsStatusDistrict.js rename to services/api/fetchGisStationsStatusDistrict.js diff --git a/services/fetchGisStatusStations.js b/services/api/fetchGisStatusStations.js similarity index 100% rename from services/fetchGisStatusStations.js rename to services/api/fetchGisStatusStations.js diff --git a/services/fetchGisSystemStatic.js b/services/api/fetchGisSystemStatic.js similarity index 100% rename from services/fetchGisSystemStatic.js rename to services/api/fetchGisSystemStatic.js diff --git a/services/fetchPoiData.js b/services/api/fetchPoiData.js similarity index 100% rename from services/fetchPoiData.js rename to services/api/fetchPoiData.js diff --git a/services/fetchUserRights.js b/services/api/fetchUserRights.js similarity index 100% rename from services/fetchUserRights.js rename to services/api/fetchUserRights.js diff --git a/services/fetchWithTimeout.js b/services/api/fetchWithTimeout.js similarity index 100% rename from services/fetchWithTimeout.js rename to services/api/fetchWithTimeout.js diff --git a/services/updateLocationInDatabase.js b/services/api/updateLocationInDatabase.js similarity index 100% rename from services/updateLocationInDatabase.js rename to services/api/updateLocationInDatabase.js diff --git a/utils/setupPOIs.js b/utils/setupPOIs.js index 7abc7c945..b4885bbfc 100644 --- a/utils/setupPOIs.js +++ b/utils/setupPOIs.js @@ -1,7 +1,7 @@ // utils/setupPOIs.js import { findClosestPoints } from "./geometryUtils"; import handlePoiSelect from "./handlePoiSelect"; -import { updateLocationInDatabase } from "../services/apiService"; +import { updateLocationInDatabase } from "../services/api/updateLocationInDatabase"; import { handleEditPoi, insertNewPOI, removePOI } from "./poiUtils"; import { parsePoint } from "./geometryUtils"; import circleIcon from "../components/gisPolylines/icons/CircleIcon";