From 71f5093a4997a3d409ceb5d9be5adf35c22a7950 Mon Sep 17 00:00:00 2001 From: Moritz Utcke Date: Tue, 1 Apr 2025 13:49:47 -0300 Subject: [PATCH] Tests --- cypress.config.ts | 8 + src/astro-typesafe-api-caller.ts | 20 +- src/client/lib/nachweisSpeichern.ts | 2 +- .../Ausweis/ButtonWeiterHilfe.svelte | 35 +- src/components/Ausweis/Progressbar.svelte | 4 + src/components/FileGrid.svelte | 10 +- .../GEGNachweis/GEGAusweisart.svelte | 8 +- .../e2e/GEGNachweisGewerbe/erstellen.cy.ts | 191 ++++--- .../e2e/GEGNachweisWohnen/erstellen.cy.ts | 211 ++++---- .../VerbrauchsausweisGewerbe/erstellen.cy.ts | 486 ++++++++--------- .../VerbrauchsausweisWohnen/erstellen.cy.ts | 505 +++++++++--------- src/cypress/support/commands.ts | 17 + src/lib/server/db.ts | 18 +- .../BedarfsausweisGewerbeModule.svelte | 2 +- .../GEGNachweisWohnenModule.svelte | 55 +- .../geg-nachweis-wohnen-anfragen/index.astro | 135 +++-- .../{[uid].ts => [id].ts} | 0 .../{[uid].ts => [id].ts} | 0 src/pages/api/geg-nachweis-gewerbe/index.ts | 36 +- .../geg-nachweis-wohnen/{[uid].ts => [id].ts} | 51 +- src/pages/api/geg-nachweis-wohnen/index.ts | 36 +- src/pages/api/rechnung/anfordern.ts | 13 +- src/pages/pdf/datenblatt.ts | 16 +- 23 files changed, 939 insertions(+), 920 deletions(-) rename src/pages/api/bedarfsausweis-gewerbe/{[uid].ts => [id].ts} (100%) rename src/pages/api/geg-nachweis-gewerbe/{[uid].ts => [id].ts} (100%) rename src/pages/api/geg-nachweis-wohnen/{[uid].ts => [id].ts} (81%) diff --git a/cypress.config.ts b/cypress.config.ts index e6e1c1a1..e11f6b25 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -35,6 +35,14 @@ export default defineConfig({ on("task", { async verbrauchsausweisWohnen(query) { return await prisma.verbrauchsausweisWohnen.findFirst(query) + }, + async plz() { + const total = await prisma.postleitzahlen.count() + const result = await prisma.postleitzahlen.findFirst({ + skip: Math.floor(Math.random() * total) + }) + + return result?.plz } }) }, diff --git a/src/astro-typesafe-api-caller.ts b/src/astro-typesafe-api-caller.ts index 932430d6..91a0bc62 100644 --- a/src/astro-typesafe-api-caller.ts +++ b/src/astro-typesafe-api-caller.ts @@ -13,28 +13,28 @@ export const createCaller = createCallerFactory({ "admin/registriernummer": await import("../src/pages/api/admin/registriernummer.ts"), "admin/stornieren": await import("../src/pages/api/admin/stornieren.ts"), "aufnahme": await import("../src/pages/api/aufnahme/index.ts"), + "bedarfsausweis-gewerbe/[id]": await import("../src/pages/api/bedarfsausweis-gewerbe/[id].ts"), + "bedarfsausweis-gewerbe": await import("../src/pages/api/bedarfsausweis-gewerbe/index.ts"), + "ausweise": await import("../src/pages/api/ausweise/index.ts"), + "bedarfsausweis-wohnen/[id]": await import("../src/pages/api/bedarfsausweis-wohnen/[id].ts"), + "bedarfsausweis-wohnen": await import("../src/pages/api/bedarfsausweis-wohnen/index.ts"), "auth/access-token": await import("../src/pages/api/auth/access-token.ts"), "auth/passwort-vergessen": await import("../src/pages/api/auth/passwort-vergessen.ts"), "auth/refresh-token": await import("../src/pages/api/auth/refresh-token.ts"), - "bedarfsausweis-gewerbe/[uid]": await import("../src/pages/api/bedarfsausweis-gewerbe/[uid].ts"), - "bedarfsausweis-gewerbe": await import("../src/pages/api/bedarfsausweis-gewerbe/index.ts"), - "bedarfsausweis-wohnen/[id]": await import("../src/pages/api/bedarfsausweis-wohnen/[id].ts"), - "bedarfsausweis-wohnen": await import("../src/pages/api/bedarfsausweis-wohnen/index.ts"), - "ausweise": await import("../src/pages/api/ausweise/index.ts"), "bilder/[id]": await import("../src/pages/api/bilder/[id].ts"), - "geg-nachweis-gewerbe/[uid]": await import("../src/pages/api/geg-nachweis-gewerbe/[uid].ts"), - "geg-nachweis-gewerbe": await import("../src/pages/api/geg-nachweis-gewerbe/index.ts"), - "geg-nachweis-wohnen/[uid]": await import("../src/pages/api/geg-nachweis-wohnen/[uid].ts"), + "geg-nachweis-wohnen/[id]": await import("../src/pages/api/geg-nachweis-wohnen/[id].ts"), "geg-nachweis-wohnen": await import("../src/pages/api/geg-nachweis-wohnen/index.ts"), + "geg-nachweis-gewerbe/[id]": await import("../src/pages/api/geg-nachweis-gewerbe/[id].ts"), + "geg-nachweis-gewerbe": await import("../src/pages/api/geg-nachweis-gewerbe/index.ts"), "objekt": await import("../src/pages/api/objekt/index.ts"), "rechnung/[id]": await import("../src/pages/api/rechnung/[id].ts"), "rechnung/anfordern": await import("../src/pages/api/rechnung/anfordern.ts"), "rechnung": await import("../src/pages/api/rechnung/index.ts"), "ticket": await import("../src/pages/api/ticket/index.ts"), - "user": await import("../src/pages/api/user/index.ts"), - "user/self": await import("../src/pages/api/user/self.ts"), "verbrauchsausweis-gewerbe/[id]": await import("../src/pages/api/verbrauchsausweis-gewerbe/[id].ts"), "verbrauchsausweis-gewerbe": await import("../src/pages/api/verbrauchsausweis-gewerbe/index.ts"), + "user": await import("../src/pages/api/user/index.ts"), + "user/self": await import("../src/pages/api/user/self.ts"), "verbrauchsausweis-wohnen/[id]": await import("../src/pages/api/verbrauchsausweis-wohnen/[id].ts"), "verbrauchsausweis-wohnen": await import("../src/pages/api/verbrauchsausweis-wohnen/index.ts"), "webhooks/mollie": await import("../src/pages/api/webhooks/mollie.ts"), diff --git a/src/client/lib/nachweisSpeichern.ts b/src/client/lib/nachweisSpeichern.ts index 8752bece..083839e8 100644 --- a/src/client/lib/nachweisSpeichern.ts +++ b/src/client/lib/nachweisSpeichern.ts @@ -195,7 +195,7 @@ export async function nachweisSpeichern( } else { const { id } = await putRoute.fetch({ nachweis, - uid_aufnahme: aufnahme.id + aufnahme_id: aufnahme.id }, { headers: { "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` diff --git a/src/components/Ausweis/ButtonWeiterHilfe.svelte b/src/components/Ausweis/ButtonWeiterHilfe.svelte index 0049f552..d266ef6d 100644 --- a/src/components/Ausweis/ButtonWeiterHilfe.svelte +++ b/src/components/Ausweis/ButtonWeiterHilfe.svelte @@ -5,12 +5,12 @@ import Overlay from "#components/Overlay.svelte"; import EmbeddedAuthFlowModule from "#modules/EmbeddedAuthFlowModule.svelte"; - import { AusweisTyp, BedarfsausweisGewerbe, Enums } from "#lib/client/prisma.js"; + import { AusweisTyp, BedarfsausweisGewerbe, Enums, GEGNachweisGewerbe, GEGNachweisWohnen } from "#lib/client/prisma.js"; import { openWindowWithPost } from "#lib/helpers/window.js"; import { PRICES } from "#lib/constants.js"; import { nachweisSpeichern } from "#client/lib/nachweisSpeichern.js"; - export let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | BedarfsausweisWohnenClient | BedarfsausweisGewerbe; + export let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | BedarfsausweisWohnenClient | BedarfsausweisGewerbe | GEGNachweisWohnen | GEGNachweisGewerbe; export let bilder: BildClient[]; export let unterlagen: UnterlageClient[] = []; export let user: BenutzerClient | null; @@ -46,16 +46,27 @@ return; } - - openWindowWithPost("/kundendaten", { - ausweis: { ...ausweis, ausweistyp }, - objekt, - aufnahme, - bilder, - unterlagen, - ausweisart, - ausweistyp - }, "") + if (ausweisart === Enums.Ausweisart.GEGNachweisWohnen || ausweisart === Enums.Ausweisart.GEGNachweisGewerbe || ausweisart === Enums.Ausweisart.BedarfsausweisGewerbe) { + openWindowWithPost("/kundendaten", { + ausweis: { ...ausweis, nachweistyp: ausweistyp }, + objekt, + aufnahme, + bilder, + unterlagen, + ausweisart, + ausweistyp + }, "") + } else { + openWindowWithPost("/kundendaten", { + ausweis: { ...ausweis, ausweistyp }, + objekt, + aufnahme, + bilder, + unterlagen, + ausweisart, + ausweistyp + }, "") + } } let loginAction: () => any = ausweisAbschicken; diff --git a/src/components/Ausweis/Progressbar.svelte b/src/components/Ausweis/Progressbar.svelte index 6295fe7a..9dda6504 100644 --- a/src/components/Ausweis/Progressbar.svelte +++ b/src/components/Ausweis/Progressbar.svelte @@ -26,6 +26,10 @@ Bedarfsausweis Wohnen {:else if ausweisart === Enums.Ausweisart.BedarfsausweisGewerbe} Bedarfsausweis Gewerbe + {:else if ausweisart === Enums.Ausweisart.GEGNachweisWohnen} + GEG Nachweis Wohngebäude + {:else if ausweisart === Enums.Ausweisart.GEGNachweisGewerbe} + GEG Nachweis Gewerbegebäude {/if} {#if ausweistyp === Enums.AusweisTyp.Beratung} mit Beratung diff --git a/src/components/FileGrid.svelte b/src/components/FileGrid.svelte index 243dacec..29c25962 100644 --- a/src/components/FileGrid.svelte +++ b/src/components/FileGrid.svelte @@ -4,15 +4,15 @@ import HelpLabel from "#components/labels/HelpLabel.svelte"; export let kategorie: string = ""; - export let files: UnterlageClient[] = []; + export let files: Unterlage[] = []; export let max: number = Infinity; export let min: number = 1; export let name: string = ""; - export let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | BedarfsausweisWohnenClient | BedarfsausweisGewerbe; + export let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | BedarfsausweisWohnenClient | BedarfsausweisGewerbe | GEGNachweisWohnen | GEGNachweisGewerbe; export let objekt: ObjektClient; import mime from "mime-types"; import { api } from "astro-typesafe-api/client"; - import { BedarfsausweisGewerbe } from "#lib/client/prisma.js"; + import { BedarfsausweisGewerbe, GEGNachweisGewerbe, GEGNachweisWohnen, Unterlage } from "#lib/client/prisma.js"; function getAllFiles(this: HTMLInputElement) { @@ -43,14 +43,14 @@ const mimeType = mime.types[file.name.split(".").pop() as string] - const { uid } = await api.unterlage.PUT.fetch({ + const { id } = await api.unterlage.PUT.fetch({ data: reader.result as string, kategorie, mime: mimeType, name: file.name }) - files.push({ uid, kategorie, name: file.name, mime: mimeType }); + files.push({ id, kategorie, name: file.name, mime: mimeType, aufnahme_id: null }); files = files; diff --git a/src/components/GEGNachweis/GEGAusweisart.svelte b/src/components/GEGNachweis/GEGAusweisart.svelte index 0b8e98bc..f6db28d5 100644 --- a/src/components/GEGNachweis/GEGAusweisart.svelte +++ b/src/components/GEGNachweis/GEGAusweisart.svelte @@ -7,7 +7,7 @@ import { auditHeizungGebaeudeBaujahr } from "../Verbrauchsausweis/audits/HeizungGebaeudeBaujahr.js"; import { addNotification, deleteNotification } from "#components/Notifications/shared.js"; import TagInput from "../TagInput.svelte"; - import { BedarfsausweisGewerbe, Enums } from "#lib/client/prisma.js"; + import { BedarfsausweisGewerbe, Enums, GEGNachweisGewerbe, GEGNachweisWohnen } from "#lib/client/prisma.js"; import { AufnahmeClient, ObjektClient, @@ -15,8 +15,8 @@ } from "../Ausweis/types.js"; export let objekt: ObjektClient; - export let ausweis: - BedarfsausweisGewerbe; + export let nachweis: + BedarfsausweisGewerbe | GEGNachweisWohnen | GEGNachweisGewerbe; export let aufnahme: AufnahmeClient; export let ausweisart: Enums.Ausweisart; @@ -38,7 +38,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8 class="rounded-e-none" name="ausstellgrund" placeholder="Anlass" - bind:value={ausweis.ausstellgrund} + bind:value={nachweis.ausstellgrund} required data-cy="ausstellgrund" > diff --git a/src/cypress/e2e/GEGNachweisGewerbe/erstellen.cy.ts b/src/cypress/e2e/GEGNachweisGewerbe/erstellen.cy.ts index ede1ad52..e57261d0 100644 --- a/src/cypress/e2e/GEGNachweisGewerbe/erstellen.cy.ts +++ b/src/cypress/e2e/GEGNachweisGewerbe/erstellen.cy.ts @@ -8,123 +8,116 @@ import moment from "moment"; describe("Verbrauchsausweis erstellen Schritt 1", () => { it("erstellt einen neuen Verbrauchsausweis Wohngebäude.", () => { - cy.visit("/angebot-anfragen/geg-nachweis-gewerbe-anfragen"); + cy.task("plz").then(plz => { + cy.visit("/angebot-anfragen/geg-nachweis-gewerbe-anfragen"); - cy.wait(2000); + cy.wait(2000); - // Wir überprüfen, ob alle Ausstelgründe vorhanden sind, diese sollten genau so viele sein wie in der Datenbank vorhanden sind. - cy.get("select[data-cy='ausstellgrund']") - .select( - faker.number.int({ - min: 1, - max: [Enums.Ausstellgrund.Modernisierung, Enums.Ausstellgrund.Neubau].length - 1, - }) - ) + // Wir überprüfen, ob alle Ausstelgründe vorhanden sind, diese sollten genau so viele sein wie in der Datenbank vorhanden sind. + cy.get("select[data-cy='ausstellgrund']") + .select( + faker.number.int({ + min: 1, + max: [Enums.Ausstellgrund.Modernisierung, Enums.Ausstellgrund.Neubau].length - 1, + }) + ) - // Gebäudetyp - cy.get("select[name='gebaeudetyp']").then(($dropdown) => { - const options = $dropdown.find('option'); - // Select the option at the random index - cy.get("select[name='gebaeudetyp']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); - }); + // Gebäudetyp + cy.get("select[name='gebaeudetyp']").then(($dropdown) => { + const options = $dropdown.find('option'); + // Select the option at the random index + cy.get("select[name='gebaeudetyp']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + }); - // Sanierungsstatus - cy.get("select[name='saniert']").select( - Math.random() > 0.5 ? "true" : "false" - ); - - // Jetzt Füllen wir das Baujahr vom Gebäude aus. - cy.get("input[name='baujahr_gebaeude']") - .should("have.attr", "type", "number") - .type( - faker.number.int({ min: 1900, max: 2021 }).toString() + - "{enter}", - { delay: 50 } + // Sanierungsstatus + cy.get("select[name='saniert']").select( + Math.random() > 0.5 ? "true" : "false" ); - // Jetzt Füllen wir das Baujahr der Heizung aus. - cy.get("input[name='baujahr_heizung']") - .should("have.attr", "type", "number") - .type( - faker.number.int({ min: 1900, max: 2021 }).toString() + - "{enter}", - { delay: 50 } + // Jetzt Füllen wir das Baujahr vom Gebäude aus. + cy.get("input[name='baujahr_gebaeude']") + .should("have.attr", "type", "number") + .type( + faker.number.int({ min: 1900, max: 2021 }).toString() + + "{enter}", + { delay: 50 } + ); + + // Jetzt Füllen wir das Baujahr der Heizung aus. + cy.get("input[name='baujahr_heizung']") + .should("have.attr", "type", "number") + .type( + faker.number.int({ min: 1900, max: 2021 }).toString() + + "{enter}", + { delay: 50 } + ); + + // Adresse + cy.get("input[name='adresse']").type(faker.location.streetAddress()); + + // Postleitzahl + cy.get("input[name='plz']").type( + plz as string ); - // Adresse - cy.get("input[name='adresse']").type(faker.location.streetAddress()); + // TODO: Ort - Dieser wird aus der Datenbank abgefragt, wir müssen also warten, bis der Dropdown da ist. + cy.get("[data-cy='plz-container']").find("button").first().click() - // Postleitzahl - cy.get("input[name='plz']").type( - faker.location.zipCode({ - format: "#####", - }) - ); + // Gebäudeteil + cy.get("select[name='gebaeudeteil']").then(($dropdown) => { + const options = $dropdown.find('option'); + // Select the option at the random index + cy.get("select[name='gebaeudeteil']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + }); + + // Keller + cy.get("select[name='keller']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({ + max: Object.values(Enums.Heizungsstatus).length, + min: 1 + })); - // TODO: Ort - Dieser wird aus der Datenbank abgefragt, wir müssen also warten, bis der Dropdown da ist. - cy.get("[data-cy='plz-container']").find("button").first().click() + // Dachgeschoss + cy.get("select[name='dachgeschoss']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({ + max: Object.values(Enums.Heizungsstatus).length, + min: 1 + })); + + cy.get("[data-cy='beschreibung']").type(faker.lorem.paragraphs({ min: 2, max: 10 })) - // Nutzflaeche - cy.get("input[name='nutzflaeche']") - .should("have.attr", "type", "number") - .type(faker.number.int({ min: 50, max: 1000 }).toString()); + // Wärmedämmung Bilder + cy.get("input[type='file'][name='plaene']").should("have.attr", "type", "file").attachFile("images/daemmung/1.jpeg", { subjectType: "input" }).attachFile("images/daemmung/2.jpeg", { subjectType: "input" }); + cy.get("input[type='file'][name='unterlagen']").should("have.attr", "type", "file").attachFile("images/gebaeude/1.jpeg", { subjectType: "input" }).attachFile("images/daemmung/2.jpeg", { subjectType: "input" }); - // Keller - cy.get("select[name='keller']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({ - max: Object.values(Enums.Heizungsstatus).length, - min: 1 - })); + // Jetzt können wir den Verbrauchsausweis erstellen. + cy.get("form[data-cy='nachweis'] button[data-cy='weiter']").click({ force: true }); - // Dachgeschoss - cy.get("select[name='dachgeschoss']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({ - max: Object.values(Enums.Heizungsstatus).length, - min: 1 - })); - - cy.get("[data-cy='beschreibung']").type(faker.lorem.paragraphs({ min: 2, max: 10 })) + cy.url().should("contain", "/kundendaten"); - // Wärmedämmung Bilder - cy.get("input[type='file'][name='plaene']").should("have.attr", "type", "file").attachFile("images/daemmung/1.jpeg", { subjectType: "input" }).attachFile("images/daemmung/2.jpeg", { subjectType: "input" }); - cy.get("input[type='file'][name='unterlagen']").should("have.attr", "type", "file").attachFile("images/gebaeude/1.jpeg", { subjectType: "input" }).attachFile("images/daemmung/2.jpeg", { subjectType: "input" }); + const email = faker.internet.email(); + const passwort = "test1234"; + const vorname = faker.person.firstName(); + const nachname = faker.person.lastName(); + const telefon = faker.phone.number() - // Jetzt können wir den Verbrauchsausweis erstellen. - cy.get("form[data-cy='nachweis'] button[data-cy='weiter']").click({ force: true }); + const strasse = faker.location.streetAddress({ useFullAddress: true }) - cy.url().should("contain", "/kundendaten"); + cy.get("input[name='vorname']").should("have.attr", "type", "text").type(vorname); + cy.get("input[name='name']").should("have.attr", "type", "text").type(nachname); + cy.get("input[name='telefon']").should("have.attr", "type", "text").type(telefon); + // Rechnung + cy.get("input[name='rechnung_empfaenger']").should("have.attr", "type", "text").type(`${vorname} ${nachname}`); + cy.get("input[name='rechnung_strasse']").should("have.attr", "type", "text").type(strasse); + cy.get("input[name='rechnung_plz']").should("have.attr", "type", "text").type(plz as string); + cy.get("[data-cy='plz-container']").children().first().click() + cy.get("input[name='rechnung_email']").should("have.attr", "type", "email").type(email); - const email = faker.internet.email(); - const passwort = "test1234"; - const vorname = faker.person.firstName(); - const nachname = faker.person.lastName(); - const telefon = faker.phone.number() + cy.get("button[data-cy='bestellen']").click(); - const strasse = faker.location.streetAddress({ useFullAddress: true }) - const plz = faker.location.zipCode("#####") + cy.intercept({ method: "PUT", url: "**/api/rechnung/anfordern" }).as("anfordern") + cy["form:signup"](email, passwort, vorname, nachname) + cy.wait("@anfordern") - cy.get("input[name='vorname']").should("have.attr", "type", "text").type(vorname); - cy.get("input[name='name']").should("have.attr", "type", "text").type(nachname); - cy.get("input[name='telefon']").should("have.attr", "type", "text").type(telefon); - // Rechnung - cy.get("input[name='rechnung_empfaenger']").should("have.attr", "type", "text").type(`${vorname} ${nachname}`); - cy.get("input[name='rechnung_strasse']").should("have.attr", "type", "text").type(strasse); - cy.get("input[name='rechnung_plz']").should("have.attr", "type", "text").type(plz); - cy.get("[data-cy='plz-container']").children().first().click() - cy.get("input[name='rechnung_email']").should("have.attr", "type", "email").type(email); - - cy.get("button[data-cy='bestellen']").click(); - - cy.get("a[data-cy='registrieren']").should("be.visible").click(); - - // Wir sind jetzt registriert und können uns nun einloggen. - // Die Email sollte automatisch eingetragen sein, da wir uns gerade registriert haben. - cy.get("form[name='signup'] input[name='vorname']").should("be.visible").should("have.attr", "type", "text").type(vorname); - cy.get("form[name='signup'] input[name='nachname']").should("be.visible").should("have.attr", "type", "text").type(nachname); - cy.get("form[name='signup'] input[name='email']").should("be.visible").should("have.attr", "type", "email").should("contain.value", email); - cy.get("form[name='signup'] input[name='passwort']").should("be.visible").should("have.attr", "type", "password").type(passwort); - - cy.get("form[name='signup'] button[type='submit']").click(); - cy.get("form[name='login'] button[type='submit']").click(); - - cy.url().should("contain", "/einpreisung/success") + cy.url().should("contain", "/einpreisung/success") + }) }); }); diff --git a/src/cypress/e2e/GEGNachweisWohnen/erstellen.cy.ts b/src/cypress/e2e/GEGNachweisWohnen/erstellen.cy.ts index 86f049f4..9c49f4b6 100644 --- a/src/cypress/e2e/GEGNachweisWohnen/erstellen.cy.ts +++ b/src/cypress/e2e/GEGNachweisWohnen/erstellen.cy.ts @@ -8,118 +8,111 @@ import moment from "moment"; describe("Verbrauchsausweis erstellen Schritt 1", () => { it("erstellt einen neuen Verbrauchsausweis Wohngebäude.", () => { - cy.visit("/angebot-anfragen/geg-nachweis-wohnen-anfragen"); + cy.task("plz").then(plz => { + cy.visit("/angebot-anfragen/geg-nachweis-wohnen-anfragen"); - cy.wait(2000); + cy.wait(2000); - // Wir überprüfen, ob alle Ausstelgründe vorhanden sind, diese sollten genau so viele sein wie in der Datenbank vorhanden sind. - cy.get("select[data-cy='ausstellgrund']") - .select( - faker.number.int({ - min: 1, - max: [Enums.Ausstellgrund.Modernisierung, Enums.Ausstellgrund.Neubau].length - 1, - }) - ) + // Wir überprüfen, ob alle Ausstelgründe vorhanden sind, diese sollten genau so viele sein wie in der Datenbank vorhanden sind. + cy.get("select[data-cy='ausstellgrund']") + .select( + faker.number.int({ + min: 1, + max: [Enums.Ausstellgrund.Modernisierung, Enums.Ausstellgrund.Neubau].length - 1, + }) + ) - // Gebäudetyp - cy.get("select[name='gebaeudetyp']").then(($dropdown) => { - const options = $dropdown.find('option'); - // Select the option at the random index - cy.get("select[name='gebaeudetyp']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + // Gebäudetyp + cy.get("select[name='gebaeudetyp']").then(($dropdown) => { + const options = $dropdown.find('option'); + // Select the option at the random index + cy.get("select[name='gebaeudetyp']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + }); + + // Jetzt Füllen wir das Baujahr vom Gebäude aus. + cy.get("input[name='baujahr_gebaeude']") + .should("have.attr", "type", "number") + .type( + faker.number.int({ min: 1900, max: 2021 }).toString() + + "{enter}", + { delay: 50 } + ); + + // Jetzt Füllen wir das Baujahr der Heizung aus. + cy.get("input[name='baujahr_heizung']") + .should("have.attr", "type", "number") + .type( + faker.number.int({ min: 1900, max: 2021 }).toString() + + "{enter}", + { delay: 50 } + ); + + // Adresse + cy.get("input[name='adresse']").type(faker.location.streetAddress()); + + // Postleitzahl + cy.get("input[name='plz']").type( + plz as string + ); + + // TODO: Ort - Dieser wird aus der Datenbank abgefragt, wir müssen also warten, bis der Dropdown da ist. + cy.get("[data-cy='plz-container']").find("button").first().click() + + // Gebäudeteil + cy.get("select[name='gebaeudeteil']").then(($dropdown) => { + const options = $dropdown.find('option'); + // Select the option at the random index + cy.get("select[name='gebaeudeteil']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + }); + + // Keller + cy.get("select[name='keller']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({ + max: Object.values(Enums.Heizungsstatus).length, + min: 1 + })); + + // Dachgeschoss + cy.get("select[name='dachgeschoss']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({ + max: Object.values(Enums.Heizungsstatus).length, + min: 1 + })); + + cy.get("[data-cy='beschreibung']").type(faker.lorem.paragraphs({ min: 2, max: 10 })) + + // Wärmedämmung Bilder + cy.get("input[type='file'][name='plaene']").should("have.attr", "type", "file").attachFile("images/daemmung/1.jpeg", { subjectType: "input" }).attachFile("images/daemmung/2.jpeg", { subjectType: "input" }); + cy.get("input[type='file'][name='unterlagen']").should("have.attr", "type", "file").attachFile("images/gebaeude/1.jpeg", { subjectType: "input" }).attachFile("images/daemmung/2.jpeg", { subjectType: "input" }); + + // Jetzt können wir den Verbrauchsausweis erstellen. + cy.get("form[data-cy='nachweis'] button[data-cy='weiter']").click({ force: true }); + + cy.url().should("contain", "/kundendaten"); + + const email = faker.internet.email(); + const passwort = "test1234"; + const vorname = faker.person.firstName(); + const nachname = faker.person.lastName(); + const telefon = faker.phone.number() + + const strasse = faker.location.streetAddress({ useFullAddress: true }) + + cy.get("input[name='vorname']").should("have.attr", "type", "text").type(vorname); + cy.get("input[name='name']").should("have.attr", "type", "text").type(nachname); + cy.get("input[name='telefon']").should("have.attr", "type", "text").type(telefon); + // Rechnung + cy.get("input[name='rechnung_empfaenger']").should("have.attr", "type", "text").type(`${vorname} ${nachname}`); + cy.get("input[name='rechnung_strasse']").should("have.attr", "type", "text").type(strasse); + cy.get("input[name='rechnung_plz']").should("have.attr", "type", "text").type(plz as string); + cy.get("[data-cy='plz-container']").children().first().click() + cy.get("input[name='rechnung_email']").should("have.attr", "type", "email").type(email); + + cy.get("button[data-cy='bestellen']").click(); + + cy.intercept({ method: "PUT", url: "**/api/rechnung/anfordern" }).as("anfordern") + cy["form:signup"](email, passwort, vorname, nachname) + cy.wait("@anfordern") + + cy.url().should("contain", "/einpreisung/success") }); - - // Jetzt Füllen wir das Baujahr vom Gebäude aus. - cy.get("input[name='baujahr_gebaeude']") - .should("have.attr", "type", "number") - .type( - faker.number.int({ min: 1900, max: 2021 }).toString() + - "{enter}", - { delay: 50 } - ); - - // Jetzt Füllen wir das Baujahr der Heizung aus. - cy.get("input[name='baujahr_heizung']") - .should("have.attr", "type", "number") - .type( - faker.number.int({ min: 1900, max: 2021 }).toString() + - "{enter}", - { delay: 50 } - ); - - // Adresse - cy.get("input[name='adresse']").type(faker.location.streetAddress()); - - // Postleitzahl - cy.get("input[name='plz']").type( - faker.location.zipCode({ - format: "#####", - }) - ); - - // TODO: Ort - Dieser wird aus der Datenbank abgefragt, wir müssen also warten, bis der Dropdown da ist. - cy.get("[data-cy='plz-container']").find("button").first().click() - - // Nutzflaeche - cy.get("input[name='nutzflaeche']") - .should("have.attr", "type", "number") - .type(faker.number.int({ min: 50, max: 1000 }).toString()); - - // Keller - cy.get("select[name='keller']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({ - max: Object.values(Enums.Heizungsstatus).length, - min: 1 - })); - - // Dachgeschoss - cy.get("select[name='dachgeschoss']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({ - max: Object.values(Enums.Heizungsstatus).length, - min: 1 - })); - - cy.get("[data-cy='beschreibung']").type(faker.lorem.paragraphs({ min: 2, max: 10 })) - - // Wärmedämmung Bilder - cy.get("input[type='file'][name='plaene']").should("have.attr", "type", "file").attachFile("images/daemmung/1.jpeg", { subjectType: "input" }).attachFile("images/daemmung/2.jpeg", { subjectType: "input" }); - cy.get("input[type='file'][name='unterlagen']").should("have.attr", "type", "file").attachFile("images/gebaeude/1.jpeg", { subjectType: "input" }).attachFile("images/daemmung/2.jpeg", { subjectType: "input" }); - - // Jetzt können wir den Verbrauchsausweis erstellen. - cy.get("form[data-cy='nachweis'] button[data-cy='weiter']").click({ force: true }); - - cy.url().should("contain", "/kundendaten"); - - const email = faker.internet.email(); - const passwort = "test1234"; - const vorname = faker.person.firstName(); - const nachname = faker.person.lastName(); - const telefon = faker.phone.number() - - const strasse = faker.location.streetAddress({ useFullAddress: true }) - const plz = faker.location.zipCode("#####") - - cy.get("input[name='vorname']").should("have.attr", "type", "text").type(vorname); - cy.get("input[name='name']").should("have.attr", "type", "text").type(nachname); - cy.get("input[name='telefon']").should("have.attr", "type", "text").type(telefon); - // Rechnung - cy.get("input[name='rechnung_empfaenger']").should("have.attr", "type", "text").type(`${vorname} ${nachname}`); - cy.get("input[name='rechnung_strasse']").should("have.attr", "type", "text").type(strasse); - cy.get("input[name='rechnung_plz']").should("have.attr", "type", "text").type(plz); - cy.get("[data-cy='plz-container']").children().first().click() - cy.get("input[name='rechnung_email']").should("have.attr", "type", "email").type(email); - - cy.get("button[data-cy='bestellen']").click(); - - cy.get("a[data-cy='registrieren']").should("be.visible").click(); - - // Wir sind jetzt registriert und können uns nun einloggen. - // Die Email sollte automatisch eingetragen sein, da wir uns gerade registriert haben. - cy.get("form[name='signup'] input[name='vorname']").should("be.visible").should("have.attr", "type", "text").type(vorname); - cy.get("form[name='signup'] input[name='nachname']").should("be.visible").should("have.attr", "type", "text").type(nachname); - cy.get("form[name='signup'] input[name='email']").should("be.visible").should("have.attr", "type", "email").should("contain.value", email); - cy.get("form[name='signup'] input[name='passwort']").should("be.visible").should("have.attr", "type", "password").type(passwort); - - cy.get("form[name='signup'] button[type='submit']").click(); - cy.get("form[name='login'] button[type='submit']").click(); - - cy.url().should("contain", "/einpreisung/success") }); }); diff --git a/src/cypress/e2e/VerbrauchsausweisGewerbe/erstellen.cy.ts b/src/cypress/e2e/VerbrauchsausweisGewerbe/erstellen.cy.ts index 9ba3a856..17bb4c7a 100644 --- a/src/cypress/e2e/VerbrauchsausweisGewerbe/erstellen.cy.ts +++ b/src/cypress/e2e/VerbrauchsausweisGewerbe/erstellen.cy.ts @@ -1,312 +1,296 @@ import fuelList from "#components/Ausweis/brennstoffListe.js"; import { faker } from "@faker-js/faker"; -import { type Enums } from "#lib/client/prisma.js"; +import { Enums } from "#lib/client/prisma.js"; import "cypress-file-upload" import moment from "moment"; describe("Verbrauchsausweis erstellen Schritt 1", () => { - const ausstellgrund = (["Modernisierung", "Neubau", "Sonstiges", "Verkauf", "Vermietung"] as Enums.Ausstellgrund[]); - const heizungsstatus = (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]); - it("erstellt einen neuen Verbrauchsausweis Wohngebäude.", () => { - cy.visit("/energieausweis-erstellen/verbrauchsausweis-gewerbe"); + cy.task("plz").then(plz => { + cy.visit("/energieausweis-erstellen/verbrauchsausweis-gewerbe"); - cy.wait(1000); + cy.wait(1000); - // Wir überprüfen, ob alle Ausstelgründe vorhanden sind, diese sollten genau so viele sein wie in der Datenbank vorhanden sind. - cy.get("select[data-cy='ausstellgrund']") - .select( - faker.number.int({ - min: 1, - max: (["Modernisierung", "Neubau", "Sonstiges", "Verkauf", "Vermietung"] as Enums.Ausstellgrund[]).length, - }) - ) + // Wir überprüfen, ob alle Ausstelgründe vorhanden sind, diese sollten genau so viele sein wie in der Datenbank vorhanden sind. + cy.get("select[data-cy='ausstellgrund']") + .select( + faker.number.int({ + min: 1, + max: (["Modernisierung", "Neubau", "Sonstiges", "Verkauf", "Vermietung"] as Enums.Ausstellgrund[]).length, + }) + ) - // Jetzt Füllen wir das Baujahr vom Gebäude aus. - cy.get("input[name='baujahr_gebaeude']") - .should("have.attr", "type", "number") - .type( - faker.number.int({ min: 1900, max: 2021 }).toString() + - "{enter}", - { delay: 50 } + // Jetzt Füllen wir das Baujahr vom Gebäude aus. + cy.get("input[name='baujahr_gebaeude']") + .should("have.attr", "type", "number") + .type( + faker.number.int({ min: 1900, max: 2021 }).toString() + + "{enter}", + { delay: 50 } + ); + + // Jetzt Füllen wir das Baujahr der Heizung aus. + cy.get("input[name='baujahr_heizung']") + .should("have.attr", "type", "number") + .type( + faker.number.int({ min: 1900, max: 2021 }).toString() + + "{enter}", + { delay: 50 } + ); + + // // Anzahl Einheiten + // cy.get("input[name='einheiten']") + // .should("have.attr", "type", "number") + // .type(faker.number.int({ min: 1, max: 5 }).toString()); + + // Sanierungsstatus + cy.get("select[name='saniert']").select( + Math.random() > 0.5 ? "true" : "false" ); - // Jetzt Füllen wir das Baujahr der Heizung aus. - cy.get("input[name='baujahr_heizung']") - .should("have.attr", "type", "number") - .type( - faker.number.int({ min: 1900, max: 2021 }).toString() + - "{enter}", - { delay: 50 } + // Adresse + cy.get("input[name='adresse']").type(faker.location.streetAddress()); + + // Postleitzahl + cy.get("input[name='plz']").type( + plz as string ); - // // Anzahl Einheiten - // cy.get("input[name='einheiten']") - // .should("have.attr", "type", "number") - // .type(faker.number.int({ min: 1, max: 5 }).toString()); + // TODO: Ort - Dieser wird aus der Datenbank abgefragt, wir müssen also warten, bis der Dropdown da ist. + cy.get("[data-cy='plz-container']").find("button").first().click() - // Sanierungsstatus - cy.get("select[name='saniert']").select( - Math.random() > 0.5 ? "true" : "false" - ); + // // Flaeche + // cy.get("input[name='flaeche']") + // .should("have.attr", "type", "number") + // .type(faker.number.int({ min: 50, max: 1000 }).toString()); - // Adresse - cy.get("input[name='adresse']").type(faker.location.streetAddress()); + // Nutzlaeche + cy.get("input[name='nutzflaeche']") + .should("have.attr", "type", "number") + .type(faker.number.int({ min: 50, max: 1000 }).toString()); - // Postleitzahl - cy.get("input[name='plz']").type( - faker.location.zipCode({ - format: "#####", - }) - ); + // Keller + cy.get("select[name='keller']").find("option:not([disabled])").should("have.length", Object.keys(Enums.Heizungsstatus).length).parent().select(faker.number.int({ + max: Object.keys(Enums.Heizungsstatus).length, + min: 1 + })); - // TODO: Ort - Dieser wird aus der Datenbank abgefragt, wir müssen also warten, bis der Dropdown da ist. - cy.get("[data-cy='plz-container']").find("button").first().click() + // Dachgeschoss + cy.get("select[name='dachgeschoss']").find("option:not([disabled])").should("have.length", Object.keys(Enums.Heizungsstatus).length).parent().select(faker.number.int({ + max: Object.keys(Enums.Heizungsstatus).length, + min: 1 + })); - // // Flaeche - // cy.get("input[name='flaeche']") - // .should("have.attr", "type", "number") - // .type(faker.number.int({ min: 50, max: 1000 }).toString()); + // Brennstoff und Einheit 1 + const brennstoffKombo = fuelList[faker.number.int({ min: 0, max: fuelList.length - 1 })]; - // Nutzlaeche - cy.get("input[name='nutzflaeche']") - .should("have.attr", "type", "number") - .type(faker.number.int({ min: 50, max: 1000 }).toString()); - - // Keller - cy.get("select[name='keller']").find("option:not([disabled])").should("have.length", heizungsstatus.length).parent().select(faker.number.int({ - max: heizungsstatus.length, - min: 1 - })); - - // Dachgeschoss - cy.get("select[name='dachgeschoss']").find("option:not([disabled])").should("have.length", heizungsstatus.length).parent().select(faker.number.int({ - max: heizungsstatus.length, - min: 1 - })); - - // Brennstoff und Einheit 1 - const brennstoffKombo = fuelList[faker.number.int({ min: 0, max: fuelList.length - 1 })]; - - cy.get("select[name='brennstoff_1']").select(brennstoffKombo[0]); - cy.get("select[name='einheit_1']").select(brennstoffKombo[1]); - - let availableDates = []; - const startDate = moment() - .subtract(4, "years") - .subtract(6, "months"); - const endDate = moment().subtract(3, "years"); - - for (let m = moment(startDate); m.isBefore(endDate); m.add(1, "month")) { - availableDates.push({ - year: m.year(), - month: m.month(), - }); - } - - // Verbrauchszeitraum - cy.get("select[name='energieverbrauch_zeitraum_jahr']").select(availableDates[0].year.toString()); - cy.get("select[name='energieverbrauch_zeitraum_monat']").select(availableDates[0].month.toString()); - - // Verbrauch - cy.get("input[name='verbrauch_1']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); - cy.get("input[name='verbrauch_2']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); - cy.get("input[name='verbrauch_3']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + cy.get("select[name='brennstoff_1']").select(brennstoffKombo[0]); + cy.get("select[name='einheit_1']").select(brennstoffKombo[1]); + let availableDates = []; + const startDate = moment() + .subtract(4, "years") + .subtract(6, "months"); + const endDate = moment().subtract(3, "years"); - const zusaetzlicheHeizquelle = Math.random() > 0.5; + for (let m = moment(startDate); m.isBefore(endDate); m.add(1, "month")) { + availableDates.push({ + year: m.year(), + month: m.month(), + }); + } - if (zusaetzlicheHeizquelle) { - cy.get("[data-cy='zusaetzliche_heizquelle']").check(); - - // Brennstoff und Einheit 2 - const brennstoffKombo2 = fuelList[faker.number.int({ min: 0, max: fuelList.length - 1 })]; - - cy.get("[data-cy='brennstoff_2']").select(brennstoffKombo2[0], { force: true }); - cy.get("[data-cy='einheit_2']").select(brennstoffKombo2[1], { force: true }); + // Verbrauchszeitraum + cy.get("select[name='energieverbrauch_zeitraum_jahr']").select(availableDates[0].year.toString()); + cy.get("select[name='energieverbrauch_zeitraum_monat']").select(availableDates[0].month.toString()); // Verbrauch - cy.get("input[name='verbrauch_4']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); - cy.get("input[name='verbrauch_5']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); - cy.get("input[name='verbrauch_6']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); - } + cy.get("input[name='verbrauch_1']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + cy.get("input[name='verbrauch_2']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + cy.get("input[name='verbrauch_3']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); - // Gebäudestrom - cy.get("input[name='strom_1']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); - cy.get("input[name='strom_2']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); - cy.get("input[name='strom_3']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + + const zusaetzlicheHeizquelle = Math.random() > 0.5; - // Stromverbrauch Enthält - if (Math.random() > 0.5) cy.get("input[name='stromverbrauch_enthaelt_heizung']").check(); - if (Math.random() > 0.5) cy.get("input[name='stromverbrauch_enthaelt_warmwasser']").check(); - if (Math.random() > 0.5) cy.get("input[name='stromverbrauch_enthaelt_lueftung']").check(); - if (Math.random() > 0.5) cy.get("input[name='stromverbrauch_enthaelt_beleuchtung']").check(); - if (Math.random() > 0.5) cy.get("input[name='stromverbrauch_enthaelt_kuehlung']").check(); + if (zusaetzlicheHeizquelle) { + cy.get("[data-cy='zusaetzliche_heizquelle']").check(); - // Warmwasser enthalten und bekannt - const warmwasserEnthalten = Math.random() > 0.5; - const anteilBekannt = Math.random() > 0.5; + // Brennstoff und Einheit 2 + const brennstoffKombo2 = fuelList[faker.number.int({ min: 0, max: fuelList.length - 1 })]; - if (warmwasserEnthalten) { - cy.get("input[name='warmwasser_enthalten']").check(); + cy.get("[data-cy='brennstoff_2']").select(brennstoffKombo2[0], { force: true }); + cy.get("[data-cy='einheit_2']").select(brennstoffKombo2[1], { force: true }); - if (anteilBekannt) { - // Der Anteil ist bekannt, wir müssen ihn also angeben. - cy.get("input[name='warmwasser_anteil_bekannt']").check(); + // Verbrauch + cy.get("input[name='verbrauch_4']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); + cy.get("input[name='verbrauch_5']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); + cy.get("input[name='verbrauch_6']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); + } - cy.get("input[name='anteil_warmwasser_1']").type(faker.number.int({ min: 0, max: 50 }).toString()); + // Gebäudestrom + cy.get("input[name='strom_1']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + cy.get("input[name='strom_2']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + cy.get("input[name='strom_3']").type(faker.number.int({ min: 4000, max: 15000 }).toString()); + + // Stromverbrauch Enthält + if (Math.random() > 0.5) cy.get("input[name='stromverbrauch_enthaelt_heizung']").check(); + if (Math.random() > 0.5) cy.get("input[name='stromverbrauch_enthaelt_warmwasser']").check(); + if (Math.random() > 0.5) cy.get("input[name='stromverbrauch_enthaelt_lueftung']").check(); + if (Math.random() > 0.5) cy.get("input[name='stromverbrauch_enthaelt_beleuchtung']").check(); + if (Math.random() > 0.5) cy.get("input[name='stromverbrauch_enthaelt_kuehlung']").check(); + + // Warmwasser enthalten und bekannt + const warmwasserEnthalten = Math.random() > 0.5; + const anteilBekannt = Math.random() > 0.5; + + if (warmwasserEnthalten) { + cy.get("input[name='warmwasser_enthalten']").check(); + + if (anteilBekannt) { + // Der Anteil ist bekannt, wir müssen ihn also angeben. + cy.get("input[name='warmwasser_anteil_bekannt']").check(); + + cy.get("input[name='anteil_warmwasser_1']").type(faker.number.int({ min: 0, max: 50 }).toString()); + + if (zusaetzlicheHeizquelle) { + // Zusätzliche Heizquelle existiert, also müssen wir auch hier den Anteil angeben. + cy.get("input[name='anteil_warmwasser_1']").type(faker.number.int({ min: 0, max: 50 }).toString()); + } + } + } + + // Thermische Kühlung enthalten + const kuehlungEnthalten = Math.random() > 0.5; + + if (kuehlungEnthalten) { + cy.get("input[name='kuehlung_enthalten']").check(); + + cy.get("input[name='anteil_kuehlung_1']").type(faker.number.int({ min: 0, max: 50 }).toString()); if (zusaetzlicheHeizquelle) { // Zusätzliche Heizquelle existiert, also müssen wir auch hier den Anteil angeben. - cy.get("input[name='anteil_warmwasser_1']").type(faker.number.int({ min: 0, max: 50 }).toString()); + cy.get("input[name='anteil_kuehlung_2']").type(faker.number.int({ min: 0, max: 50 }).toString()); } } - } - // Thermische Kühlung enthalten - const kuehlungEnthalten = Math.random() > 0.5; + // Alternative Energieversorgungssysteme + if (Math.random() > 0.5) cy.get("input[name='alternative_heizung']").check(); + if (Math.random() > 0.5) cy.get("input[name='alternative_warmwasser']").check(); + if (Math.random() > 0.5) cy.get("input[name='alternative_lueftung']").check(); + if (Math.random() > 0.5) cy.get("input[name='alternative_kuehlung']").check(); - if (kuehlungEnthalten) { - cy.get("input[name='kuehlung_enthalten']").check(); + // Gebäudetyp + cy.get("select[name='gebaeudetyp']").then(($dropdown) => { + const options = $dropdown.find('option:not([disabled])'); + // Select the option at the random index + cy.get("select[name='gebaeudetyp']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + }); - cy.get("input[name='anteil_kuehlung_1']").type(faker.number.int({ min: 0, max: 50 }).toString()); + // Gebäudeteil + cy.get("select[name='gebaeudeteil']").then(($dropdown) => { + const options = $dropdown.find('option'); + // Select the option at the random index + cy.get("select[name='gebaeudeteil']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + }); - if (zusaetzlicheHeizquelle) { - // Zusätzliche Heizquelle existiert, also müssen wir auch hier den Anteil angeben. - cy.get("input[name='anteil_kuehlung_2']").type(faker.number.int({ min: 0, max: 50 }).toString()); - } - } + // Lüftung + cy.get("select[name='lueftung']").then(($dropdown) => { + const options = $dropdown.find('option'); + // Select the option at the random index + cy.get("select[name='lueftung']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + }); - // Alternative Energieversorgungssysteme - if (Math.random() > 0.5) cy.get("input[name='alternative_heizung']").check(); - if (Math.random() > 0.5) cy.get("input[name='alternative_warmwasser']").check(); - if (Math.random() > 0.5) cy.get("input[name='alternative_lueftung']").check(); - if (Math.random() > 0.5) cy.get("input[name='alternative_kuehlung']").check(); + // Kühlung + cy.get("select[name='kuehlung']").then(($dropdown) => { + const options = $dropdown.find('option'); + // Select the option at the random index + cy.get("select[name='kuehlung']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + }); - // Gebäudetyp - cy.get("select[name='gebaeudetyp']").then(($dropdown) => { - const options = $dropdown.find('option:not([disabled])'); - // Select the option at the random index - cy.get("select[name='gebaeudetyp']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); - }); + // Leerstand + cy.get("input[name='leerstand']").should("have.attr", "type", "number").type(faker.number.int({ min: 0, max: 30 }).toString()); - // Gebäudeteil - cy.get("select[name='gebaeudeteil']").then(($dropdown) => { - const options = $dropdown.find('option'); - // Select the option at the random index - cy.get("select[name='gebaeudeteil']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); - }); + // Heizungsanlage Daten + if (Math.random() > 0.5) cy.get("input[name='zentralheizung']").check(); + if (Math.random() > 0.5) cy.get("input[name='einzelofen']").check(); + if (Math.random() > 0.5) cy.get("input[name='durchlauf_erhitzer']").check(); + if (Math.random() > 0.5) cy.get("input[name='standard_kessel']").check(); + if (Math.random() > 0.5) cy.get("input[name='solarsystem_warmwasser']").check(); + if (Math.random() > 0.5) cy.get("input[name='waermepumpe']").check(); + if (Math.random() > 0.5) cy.get("input[name='niedertemperatur_kessel']").check(); + if (Math.random() > 0.5) cy.get("input[name='brennwert_kessel']").check(); + if (Math.random() > 0.5) cy.get("input[name='warmwasser_rohre_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("input[name='heizungsrohre_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("input[name='zirkulation']").check(); + // if (Math.random() > 0.5) cy.get("input[name='raum_temperatur_regler']").check(); - // Lüftung - cy.get("select[name='lueftung']").then(($dropdown) => { - const options = $dropdown.find('option'); - // Select the option at the random index - cy.get("select[name='lueftung']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); - }); + // Heizungsanlage Bilder + cy.get("input[name='heizung_image']").should("have.attr", "type", "file").attachFile("images/heizungsanlage/1.jpeg", { subjectType: "input" }); + cy.get("input[name='heizung_image']").should("have.attr", "type", "file").attachFile("images/heizungsanlage/2.jpeg", { subjectType: "input" }); - // Kühlung - cy.get("select[name='kuehlung']").then(($dropdown) => { - const options = $dropdown.find('option'); - // Select the option at the random index - cy.get("select[name='kuehlung']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); - }); + // Fenster Daten + if (Math.random() > 0.5) cy.get("input[name='einfach_verglasung']").check(); + if (Math.random() > 0.5) cy.get("input[name='doppel_verglasung']").check(); + if (Math.random() > 0.5) cy.get("input[name='isolier_verglasung']").check(); + if (Math.random() > 0.5) cy.get("input[name='dreifach_verglasung']").check(); + if (Math.random() > 0.5) cy.get("input[name='fenster_dicht']").check(); + if (Math.random() > 0.5) cy.get("input[name='fenster_teilweise_undicht']").check(); + if (Math.random() > 0.5) cy.get("input[name='tueren_dicht']").check(); + if (Math.random() > 0.5) cy.get("input[name='tueren_undicht']").check(); + if (Math.random() > 0.5) cy.get("input[name='rolllaeden_kaesten_gedaemmt']").check(); - // Leerstand - cy.get("input[name='leerstand']").should("have.attr", "type", "number").type(faker.number.int({ min: 0, max: 30 }).toString()); + // Fenster Bilder + cy.get("input[name='fenster_image']").should("have.attr", "type", "file").attachFile("images/fenster/1.jpeg", { subjectType: "input" }); + cy.get("input[name='fenster_image']").should("have.attr", "type", "file").attachFile("images/fenster/2.jpeg", { subjectType: "input" }); - // Heizungsanlage Daten - if (Math.random() > 0.5) cy.get("input[name='zentralheizung']").check(); - if (Math.random() > 0.5) cy.get("input[name='einzelofen']").check(); - if (Math.random() > 0.5) cy.get("input[name='durchlauf_erhitzer']").check(); - if (Math.random() > 0.5) cy.get("input[name='standard_kessel']").check(); - if (Math.random() > 0.5) cy.get("input[name='solarsystem_warmwasser']").check(); - if (Math.random() > 0.5) cy.get("input[name='waermepumpe']").check(); - if (Math.random() > 0.5) cy.get("input[name='niedertemperatur_kessel']").check(); - if (Math.random() > 0.5) cy.get("input[name='brennwert_kessel']").check(); - if (Math.random() > 0.5) cy.get("input[name='warmwasser_rohre_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("input[name='heizungsrohre_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("input[name='zirkulation']").check(); - // if (Math.random() > 0.5) cy.get("input[name='raum_temperatur_regler']").check(); + // Wärmedämmung Daten + if (Math.random() > 0.5) cy.get("input[name='aussenwand_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("input[name='keller_wand_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("input[name='keller_decke_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("input[name='dachgeschoss_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("input[name='oberste_geschossdecke_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("input[name='oberste_geschossdecke_min_12cm_gedaemmt']").check(); - // Heizungsanlage Bilder - cy.get("input[name='heizung_image']").should("have.attr", "type", "file").attachFile("images/heizungsanlage/1.jpeg", { subjectType: "input" }); - cy.get("input[name='heizung_image']").should("have.attr", "type", "file").attachFile("images/heizungsanlage/2.jpeg", { subjectType: "input" }); + // Wärmedämmung Bilder + cy.get("input[name='daemmung_image']").should("have.attr", "type", "file").attachFile("images/daemmung/1.jpeg", { subjectType: "input" }); + cy.get("input[name='daemmung_image']").should("have.attr", "type", "file").attachFile("images/daemmung/2.jpeg", { subjectType: "input" }); - // Fenster Daten - if (Math.random() > 0.5) cy.get("input[name='einfach_verglasung']").check(); - if (Math.random() > 0.5) cy.get("input[name='doppel_verglasung']").check(); - if (Math.random() > 0.5) cy.get("input[name='isolier_verglasung']").check(); - if (Math.random() > 0.5) cy.get("input[name='dreifach_verglasung']").check(); - if (Math.random() > 0.5) cy.get("input[name='fenster_dicht']").check(); - if (Math.random() > 0.5) cy.get("input[name='fenster_teilweise_undicht']").check(); - if (Math.random() > 0.5) cy.get("input[name='tueren_dicht']").check(); - if (Math.random() > 0.5) cy.get("input[name='tueren_undicht']").check(); - if (Math.random() > 0.5) cy.get("input[name='rolllaeden_kaesten_gedaemmt']").check(); + // Gebäude Bild + cy.get("input[name='gebaeude_image']").should("have.attr", "type", "file").attachFile("images/gebaeude/1.jpeg", { subjectType: "input" }); - // Fenster Bilder - cy.get("input[name='fenster_image']").should("have.attr", "type", "file").attachFile("images/fenster/1.jpeg", { subjectType: "input" }); - cy.get("input[name='fenster_image']").should("have.attr", "type", "file").attachFile("images/fenster/2.jpeg", { subjectType: "input" }); + cy.get("form[data-cy='ausweis'] button[data-cy='weiter']").click({ force: true }); - // Wärmedämmung Daten - if (Math.random() > 0.5) cy.get("input[name='aussenwand_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("input[name='keller_wand_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("input[name='keller_decke_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("input[name='dachgeschoss_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("input[name='oberste_geschossdecke_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("input[name='oberste_geschossdecke_min_12cm_gedaemmt']").check(); + cy.url().should("contain", "/kundendaten"); - // Wärmedämmung Bilder - cy.get("input[name='daemmung_image']").should("have.attr", "type", "file").attachFile("images/daemmung/1.jpeg", { subjectType: "input" }); - cy.get("input[name='daemmung_image']").should("have.attr", "type", "file").attachFile("images/daemmung/2.jpeg", { subjectType: "input" }); + const email = faker.internet.email(); + const passwort = "test1234"; + const vorname = faker.person.firstName(); + const nachname = faker.person.lastName(); + const telefon = faker.phone.number() - // Gebäude Bild - cy.get("input[name='gebaeude_image']").should("have.attr", "type", "file").attachFile("images/gebaeude/1.jpeg", { subjectType: "input" }); + const strasse = faker.location.streetAddress({ useFullAddress: true }) - cy.get("form[data-cy='ausweis'] button[data-cy='weiter']").click({ force: true }); + cy.get("input[name='vorname']").should("have.attr", "type", "text").type(vorname); + cy.get("input[name='name']").should("have.attr", "type", "text").type(nachname); + cy.get("input[name='telefon']").should("have.attr", "type", "text").type(telefon); + // Rechnung + cy.get("input[name='rechnung_empfaenger']").should("have.attr", "type", "text").type(`${vorname} ${nachname}`); + cy.get("input[name='rechnung_strasse']").should("have.attr", "type", "text").type(strasse); + cy.get("input[name='rechnung_plz']").should("have.attr", "type", "text").type(plz as string); + cy.get("[data-cy='plz-container']").children().first().click() + cy.get("input[name='rechnung_email']").should("have.attr", "type", "email").type(email); - cy.url().should("contain", "/kundendaten"); + cy.get("[data-cy='paypal']").click() - const email = faker.internet.email(); - const passwort = "test1234"; - const vorname = faker.person.firstName(); - const nachname = faker.person.lastName(); - const telefon = faker.phone.number() + cy.get("button[data-cy='bestellen']").click(); - const strasse = faker.location.streetAddress({ useFullAddress: true }) - const plz = faker.location.zipCode("#####") + cy["form:signup"](email, passwort, vorname, nachname) - cy.get("input[name='vorname']").should("have.attr", "type", "text").type(vorname); - cy.get("input[name='name']").should("have.attr", "type", "text").type(nachname); - cy.get("input[name='telefon']").should("have.attr", "type", "text").type(telefon); - // Rechnung - cy.get("input[name='rechnung_empfaenger']").should("have.attr", "type", "text").type(`${vorname} ${nachname}`); - cy.get("input[name='rechnung_strasse']").should("have.attr", "type", "text").type(strasse); - cy.get("input[name='rechnung_plz']").should("have.attr", "type", "text").type(plz); - cy.get("[data-cy='plz-container']").children().first().click() - cy.get("input[name='rechnung_email']").should("have.attr", "type", "email").type(email); - - cy.get("[data-cy='paypal']").click() - - cy.get("button[data-cy='bestellen']").click(); - - cy.get("a[data-cy='registrieren']").should("be.visible").click(); - - // Wir sind jetzt registriert und können uns nun einloggen. - // Die Email sollte automatisch eingetragen sein, da wir uns gerade registriert haben. - cy.get("form[name='signup'] input[name='vorname']").should("be.visible").should("have.attr", "type", "text").type(vorname); - cy.get("form[name='signup'] input[name='nachname']").should("be.visible").should("have.attr", "type", "text").type(nachname); - cy.get("form[name='signup'] input[name='email']").should("be.visible").should("have.attr", "type", "email").should("contain.value", email); - cy.get("form[name='signup'] input[name='passwort']").should("be.visible").should("have.attr", "type", "password").type(passwort); - - cy.intercept({ method: "PUT", url: "**/api/user" }).as("signup") - cy.get("form[name='signup'] button[type='submit']").click(); - cy.wait("@signup") - cy.get("form[name='login'] button[type='submit']").click(); - - cy.origin('https://www.mollie.com', () => { - // Jetzt sind wir auf der Mollie Seite, dort wählen wir den "paid" status aus - cy.get("input[type='radio'][name='final_state'][value='paid']").check(); - // Da wird unser Test fehlschlagen, da die localhost domain von Mollie aus nicht erreichbar ist. + cy.origin('https://www.mollie.com', () => { + // Jetzt sind wir auf der Mollie Seite, dort wählen wir den "paid" status aus + cy.get("input[type='radio'][name='final_state'][value='paid']").check(); + // Da wird unser Test fehlschlagen, da die localhost domain von Mollie aus nicht erreichbar ist. + }) }) }); }); diff --git a/src/cypress/e2e/VerbrauchsausweisWohnen/erstellen.cy.ts b/src/cypress/e2e/VerbrauchsausweisWohnen/erstellen.cy.ts index a0ce8e9e..d0eeaf18 100644 --- a/src/cypress/e2e/VerbrauchsausweisWohnen/erstellen.cy.ts +++ b/src/cypress/e2e/VerbrauchsausweisWohnen/erstellen.cy.ts @@ -6,296 +6,283 @@ import moment from "moment"; describe("Verbrauchsausweis erstellen Schritt 1", () => { it("erstellt einen neuen Verbrauchsausweis Wohngebäude.", () => { - const email = faker.internet.email(); - const passwort = "test1234"; - const vorname = faker.person.firstName(); - const nachname = faker.person.lastName(); - const telefon = faker.phone.number() + cy.task("plz").then(plz => { + const email = faker.internet.email(); + const passwort = "test1234"; + const vorname = faker.person.firstName(); + const nachname = faker.person.lastName(); + const telefon = faker.phone.number() - const strasse = faker.location.streetAddress({ useFullAddress: true }) - const plz = faker.location.zipCode("#####") + const strasse = faker.location.streetAddress({ useFullAddress: true }) - const preLogin = Math.random() > 0.5; + const preLogin = Math.random() > 0.5; - if (preLogin) { - cy.signup(email, passwort, vorname, nachname) - cy.login(email, passwort) - } + if (preLogin) { + cy.signup(email, passwort, vorname, nachname) + cy.login(email, passwort) + } - cy.visit("/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"); - - cy.wait(2000); + cy.visit("/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"); + + cy.wait(2000); - // Wir überprüfen, ob alle Ausstelgründe vorhanden sind, diese sollten genau so viele sein wie in der Datenbank vorhanden sind. - cy.get("select[data-cy='ausstellgrund']") - .select( - faker.number.int({ - min: 1, - max: Object.values(Enums.Ausstellgrund).length - 1, - }) - ) + // Wir überprüfen, ob alle Ausstelgründe vorhanden sind, diese sollten genau so viele sein wie in der Datenbank vorhanden sind. + cy.get("select[data-cy='ausstellgrund']") + .select( + faker.number.int({ + min: 1, + max: Object.values(Enums.Ausstellgrund).length - 1, + }) + ) - // Jetzt Füllen wir das Baujahr vom Gebäude aus. - cy.get("input[name='baujahr_gebaeude']") - .should("have.attr", "type", "number") - .type( - faker.number.int({ min: 1900, max: 2021 }).toString() + - "{enter}", - { delay: 50 } + // Jetzt Füllen wir das Baujahr vom Gebäude aus. + cy.get("input[name='baujahr_gebaeude']") + .should("have.attr", "type", "number") + .type( + faker.number.int({ min: 1900, max: 2021 }).toString() + + "{enter}", + { delay: 50 } + ); + + // Jetzt Füllen wir das Baujahr der Heizung aus. + cy.get("input[name='baujahr_heizung']") + .should("have.attr", "type", "number") + .type( + faker.number.int({ min: 1900, max: 2021 }).toString() + + "{enter}", + { delay: 50 } + ); + + // Anzahl Einheiten + cy.get("input[name='einheiten']") + .should("have.attr", "type", "number") + .type(faker.number.int({ min: 1, max: 5 }).toString()); + + // Sanierungsstatus + cy.get("select[name='saniert']").select( + Math.random() > 0.5 ? "true" : "false" ); - // Jetzt Füllen wir das Baujahr der Heizung aus. - cy.get("input[name='baujahr_heizung']") - .should("have.attr", "type", "number") - .type( - faker.number.int({ min: 1900, max: 2021 }).toString() + - "{enter}", - { delay: 50 } + // Adresse + cy.get("input[name='adresse']").type(faker.location.streetAddress()); + + // Postleitzahl + cy.get("input[name='plz']").type( + plz as string ); - // Anzahl Einheiten - cy.get("input[name='einheiten']") - .should("have.attr", "type", "number") - .type(faker.number.int({ min: 1, max: 5 }).toString()); + // TODO: Ort - Dieser wird aus der Datenbank abgefragt, wir müssen also warten, bis der Dropdown da ist. + cy.get("[data-cy='plz-container']").find("button").first().click() - // Sanierungsstatus - cy.get("select[name='saniert']").select( - Math.random() > 0.5 ? "true" : "false" - ); + // Flaeche + cy.get("input[name='flaeche']") + .should("have.attr", "type", "number") + .type(faker.number.int({ min: 50, max: 1000 }).toString()); - // Adresse - cy.get("input[name='adresse']").type(faker.location.streetAddress()); + // Nutzflaeche + cy.get("input[name='nutzflaeche']") + .should("have.attr", "type", "number") + .type(faker.number.int({ min: 50, max: 1000 }).toString()); - // Postleitzahl - cy.get("input[name='plz']").type( - faker.location.zipCode({ - format: "#####", - }) - ); + // Keller + cy.get("select[name='keller']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({ + max: (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length, + min: 1 + })); - // TODO: Ort - Dieser wird aus der Datenbank abgefragt, wir müssen also warten, bis der Dropdown da ist. - cy.get("[data-cy='plz-container']").find("button").first().click() + // Dachgeschoss + cy.get("select[name='dachgeschoss']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({ + max: (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length, + min: 1 + })); - // Flaeche - cy.get("input[name='flaeche']") - .should("have.attr", "type", "number") - .type(faker.number.int({ min: 50, max: 1000 }).toString()); + // Brennstoff und Einheit 1 + const brennstoffKombo = fuelList[faker.number.int({ min: 0, max: fuelList.length - 1 })]; - // Nutzflaeche - cy.get("input[name='nutzflaeche']") - .should("have.attr", "type", "number") - .type(faker.number.int({ min: 50, max: 1000 }).toString()); - - // Keller - cy.get("select[name='keller']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({ - max: (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length, - min: 1 - })); - - // Dachgeschoss - cy.get("select[name='dachgeschoss']").find("option:not([disabled])").should("have.length", (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length).parent().select(faker.number.int({ - max: (["BEHEIZT", "NICHT_VORHANDEN", "UNBEHEIZT"] as Enums.Heizungsstatus[]).length, - min: 1 - })); - - // Brennstoff und Einheit 1 - const brennstoffKombo = fuelList[faker.number.int({ min: 0, max: fuelList.length - 1 })]; - - cy.get("select[name='brennstoff_1']").select(brennstoffKombo[0]); - cy.get("select[name='einheit_1']").select(brennstoffKombo[1]); - - let availableDates = []; - const startDate = moment() - .subtract(4, "years") - .subtract(6, "months"); - const endDate = moment().subtract(3, "years"); - - for (let m = moment(startDate); m.isBefore(endDate); m.add(1, "month")) { - availableDates.push({ - year: m.year(), - month: m.month(), - }); - } - - // Verbrauchszeitraum - cy.get("select[name='energieverbrauch_zeitraum_jahr']").select(availableDates[0].year.toString()); - cy.get("select[name='energieverbrauch_zeitraum_monat']").select(availableDates[0].month.toString()); - - - // Verbrauch - cy.get("input[name='verbrauch_1']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); - cy.get("input[name='verbrauch_2']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); - cy.get("input[name='verbrauch_3']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); + cy.get("select[name='brennstoff_1']").select(brennstoffKombo[0]); + cy.get("select[name='einheit_1']").select(brennstoffKombo[1]); + let availableDates = []; + const startDate = moment() + .subtract(4, "years") + .subtract(6, "months"); + const endDate = moment().subtract(3, "years"); - const zusaetzlicheHeizquelle = Math.random() > 0.5; + for (let m = moment(startDate); m.isBefore(endDate); m.add(1, "month")) { + availableDates.push({ + year: m.year(), + month: m.month(), + }); + } - if (zusaetzlicheHeizquelle) { - cy.get("[data-cy='zusaetzliche_heizquelle']").check(); + // Verbrauchszeitraum + cy.get("select[name='energieverbrauch_zeitraum_jahr']").select(availableDates[0].year.toString()); + cy.get("select[name='energieverbrauch_zeitraum_monat']").select(availableDates[0].month.toString()); - // Brennstoff und Einheit 2 - const brennstoffKombo2 = fuelList[faker.number.int({ min: 0, max: fuelList.length - 1 })]; - - cy.get("[data-cy='brennstoff_2']").select(brennstoffKombo2[0], { force: true }); - cy.get("[data-cy='einheit_2']").select(brennstoffKombo2[1], { force: true }); // Verbrauch - cy.get("input[name='verbrauch_4']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); - cy.get("input[name='verbrauch_5']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); - cy.get("input[name='verbrauch_6']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); - } + cy.get("input[name='verbrauch_1']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); + cy.get("input[name='verbrauch_2']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); + cy.get("input[name='verbrauch_3']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); - // Warmwasser enthalten und bekannt - const warmwasserEnthalten = Math.random() > 0.5; - const anteilBekannt = Math.random() > 0.5; + + const zusaetzlicheHeizquelle = Math.random() > 0.5; - if (warmwasserEnthalten) { - cy.get("input[name='warmwasser_enthalten']").check(); + if (zusaetzlicheHeizquelle) { + cy.get("[data-cy='zusaetzliche_heizquelle']").check(); - if (anteilBekannt) { - // Der Anteil ist bekannt, wir müssen ihn also angeben. - cy.get("input[name='warmwasser_anteil_bekannt']").check(); + // Brennstoff und Einheit 2 + const brennstoffKombo2 = fuelList[faker.number.int({ min: 0, max: fuelList.length - 1 })]; - cy.get("input[name='anteil_warmwasser_1']").type(faker.number.int({ min: 0, max: 50 }).toString()); + cy.get("[data-cy='brennstoff_2']").select(brennstoffKombo2[0], { force: true }); + cy.get("[data-cy='einheit_2']").select(brennstoffKombo2[1], { force: true }); - if (zusaetzlicheHeizquelle) { - // Zusätzliche Heizquelle existiert, also müssen wir auch hier den Anteil angeben. - cy.get("input[name='anteil_warmwasser_2']").type(faker.number.int({ min: 0, max: 50 }).toString(), {force: true}); + // Verbrauch + cy.get("input[name='verbrauch_4']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); + cy.get("input[name='verbrauch_5']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); + cy.get("input[name='verbrauch_6']").type(faker.number.int({ min: 4000, max: 15000 }).toString(), { force: true }); + } + + // Warmwasser enthalten und bekannt + const warmwasserEnthalten = Math.random() > 0.5; + const anteilBekannt = Math.random() > 0.5; + + if (warmwasserEnthalten) { + cy.get("input[name='warmwasser_enthalten']").check(); + + if (anteilBekannt) { + // Der Anteil ist bekannt, wir müssen ihn also angeben. + cy.get("input[name='warmwasser_anteil_bekannt']").check(); + + cy.get("input[name='anteil_warmwasser_1']").type(faker.number.int({ min: 0, max: 50 }).toString()); + + if (zusaetzlicheHeizquelle) { + // Zusätzliche Heizquelle existiert, also müssen wir auch hier den Anteil angeben. + cy.get("input[name='anteil_warmwasser_2']").type(faker.number.int({ min: 0, max: 50 }).toString(), {force: true}); + } } } - } - // Alternative Energieversorgungssysteme - if (Math.random() > 0.5) cy.get("input[name='alternative_heizung']").check(); - if (Math.random() > 0.5) cy.get("input[name='alternative_warmwasser']").check(); - if (Math.random() > 0.5) cy.get("input[name='alternative_lueftung']").check(); - if (Math.random() > 0.5) cy.get("input[name='alternative_kuehlung']").check(); + // Alternative Energieversorgungssysteme + if (Math.random() > 0.5) cy.get("input[name='alternative_heizung']").check(); + if (Math.random() > 0.5) cy.get("input[name='alternative_warmwasser']").check(); + if (Math.random() > 0.5) cy.get("input[name='alternative_lueftung']").check(); + if (Math.random() > 0.5) cy.get("input[name='alternative_kuehlung']").check(); - // Gebäudetyp - cy.get("select[name='gebaeudetyp']").then(($dropdown) => { - const options = $dropdown.find('option'); - // Select the option at the random index - cy.get("select[name='gebaeudetyp']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + // Gebäudetyp + cy.get("select[name='gebaeudetyp']").then(($dropdown) => { + const options = $dropdown.find('option'); + // Select the option at the random index + cy.get("select[name='gebaeudetyp']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + }); + + // Gebäudeteil + cy.get("select[name='gebaeudeteil']").then(($dropdown) => { + const options = $dropdown.find('option'); + // Select the option at the random index + cy.get("select[name='gebaeudeteil']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + }); + + // Lüftung + cy.get("select[name='lueftung']").then(($dropdown) => { + const options = $dropdown.find('option'); + // Select the option at the random index + cy.get("select[name='lueftung']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); + }); + + // Kühlung + cy.get("select[name='kuehlung']").then(($dropdown) => { + const options = $dropdown.find('option'); + // Select the option at the random index + cy.get("select[name='kuehlung']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string, { force: true }); + }); + + // Leerstand + cy.get("input[name='leerstand']").should("have.attr", "type", "number").type(faker.number.int({ min: 0, max: 30 }).toString()); + + // Heizungsanlage Daten + if (Math.random() > 0.5) cy.get("[data-cy='zentralheizung']").check(); + if (Math.random() > 0.5) cy.get("[data-cy='einzelofen']").check(); + if (Math.random() > 0.5) cy.get("[data-cy='durchlauf_erhitzer']").check(); + if (Math.random() > 0.5) cy.get("[data-cy='standard_kessel']").check(); + if (Math.random() > 0.5) cy.get("[data-cy='solarsystem_warmwasser']").check(); + if (Math.random() > 0.5) cy.get("[data-cy='waermepumpe']").check(); + if (Math.random() > 0.5) cy.get("[data-cy='niedertemperatur_kessel']").check(); + if (Math.random() > 0.5) cy.get("[data-cy='brennwert_kessel']").check(); + if (Math.random() > 0.5) cy.get("[data-cy='warmwasser_rohre_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("[data-cy='heizungsrohre_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("[data-cy='zirkulation']").check(); + // if (Math.random() > 0.5) cy.get("[data-cy='raum_temperatur_regler']").check(); + + // Heizungsanlage Bilder + cy.get("input[name='heizung_image']").should("have.attr", "type", "file").attachFile("images/heizungsanlage/1.jpeg", { subjectType: "input" }); + cy.get("input[name='heizung_image']").should("have.attr", "type", "file").attachFile("images/heizungsanlage/2.jpeg", { subjectType: "input" }); + + // Fenster Daten + if (Math.random() > 0.5) cy.get("input[name='einfach_verglasung']").check(); + if (Math.random() > 0.5) cy.get("input[name='doppel_verglasung']").check(); + if (Math.random() > 0.5) cy.get("input[name='isolier_verglasung']").check(); + if (Math.random() > 0.5) cy.get("input[name='dreifach_verglasung']").check(); + if (Math.random() > 0.5) cy.get("input[name='fenster_dicht']").check(); + if (Math.random() > 0.5) cy.get("input[name='fenster_teilweise_undicht']").check(); + if (Math.random() > 0.5) cy.get("input[name='tueren_dicht']").check(); + if (Math.random() > 0.5) cy.get("input[name='tueren_undicht']").check(); + if (Math.random() > 0.5) cy.get("input[name='rolllaeden_kaesten_gedaemmt']").check(); + + // Fenster Bilder + cy.get("input[name='fenster_image']").should("have.attr", "type", "file").attachFile("images/fenster/1.jpeg", { subjectType: "input" }); + cy.get("input[name='fenster_image']").should("have.attr", "type", "file").attachFile("images/fenster/2.jpeg", { subjectType: "input" }); + + // Wärmedämmung Daten + if (Math.random() > 0.5) cy.get("input[name='aussenwand_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("input[name='keller_wand_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("input[name='keller_decke_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("input[name='dachgeschoss_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("input[name='oberste_geschossdecke_gedaemmt']").check(); + if (Math.random() > 0.5) cy.get("input[name='oberste_geschossdecke_min_12cm_gedaemmt']").check(); + + // Wärmedämmung Bilder + cy.get("input[name='daemmung_image']").should("have.attr", "type", "file").attachFile("images/daemmung/1.jpeg", { subjectType: "input" }); + cy.get("input[name='daemmung_image']").should("have.attr", "type", "file").attachFile("images/daemmung/2.jpeg", { subjectType: "input" }); + + // Gebäude Bild + cy.get("input[name='gebaeude_image']").should("have.attr", "type", "file").attachFile("images/gebaeude/1.jpeg", { subjectType: "input" }); + + // Jetzt können wir den Verbrauchsausweis erstellen. + cy.get("form[data-cy='ausweis'] button[data-cy='weiter']").click({ force: true }); + + cy.url().should("contain", "/kundendaten"); + + cy.get("input[name='telefon']").should("have.attr", "type", "text").type(telefon); + // Rechnung + if (preLogin) { + cy.get("input[name='rechnung_empfaenger']").should("have.attr", "type", "text").should("contain.value", `${vorname} ${nachname}`); + cy.get("input[name='vorname']").should("have.attr", "type", "text").should("contain.value", vorname); + cy.get("input[name='name']").should("have.attr", "type", "text").should("contain.value", nachname); + cy.get("input[name='rechnung_email']").should("have.attr", "type", "email").should("contain.value", email); + } else { + cy.get("input[name='rechnung_empfaenger']").should("have.attr", "type", "text").type(`${vorname} ${nachname}`); + cy.get("input[name='vorname']").should("have.attr", "type", "text").type(vorname); + cy.get("input[name='name']").should("have.attr", "type", "text").type(nachname); + cy.get("input[name='rechnung_email']").should("have.attr", "type", "email").type(email); + } + cy.get("input[name='rechnung_strasse']").should("have.attr", "type", "text").type(strasse); + cy.get("input[name='rechnung_plz']").should("have.attr", "type", "text").type(plz as string); + cy.get("[data-cy='plz-container']").children().first().click() + + cy.get("[data-cy='paypal']").click() + + cy.get("button[data-cy='bestellen']").click(); + + if (!preLogin) { + cy["form:signup"](email, passwort, vorname, nachname) + } + + cy.origin('https://www.mollie.com', () => { + // Jetzt sind wir auf der Mollie Seite, dort wählen wir den "paid" status aus + cy.get("input[type='radio'][name='final_state'][value='paid']").check(); + // Da wird unser Test fehlschlagen, da die localhost domain von Mollie aus nicht erreichbar ist. + }) }); - - // Gebäudeteil - cy.get("select[name='gebaeudeteil']").then(($dropdown) => { - const options = $dropdown.find('option'); - // Select the option at the random index - cy.get("select[name='gebaeudeteil']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); - }); - - // Lüftung - cy.get("select[name='lueftung']").then(($dropdown) => { - const options = $dropdown.find('option'); - // Select the option at the random index - cy.get("select[name='lueftung']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string); - }); - - // Kühlung - cy.get("select[name='kuehlung']").then(($dropdown) => { - const options = $dropdown.find('option'); - // Select the option at the random index - cy.get("select[name='kuehlung']").select(options.eq(faker.number.int({ min: 1, max: options.length - 1 })).val() as string, { force: true }); - }); - - // Leerstand - cy.get("input[name='leerstand']").should("have.attr", "type", "number").type(faker.number.int({ min: 0, max: 30 }).toString()); - - // Heizungsanlage Daten - if (Math.random() > 0.5) cy.get("[data-cy='zentralheizung']").check(); - if (Math.random() > 0.5) cy.get("[data-cy='einzelofen']").check(); - if (Math.random() > 0.5) cy.get("[data-cy='durchlauf_erhitzer']").check(); - if (Math.random() > 0.5) cy.get("[data-cy='standard_kessel']").check(); - if (Math.random() > 0.5) cy.get("[data-cy='solarsystem_warmwasser']").check(); - if (Math.random() > 0.5) cy.get("[data-cy='waermepumpe']").check(); - if (Math.random() > 0.5) cy.get("[data-cy='niedertemperatur_kessel']").check(); - if (Math.random() > 0.5) cy.get("[data-cy='brennwert_kessel']").check(); - if (Math.random() > 0.5) cy.get("[data-cy='warmwasser_rohre_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("[data-cy='heizungsrohre_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("[data-cy='zirkulation']").check(); - // if (Math.random() > 0.5) cy.get("[data-cy='raum_temperatur_regler']").check(); - - // Heizungsanlage Bilder - cy.get("input[name='heizung_image']").should("have.attr", "type", "file").attachFile("images/heizungsanlage/1.jpeg", { subjectType: "input" }); - cy.get("input[name='heizung_image']").should("have.attr", "type", "file").attachFile("images/heizungsanlage/2.jpeg", { subjectType: "input" }); - - // Fenster Daten - if (Math.random() > 0.5) cy.get("input[name='einfach_verglasung']").check(); - if (Math.random() > 0.5) cy.get("input[name='doppel_verglasung']").check(); - if (Math.random() > 0.5) cy.get("input[name='isolier_verglasung']").check(); - if (Math.random() > 0.5) cy.get("input[name='dreifach_verglasung']").check(); - if (Math.random() > 0.5) cy.get("input[name='fenster_dicht']").check(); - if (Math.random() > 0.5) cy.get("input[name='fenster_teilweise_undicht']").check(); - if (Math.random() > 0.5) cy.get("input[name='tueren_dicht']").check(); - if (Math.random() > 0.5) cy.get("input[name='tueren_undicht']").check(); - if (Math.random() > 0.5) cy.get("input[name='rolllaeden_kaesten_gedaemmt']").check(); - - // Fenster Bilder - cy.get("input[name='fenster_image']").should("have.attr", "type", "file").attachFile("images/fenster/1.jpeg", { subjectType: "input" }); - cy.get("input[name='fenster_image']").should("have.attr", "type", "file").attachFile("images/fenster/2.jpeg", { subjectType: "input" }); - - // Wärmedämmung Daten - if (Math.random() > 0.5) cy.get("input[name='aussenwand_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("input[name='keller_wand_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("input[name='keller_decke_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("input[name='dachgeschoss_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("input[name='oberste_geschossdecke_gedaemmt']").check(); - if (Math.random() > 0.5) cy.get("input[name='oberste_geschossdecke_min_12cm_gedaemmt']").check(); - - // Wärmedämmung Bilder - cy.get("input[name='daemmung_image']").should("have.attr", "type", "file").attachFile("images/daemmung/1.jpeg", { subjectType: "input" }); - cy.get("input[name='daemmung_image']").should("have.attr", "type", "file").attachFile("images/daemmung/2.jpeg", { subjectType: "input" }); - - // Gebäude Bild - cy.get("input[name='gebaeude_image']").should("have.attr", "type", "file").attachFile("images/gebaeude/1.jpeg", { subjectType: "input" }); - - // Jetzt können wir den Verbrauchsausweis erstellen. - cy.get("form[data-cy='ausweis'] button[data-cy='weiter']").click({ force: true }); - - cy.url().should("contain", "/kundendaten"); - - cy.get("input[name='telefon']").should("have.attr", "type", "text").type(telefon); - // Rechnung - if (preLogin) { - cy.get("input[name='rechnung_empfaenger']").should("have.attr", "type", "text").should("contain.value", `${vorname} ${nachname}`); - cy.get("input[name='vorname']").should("have.attr", "type", "text").should("contain.value", vorname); - cy.get("input[name='name']").should("have.attr", "type", "text").should("contain.value", nachname); - cy.get("input[name='rechnung_email']").should("have.attr", "type", "email").should("contain.value", email); - } else { - cy.get("input[name='rechnung_empfaenger']").should("have.attr", "type", "text").type(`${vorname} ${nachname}`); - cy.get("input[name='vorname']").should("have.attr", "type", "text").type(vorname); - cy.get("input[name='name']").should("have.attr", "type", "text").type(nachname); - cy.get("input[name='rechnung_email']").should("have.attr", "type", "email").type(email); - } - cy.get("input[name='rechnung_strasse']").should("have.attr", "type", "text").type(strasse); - cy.get("input[name='rechnung_plz']").should("have.attr", "type", "text").type(plz); - cy.get("[data-cy='plz-container']").children().first().click() - - cy.get("[data-cy='paypal']").click() - - cy.get("button[data-cy='bestellen']").click(); - - if (!preLogin) { - cy.get("a[data-cy='registrieren']").should("be.visible").click(); - - // Wir sind jetzt registriert und können uns nun einloggen. - // Die Email sollte automatisch eingetragen sein, da wir uns gerade registriert haben. - cy.get("form[name='signup'] input[name='vorname']").should("be.visible").should("have.attr", "type", "text").type(vorname); - cy.get("form[name='signup'] input[name='nachname']").should("be.visible").should("have.attr", "type", "text").type(nachname); - cy.get("form[name='signup'] input[name='email']").should("be.visible").should("have.attr", "type", "email").should("contain.value", email); - cy.get("form[name='signup'] input[name='passwort']").should("be.visible").should("have.attr", "type", "password").type(passwort); - - cy.intercept({ method: "PUT", url: "**/api/user" }).as("signup") - cy.get("form[name='signup'] button[type='submit']").click(); - cy.wait("@signup") - cy.get("form[name='login'] button[type='submit']").click(); - } - - cy.origin('https://www.mollie.com', () => { - // Jetzt sind wir auf der Mollie Seite, dort wählen wir den "paid" status aus - cy.get("input[type='radio'][name='final_state'][value='paid']").check(); - // Da wird unser Test fehlschlagen, da die localhost domain von Mollie aus nicht erreichbar ist. - }) }); }); diff --git a/src/cypress/support/commands.ts b/src/cypress/support/commands.ts index 71650262..3fb78854 100644 --- a/src/cypress/support/commands.ts +++ b/src/cypress/support/commands.ts @@ -30,11 +30,28 @@ Cypress.Commands.add("signup", (email, passwort, vorname, name) => { cy.url().should("include", "/auth/login") }) +Cypress.Commands.add("form:signup", (email, passwort, vorname, name) => { + cy.get("a[data-cy='registrieren']").should("be.visible").click(); + + // Wir sind jetzt registriert und können uns nun einloggen. + // Die Email sollte automatisch eingetragen sein, da wir uns gerade registriert haben. + cy.get("form[name='signup'] input[name='vorname']").should("be.visible").should("have.attr", "type", "text").type(vorname); + cy.get("form[name='signup'] input[name='nachname']").should("be.visible").should("have.attr", "type", "text").type(name); + cy.get("form[name='signup'] input[name='email']").should("be.visible").should("have.attr", "type", "email").should("contain.value", email); + cy.get("form[name='signup'] input[name='passwort']").should("be.visible").should("have.attr", "type", "password").type(passwort); + + cy.intercept({ method: "PUT", url: "**/api/user" }).as("signup") + cy.get("form[name='signup'] button[type='submit']").click(); + cy.wait("@signup") + cy.get("form[name='login'] button[type='submit']").click(); +}) + declare global { namespace Cypress { interface Chainable { login(email: string, passwort: string): Chainable signup(email: string, passwort: string, vorname: string, name: string): Chainable + "form:signup"(email: string, passwort: string, vorname: string, name: string): Chainable } } } \ No newline at end of file diff --git a/src/lib/server/db.ts b/src/lib/server/db.ts index a1d700cc..bf628b9d 100644 --- a/src/lib/server/db.ts +++ b/src/lib/server/db.ts @@ -1,4 +1,4 @@ -import { Aufnahme, BedarfsausweisGewerbe, BedarfsausweisWohnen, Bild, Objekt, prisma, Unterlage, VerbrauchsausweisGewerbe, VerbrauchsausweisWohnen } from "./prisma.js"; +import { Aufnahme, BedarfsausweisGewerbe, BedarfsausweisWohnen, Bild, GEGNachweisGewerbe, GEGNachweisWohnen, Objekt, prisma, Unterlage, VerbrauchsausweisGewerbe, VerbrauchsausweisWohnen } from "./prisma.js"; export async function getVerbrauchsausweisWohnen(id: string): Promise { return await prisma.verbrauchsausweisWohnen.findUnique({ @@ -32,6 +32,22 @@ export async function getBedarfsausweisGewerbe(id: string): Promise { + return await prisma.gEGNachweisWohnen.findUnique({ + where: { + id + } + }) +} + +export async function getGEGNachweisGewerbe(id: string): Promise { + return await prisma.gEGNachweisGewerbe.findUnique({ + where: { + id + } + }) +} + export async function getAufnahme(id: string): Promise { return await prisma.aufnahme.findUnique({ where: { diff --git a/src/modules/angebot-anfragen/BedarfsausweisGewerbeModule.svelte b/src/modules/angebot-anfragen/BedarfsausweisGewerbeModule.svelte index c9aae1d6..852fe40a 100644 --- a/src/modules/angebot-anfragen/BedarfsausweisGewerbeModule.svelte +++ b/src/modules/angebot-anfragen/BedarfsausweisGewerbeModule.svelte @@ -111,7 +111,7 @@ diff --git a/src/modules/angebot-anfragen/GEGNachweisWohnenModule.svelte b/src/modules/angebot-anfragen/GEGNachweisWohnenModule.svelte index 882e5e24..1bb41b8f 100644 --- a/src/modules/angebot-anfragen/GEGNachweisWohnenModule.svelte +++ b/src/modules/angebot-anfragen/GEGNachweisWohnenModule.svelte @@ -9,64 +9,50 @@ BildClient, } from "#components/Ausweis/types.js"; import Bereich from "#components/labels/Bereich.svelte"; - import { Enums } from "#lib/client/prisma.js"; + import { Enums, Unterlage } from "#lib/client/prisma.js"; import InputLabel from "#components/labels/InputLabel.svelte"; import HelpLabel from "#components/labels/HelpLabel.svelte"; import Progressbar from "#components/Ausweis/Progressbar.svelte"; import FileGrid from "#components/FileGrid.svelte"; import ButtonWeiterHilfe from "#components/Ausweis/ButtonWeiterHilfe.svelte"; import GEGAusweisart from "#components/GEGNachweis/GEGAusweisart.svelte"; + import moment from "moment"; export let nachweis: GEGNachweisWohnenClient; export let objekt: ObjektClient; export let aufnahme: AufnahmeClient; export let user: BenutzerClient = {} as BenutzerClient; export let bilder: BildClient[] = []; - export let plaene: UnterlageClient[] = []; - export let unterlagen: UnterlageClient[] = []; + export let plaene: Unterlage[] = []; + export let unterlagen: Unterlage[] = []; + export let nachweistyp: Enums.AusweisTyp = Enums.AusweisTyp.Standard; + export let id: string | null; - if (Object.keys(nachweis).length === 0) { - const localStorageAusweis = localStorage.getItem( - "geg-nachweis-wohnen.ausweis" - ); - if (localStorageAusweis) { - nachweis = JSON.parse(localStorageAusweis); + if ((user && user.rolle !== Enums.BenutzerRolle.ADMIN) && !id && (!nachweis.updated_at || moment(localStorage.getItem("geg-nachweis-wohnen.updated_at") || new Date()).isAfter(nachweis.updated_at))) { + const localStorageNachweis = localStorage.getItem("geg-nachweis-wohnen.ausweis"); + if (localStorageNachweis) { + nachweis = JSON.parse(localStorageNachweis) + nachweis.nachweistyp = nachweistyp; } - } - if (Object.keys(aufnahme).length === 0) { - const localStorageAufnahme = localStorage.getItem( - "geg-nachweis-wohnen.aufnahme" - ); + const localStorageAufnahme = localStorage.getItem("geg-nachweis-wohnen.aufnahme"); if (localStorageAufnahme) { - aufnahme = JSON.parse(localStorageAufnahme); + aufnahme = JSON.parse(localStorageAufnahme) } - } - if (Object.keys(objekt).length === 0) { - const localStorageObjekt = localStorage.getItem( - "geg-nachweis-wohnen.objekt" - ); + const localStorageObjekt = localStorage.getItem("geg-nachweis-wohnen.objekt"); if (localStorageObjekt) { - objekt = JSON.parse(localStorageObjekt); + objekt = JSON.parse(localStorageObjekt) } - } - if (Object.keys(bilder).length === 0) { - const localStorageBilder = localStorage.getItem( - "geg-nachweis-wohnen.bilder" - ); + const localStorageBilder = localStorage.getItem("geg-nachweis-wohnen.bilder"); if (localStorageBilder) { - bilder = JSON.parse(localStorageBilder); + bilder = JSON.parse(localStorageBilder) } - } - if (Object.keys(unterlagen).length === 0) { - const localStorageUnterlagen = localStorage.getItem( - "geg-nachweis-wohnen.unterlagen" - ); + const localStorageUnterlagen = localStorage.getItem("geg-nachweis-wohnen.unterlagen"); if (localStorageUnterlagen) { - unterlagen = JSON.parse(localStorageUnterlagen); + unterlagen = JSON.parse(localStorageUnterlagen) } } @@ -110,6 +96,7 @@ {ausweisart} {anliegen} steps={["Gebäudedaten", "Kundendaten", "Anfragebestätigung"]} + ausweistyp={nachweistyp} /> @@ -121,7 +108,7 @@ diff --git a/src/pages/angebot-anfragen/geg-nachweis-wohnen-anfragen/index.astro b/src/pages/angebot-anfragen/geg-nachweis-wohnen-anfragen/index.astro index e8718bea..8fc53246 100644 --- a/src/pages/angebot-anfragen/geg-nachweis-wohnen-anfragen/index.astro +++ b/src/pages/angebot-anfragen/geg-nachweis-wohnen-anfragen/index.astro @@ -1,90 +1,87 @@ --- import AusweisLayout from "#layouts/AusweisLayoutDaten.astro"; -import { AufnahmeClient, BildClient, GEGNachweisWohnenClient, ObjektClient, UnterlageClient } from "#components/Ausweis/types"; -import { createCaller } from "src/astro-typesafe-api-caller"; -import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js"; -import { validateAccessTokenServer } from "#server/lib/validateAccessToken.js"; import GEGNachweisWohnenModule from "#modules/angebot-anfragen/GEGNachweisWohnenModule.svelte"; +import { getGEGNachweisWohnen, getAufnahme, getObjekt, getBilder } from "#lib/server/db"; +import { Enums, Aufnahme, Objekt, Bild, GEGNachweisWohnen, Unterlage } from "#lib/server/prisma"; +import { getCurrentUser } from "#lib/server/user"; +import { getUnterlagen } from "#lib/server/db"; -const uid = Astro.url.searchParams.get("uid"); -let nachweis: GEGNachweisWohnenClient = {} as GEGNachweisWohnenClient; -let aufnahme: AufnahmeClient = {} as AufnahmeClient; -let objekt: ObjektClient = {} as ObjektClient; -let bilder: BildClient[] = [] -let unterlagen: UnterlageClient[] = [] +const id = Astro.url.searchParams.get("id"); +const aufnahme_id = Astro.url.searchParams.get("aufnahme") +let ausweistyp = Astro.url.searchParams.get("ausweistyp") as Enums.AusweisTyp || Enums.AusweisTyp.Standard; -const valid = validateAccessTokenServer(Astro); +let nachweis: GEGNachweisWohnen = {} as GEGNachweisWohnen; +let aufnahme: Aufnahme = {} as Aufnahme; +let objekt: Objekt = {} as Objekt; +let bilder: Bild[] = [] +let unterlagen: Unterlage[] = [] -const caller = createCaller(Astro); +const user = await getCurrentUser(Astro) -if (uid) { - if (!valid) { +if (id) { + if (!user) { return Astro.redirect( `/auth/login?redirect=${Astro.url.toString()}` ); } - try { - nachweis = await caller["geg-nachweis-wohnen"]._uid.GET.fetch(null, { - headers: { - authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - }, - params: { - uid - } - }); + nachweis = await getGEGNachweisWohnen(id) as GEGNachweisWohnen - aufnahme = await caller.aufnahme._uid.GET.fetch(null, { - headers: { - authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - }, - params: { - uid: nachweis.uid_aufnahme - } - }) - - objekt = await caller.objekt._uid.GET.fetch(null, { - headers: { - authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - }, - params: { - uid: nachweis.uid_objekt - } - }) - - bilder = await caller.aufnahme._uid.bilder.GET.fetch(null, { - headers: { - authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - }, - params: { - uid: nachweis.uid_aufnahme - } - }) - - unterlagen = await caller.aufnahme._uid.unterlagen.GET.fetch(null, { - headers: { - authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - }, - params: { - uid: nachweis.uid_aufnahme - } - }) - - if (!nachweis) { - // Der Ausweis scheint nicht zu existieren. - // Wir leiten auf die generische Ausweisseite ohne UID weiter. - return Astro.redirect( - "/angebot-anfragen/geg-nachweis-wohnen-anfragen" - ); - } - } catch(e) { + if (!nachweis || nachweis.benutzer_id !== user.id) { + // Der Ausweis scheint nicht zu existieren. + // Wir leiten auf die generische Ausweisseite ohne ID weiter. return Astro.redirect( - "/angebot-anfragen/geg-nachweis-wohnen-anfragen" + "/energieausweis-erstellen/verbrauchsausweis-wohngebaeude" + ); + } + + aufnahme = await getAufnahme(nachweis.aufnahme_id) as Aufnahme + + if (!aufnahme) { + // Die Aufnahme existiert nicht, das sollte eigentlich nicht passieren aber so können wir nicht fortfahren. + return Astro.redirect( + "/energieausweis-erstellen/verbrauchsausweis-wohngebaeude" + ); + } + + objekt = await getObjekt(aufnahme.objekt_id) as Objekt + + if (!objekt) { + // Das Objekt existiert nicht, das sollte eigentlich nicht passieren aber so können wir nicht fortfahren. + return Astro.redirect( + "/energieausweis-erstellen/verbrauchsausweis-wohngebaeude" + ); + } + + bilder = await getBilder(aufnahme.id); + unterlagen = await getUnterlagen(aufnahme.id); +} else if (aufnahme_id) { + if (!user) { + return Astro.redirect( + `/auth/login?redirect=${Astro.url.toString()}` + ); + } + + aufnahme = await getAufnahme(nachweis.aufnahme_id) as Aufnahme + + if (!aufnahme) { + // Die Aufnahme existiert wohl nicht. + return Astro.redirect( + "/energieausweis-erstellen/verbrauchsausweis-wohngebaeude" + ); + } + + objekt = await getObjekt(aufnahme.objekt_id) as Objekt + + if (!objekt) { + // Das Objekt existiert nicht. + return Astro.redirect( + "/energieausweis-erstellen/verbrauchsausweis-wohngebaeude" ); } } --- - + diff --git a/src/pages/api/bedarfsausweis-gewerbe/[uid].ts b/src/pages/api/bedarfsausweis-gewerbe/[id].ts similarity index 100% rename from src/pages/api/bedarfsausweis-gewerbe/[uid].ts rename to src/pages/api/bedarfsausweis-gewerbe/[id].ts diff --git a/src/pages/api/geg-nachweis-gewerbe/[uid].ts b/src/pages/api/geg-nachweis-gewerbe/[id].ts similarity index 100% rename from src/pages/api/geg-nachweis-gewerbe/[uid].ts rename to src/pages/api/geg-nachweis-gewerbe/[id].ts diff --git a/src/pages/api/geg-nachweis-gewerbe/index.ts b/src/pages/api/geg-nachweis-gewerbe/index.ts index 612350a0..f0e441d1 100644 --- a/src/pages/api/geg-nachweis-gewerbe/index.ts +++ b/src/pages/api/geg-nachweis-gewerbe/index.ts @@ -1,4 +1,6 @@ import { UUidWithPrefix } from "#components/Ausweis/types.js"; +import { VALID_UUID_PREFIXES } from "#lib/constants.js"; +import { generatePrefixedId } from "#lib/db.js"; import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js"; import { prisma } from "#lib/server/prisma.js"; import { APIError, defineApiRoute } from "astro-typesafe-api/server"; @@ -16,24 +18,25 @@ export const PUT = defineApiRoute({ nachweis: GEGNachweisGewerbeSchema.omit({ id: true, benutzer_id: true, - uid: true, aufnahme_id: true, + created_at: true, + updated_at: true, geg_einpreisung_id: true, rechnung_id: true }), - uid_aufnahme: UUidWithPrefix + aufnahme_id: UUidWithPrefix }), output: z.object({ - uid: UUidWithPrefix, - objekt_uid: UUidWithPrefix, - aufnahme_uid: UUidWithPrefix, + id: UUidWithPrefix, + objekt_id: UUidWithPrefix, + aufnahme_id: UUidWithPrefix, }), headers: authorizationHeaders, middleware: authorizationMiddleware, async fetch(input, ctx, user) { const aufnahme = await prisma.aufnahme.findUnique({ where: { - uid: input.uid_aufnahme + id: input.aufnahme_id } }) @@ -44,8 +47,11 @@ export const PUT = defineApiRoute({ }) } + const id = generatePrefixedId(6, VALID_UUID_PREFIXES.GEGNachweisGewerbe) + const nachweis = await prisma.gEGNachweisGewerbe.create({ data: { + id, ...input.nachweis, benutzer: { connect: { @@ -59,13 +65,13 @@ export const PUT = defineApiRoute({ } }, select: { - uid: true, + id: true, aufnahme: { select: { - uid: true, + id: true, objekt: { select: { - uid: true, + id: true, }, }, }, @@ -74,9 +80,9 @@ export const PUT = defineApiRoute({ }); return { - uid: nachweis.uid, - objekt_uid: nachweis.aufnahme.objekt.uid, - aufnahme_uid: nachweis.aufnahme.uid, + id: nachweis.id, + objekt_id: nachweis.aufnahme.objekt.id, + aufnahme_id: nachweis.aufnahme.id, }; }, }); @@ -101,11 +107,11 @@ export const GET = defineApiRoute({ headers: authorizationHeaders, middleware: authorizationMiddleware, async fetch(input, context, user) { - const { uid } = context.params; + const { id } = context.params; const nachweis = await prisma.gEGNachweisGewerbe.findUnique({ where: { - uid, + id, }, include: { benutzer: true, @@ -115,7 +121,7 @@ export const GET = defineApiRoute({ include: { benutzer: { select: { - uid: true, + id: true, }, }, }, diff --git a/src/pages/api/geg-nachweis-wohnen/[uid].ts b/src/pages/api/geg-nachweis-wohnen/[id].ts similarity index 81% rename from src/pages/api/geg-nachweis-wohnen/[uid].ts rename to src/pages/api/geg-nachweis-wohnen/[id].ts index 4a6725a8..05b95b6b 100644 --- a/src/pages/api/geg-nachweis-wohnen/[uid].ts +++ b/src/pages/api/geg-nachweis-wohnen/[id].ts @@ -1,13 +1,15 @@ -import { GEGNachweisWohnenClient, OptionalNullable, UUidWithPrefix, ZodOverlap } from "#components/Ausweis/types.js"; +import { UUidWithPrefix } from "#components/Ausweis/types.js"; +import { VALID_UUID_PREFIXES } from "#lib/constants.js"; +import { generatePrefixedId } from "#lib/db.js"; import { exclude } from "#lib/exclude.js"; import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js"; -import { GEGNachweisWohnenSchema, prisma } from "#lib/server/prisma"; +import { prisma } from "#lib/server/prisma.js"; import { APIError, defineApiRoute } from "astro-typesafe-api/server"; +import { GEGNachweisWohnenSchema } from "src/generated/zod/gegnachweiswohnen.js"; import { z } from "zod"; export const PATCH = defineApiRoute({ input: GEGNachweisWohnenSchema.omit({ - uid: true, id: true, benutzer_id: true, geg_einpreisung_id: true, @@ -21,7 +23,7 @@ export const PATCH = defineApiRoute({ async fetch(input, ctx, user) { const objekt = await prisma.gEGNachweisWohnen.findUnique({ where: { - uid: ctx.params.uid, + id: ctx.params.id, benutzer: { id: user.id } @@ -37,7 +39,7 @@ export const PATCH = defineApiRoute({ await prisma.gEGNachweisWohnen.update({ where: { - uid: ctx.params.uid + id: ctx.params.id }, data: input }) @@ -51,9 +53,9 @@ export const DELETE = defineApiRoute({ headers: authorizationHeaders, middleware: authorizationMiddleware, async fetch(input, ctx, user) { - const { uid } = ctx.params; + const { id } = ctx.params; - if (!UUidWithPrefix.safeParse(uid).success) { + if (!UUidWithPrefix.safeParse(id).success) { throw new APIError({ code: "BAD_REQUEST", message: "UID konnte nicht verifiziert werden." @@ -64,7 +66,7 @@ export const DELETE = defineApiRoute({ // Dieser MUSS mit dem Nutzer verknüpft sein. const nachweis = await prisma.gEGNachweisWohnen.findUnique({ where: { - uid, + id, } }); @@ -111,10 +113,13 @@ export const DELETE = defineApiRoute({ } }) + const event_id = + // Wir erstellen ein Event, dass der Nachweis storniert wurde // Dann können wir das in der Historie anzeigen await prisma.event.create({ data: { + id: generatePrefixedId(6, VALID_UUID_PREFIXES.Event), title: "Nachweis storniert", description: ((user.rolle === "ADMIN") && (nachweis.benutzer_id !== user.id)) ? "Nachweis wurde von einem Administrator storniert." : "Nachweis wurde vom Besitzer storniert.", benutzer: { @@ -150,9 +155,9 @@ export const GET = defineApiRoute({ } }, output: GEGNachweisWohnenSchema.merge(z.object({ - uid_aufnahme: UUidWithPrefix, - uid_objekt: UUidWithPrefix, - uid_benutzer: UUidWithPrefix.optional() + aufnahme_id: UUidWithPrefix, + objekt_id: UUidWithPrefix, + benutzer_id: UUidWithPrefix.optional() })).omit({ id: true, aufnahme_id: true, @@ -160,32 +165,32 @@ export const GET = defineApiRoute({ }), middleware: authorizationMiddleware, async fetch(input, context, user) { - const { uid } = context.params; + const { id } = context.params; - if (!uid) { + if (!id) { throw new APIError({ code: "BAD_REQUEST", message: "Missing uid in request params" }) } - const Nachweis = await prisma.gEGNachweisWohnen.findUnique({ + const nachweis = await prisma.gEGNachweisWohnen.findUnique({ where: { - uid, + id, benutzer_id: user.id }, include: { benutzer: { select: { - uid: true + id: true } }, aufnahme: { select: { - uid: true, + id: true, objekt: { select: { - uid: true + id: true } } } @@ -193,7 +198,7 @@ export const GET = defineApiRoute({ } }); - if (!Nachweis) { + if (!nachweis) { // Falls wir den Nachweis nicht finden können, werfen wir einen Fehler throw new APIError({ code: "NOT_FOUND", @@ -202,10 +207,10 @@ export const GET = defineApiRoute({ } return { - uid_aufnahme: Nachweis.aufnahme.uid, - uid_objekt: Nachweis.aufnahme.objekt.uid, - uid_benutzer: Nachweis.benutzer?.uid, - ...exclude(Nachweis, ["id", "aufnahme_id", "benutzer_id", "aufnahme"]) + aufnahme_id: nachweis.aufnahme.id, + objekt_id: nachweis.aufnahme.objekt.id, + benutzer_id: nachweis.benutzer?.id, + ...exclude(nachweis, ["id", "aufnahme_id", "benutzer_id", "aufnahme"]) } }, }); diff --git a/src/pages/api/geg-nachweis-wohnen/index.ts b/src/pages/api/geg-nachweis-wohnen/index.ts index c8a8b968..f164233a 100644 --- a/src/pages/api/geg-nachweis-wohnen/index.ts +++ b/src/pages/api/geg-nachweis-wohnen/index.ts @@ -1,4 +1,6 @@ import { UUidWithPrefix } from "#components/Ausweis/types.js"; +import { VALID_UUID_PREFIXES } from "#lib/constants.js"; +import { generatePrefixedId } from "#lib/db.js"; import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js"; import { prisma } from "#lib/server/prisma.js"; import { APIError, defineApiRoute } from "astro-typesafe-api/server"; @@ -16,24 +18,25 @@ export const PUT = defineApiRoute({ nachweis: GEGNachweisWohnenSchema.omit({ id: true, benutzer_id: true, - uid: true, aufnahme_id: true, + updated_at: true, + created_at: true, geg_einpreisung_id: true, rechnung_id: true }), - uid_aufnahme: UUidWithPrefix + aufnahme_id: UUidWithPrefix }), output: z.object({ - uid: UUidWithPrefix, - objekt_uid: UUidWithPrefix, - aufnahme_uid: UUidWithPrefix, + id: UUidWithPrefix, + objekt_id: UUidWithPrefix, + aufnahme_id: UUidWithPrefix, }), headers: authorizationHeaders, middleware: authorizationMiddleware, async fetch(input, ctx, user) { const aufnahme = await prisma.aufnahme.findUnique({ where: { - uid: input.uid_aufnahme + id: input.aufnahme_id } }) @@ -44,8 +47,11 @@ export const PUT = defineApiRoute({ }) } + const id = generatePrefixedId(6, VALID_UUID_PREFIXES.GEGNachweisWohnen) + const nachweis = await prisma.gEGNachweisWohnen.create({ data: { + id, ...input.nachweis, benutzer: { connect: { @@ -59,13 +65,13 @@ export const PUT = defineApiRoute({ } }, select: { - uid: true, + id: true, aufnahme: { select: { - uid: true, + id: true, objekt: { select: { - uid: true, + id: true, }, }, }, @@ -74,9 +80,9 @@ export const PUT = defineApiRoute({ }); return { - uid: nachweis.uid, - objekt_uid: nachweis.aufnahme.objekt.uid, - aufnahme_uid: nachweis.aufnahme.uid, + id: nachweis.id, + objekt_id: nachweis.aufnahme.objekt.id, + aufnahme_id: nachweis.aufnahme.id, }; }, }); @@ -101,11 +107,11 @@ export const GET = defineApiRoute({ headers: authorizationHeaders, middleware: authorizationMiddleware, async fetch(input, context, user) { - const { uid } = context.params; + const { id } = context.params; const nachweis = await prisma.gEGNachweisGewerbe.findUnique({ where: { - uid, + id, }, include: { benutzer: true, @@ -115,7 +121,7 @@ export const GET = defineApiRoute({ include: { benutzer: { select: { - uid: true, + id: true, }, }, }, diff --git a/src/pages/api/rechnung/anfordern.ts b/src/pages/api/rechnung/anfordern.ts index 74c417b1..47393a7d 100644 --- a/src/pages/api/rechnung/anfordern.ts +++ b/src/pages/api/rechnung/anfordern.ts @@ -1,8 +1,10 @@ import { getAusweisartFromId, UUidWithPrefix } from "#components/Ausweis/types.js"; +import { VALID_UUID_PREFIXES } from "#lib/constants.js"; +import { generatePrefixedId } from "#lib/db.js"; import { omit } from "#lib/helpers.js"; import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js"; import { sendGEGAnforderungsMail } from "#lib/server/mail/geg-anfordern.js"; -import { Enums, GEGNachweisGewerbe, GEGNachweisWohnen, prisma } from "#lib/server/prisma.js"; +import { BedarfsausweisGewerbe, Enums, GEGNachweisGewerbe, GEGNachweisWohnen, prisma } from "#lib/server/prisma.js"; import { APIError, defineApiRoute } from "astro-typesafe-api/server"; import { GEGEinpreisungSchema } from "src/generated/zod/gegeinpreisung.js"; import { z } from "zod"; @@ -21,7 +23,7 @@ export const PUT = defineApiRoute({ const ausweisart = getAusweisartFromId(input.nachweis_id); let einpreisung; - let nachweis: GEGNachweisWohnen | GEGNachweisGewerbe; + let nachweis: GEGNachweisWohnen | GEGNachweisGewerbe | BedarfsausweisGewerbe; if (ausweisart === Enums.Ausweisart.GEGNachweisWohnen) { nachweis = await prisma.gEGNachweisWohnen.findUnique({ where: { @@ -55,9 +57,12 @@ export const PUT = defineApiRoute({ }) } + const id = generatePrefixedId(6, VALID_UUID_PREFIXES.GEGEinpreisung) + if (ausweisart === Enums.Ausweisart.GEGNachweisWohnen) { einpreisung = await prisma.gEGEinpreisung.create({ data: { + id, ...omit(input, ["nachweis_id"]), status: Enums.Einpreisungsstatus.open, benutzer: { @@ -75,6 +80,7 @@ export const PUT = defineApiRoute({ } else if (ausweisart === Enums.Ausweisart.GEGNachweisGewerbe) { einpreisung = await prisma.gEGEinpreisung.create({ data: { + id, ...omit(input, ["nachweis_id"]), status: Enums.Einpreisungsstatus.open, benutzer: { @@ -92,6 +98,7 @@ export const PUT = defineApiRoute({ } else if (ausweisart === Enums.Ausweisart.BedarfsausweisGewerbe) { einpreisung = await prisma.gEGEinpreisung.create({ data: { + id, ...omit(input, ["nachweis_id"]), status: Enums.Einpreisungsstatus.open, benutzer: { @@ -111,7 +118,7 @@ export const PUT = defineApiRoute({ await sendGEGAnforderungsMail(nachweis, user) return { - id: einpreisung.id + id } }, }) \ No newline at end of file diff --git a/src/pages/pdf/datenblatt.ts b/src/pages/pdf/datenblatt.ts index c3df0d51..f581e9f5 100644 --- a/src/pages/pdf/datenblatt.ts +++ b/src/pages/pdf/datenblatt.ts @@ -1,10 +1,8 @@ -import { AufnahmeClient, BenutzerClient, getAusweisartFromId, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js"; +import { BenutzerClient, getAusweisartFromId, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js"; import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js"; import { pdfDatenblattVerbrauchsausweisGewerbe } from "#lib/pdf/pdfDatenblattVerbrauchsausweisGewerbe.js"; import { pdfDatenblattVerbrauchsausweisWohnen } from "#lib/pdf/pdfDatenblattVerbrauchsausweisWohnen.js"; -import { pdfVerbrauchsausweisGewerbe } from "#lib/pdf/pdfVerbrauchsausweisGewerbe.js"; -import { pdfVerbrauchsausweisWohnen } from "#lib/pdf/pdfVerbrauchsausweisWohnen.js"; -import { Enums } from "#lib/client/prisma.js"; +import { Aufnahme, Benutzer, Bild, Enums, Objekt, VerbrauchsausweisGewerbe, VerbrauchsausweisWohnen } from "#lib/client/prisma.js"; import { APIRoute } from "astro"; import { createCaller } from "src/astro-typesafe-api-caller.js"; import { getS3File } from "#lib/s3.js"; @@ -20,11 +18,11 @@ export const GET: APIRoute = async (Astro) => { const ausweisart = getAusweisartFromId(ausweis_id) - let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | null = null; - let aufnahme: AufnahmeClient = {} as AufnahmeClient; - let objekt: ObjektClient = {} as ObjektClient; - let user: BenutzerClient = {} as BenutzerClient; - let bilder: UploadedGebaeudeBild[] = [] + let ausweis: VerbrauchsausweisWohnen | VerbrauchsausweisGewerbe | null = null; + let aufnahme: Aufnahme = {} as Aufnahme; + let objekt: Objekt = {} as Objekt; + let user: Benutzer = {} as Benutzer; + let bilder: Bild[] = [] if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) { ausweis = await getVerbrauchsausweisWohnen(ausweis_id)