feat: Proxy-APIs und Integrationstests für WebServices hinzugefügt
- Vier Proxy-Endpunkte implementiert: 1. gisStationsStatusDistrict 2. gisStationsStaticDistrict 3. gisStationsMeasurements 4. gisSystemStatic - API-Integrationstests mit Jest für alle Endpunkte erstellt: - Tests verwenden echte API-Responses statt Mock-Daten. - Erfolgreiche Anfragen mit gültigen Parametern getestet. - Fehlende Parameter und ungültige Parameter getestet. - Code enthält: - Dynamische URL-Generierung für Proxy-Weiterleitungen. - Prüfung von Headern, Statuscodes und JSON-Strukturen. - Unterstützung für CORS und OPTIONS-Anfragen. - Ergebnis: - Alle Tests erfolgreich bestanden. - APIs bereit für produktive Nutzung und Erweiterungen.
This commit is contained in:
67
pages/api/gisStationsMeasurements.test.js
Normal file
67
pages/api/gisStationsMeasurements.test.js
Normal file
@@ -0,0 +1,67 @@
|
||||
import axios from "axios";
|
||||
|
||||
// Basis-URL des Servers
|
||||
const BASE_URL = "http://10.10.0.70: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");
|
||||
}
|
||||
});
|
||||
});
|
||||
66
pages/api/gisStationsStaticDistrict.test.js
Normal file
66
pages/api/gisStationsStaticDistrict.test.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import axios from "axios";
|
||||
|
||||
// Basis-URL des Servers
|
||||
const BASE_URL = "http://10.10.0.70: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");
|
||||
}
|
||||
});
|
||||
});
|
||||
58
pages/api/gisStationsStatusDistrict.test.js
Normal file
58
pages/api/gisStationsStatusDistrict.test.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import axios from "axios";
|
||||
|
||||
// Basis-URL des Servers
|
||||
const BASE_URL = "http://10.10.0.70:3000/api/gisStationsStatusDistrict";
|
||||
|
||||
describe("Echte API-Integrationstests", () => {
|
||||
it("gibt JSON-Daten zurück, wenn gültige Parameter übergeben werden", async () => {
|
||||
const params = {
|
||||
m: "12",
|
||||
u: "484",
|
||||
};
|
||||
|
||||
// Echte Anfrage an den Server senden
|
||||
const response = await axios.get(BASE_URL, { params });
|
||||
|
||||
// Antwortstatus 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");
|
||||
});
|
||||
|
||||
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");
|
||||
}
|
||||
});
|
||||
|
||||
it("gibt einen Serverfehler zurück, wenn ungültige Parameter verwendet werden", async () => {
|
||||
try {
|
||||
const params = {
|
||||
m: "invalid",
|
||||
u: "invalid",
|
||||
};
|
||||
|
||||
await axios.get(BASE_URL, { params });
|
||||
} catch (error) {
|
||||
expect(error.response.status).toBe(500);
|
||||
expect(error.response.data).toHaveProperty("error");
|
||||
}
|
||||
});
|
||||
});
|
||||
67
pages/api/gisSystemStatic.test.js
Normal file
67
pages/api/gisSystemStatic.test.js
Normal file
@@ -0,0 +1,67 @@
|
||||
import axios from "axios";
|
||||
|
||||
// Basis-URL des Servers
|
||||
const BASE_URL = "http://10.10.0.70: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 });
|
||||
|
||||
// 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("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");
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user