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:
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");
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user