diff --git a/cypress.config.ts b/cypress.config.ts index 0c24e21e..e6e1c1a1 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -9,7 +9,7 @@ export default defineConfig({ baseUrl: "http://localhost:3000", viewportHeight: 900, viewportWidth: 1660, - supportFile: false, + supportFile: fileURLToPath(new URL("./src/cypress/support/commands.ts", import.meta.url)), specPattern: "./src/cypress/e2e/**/*.{ts,js}", setupNodeEvents(on, config) { on("file:preprocessor", vitePreprocessor({ diff --git a/src/astro-typesafe-api-caller.ts b/src/astro-typesafe-api-caller.ts index ec71ff20..af572bf4 100644 --- a/src/astro-typesafe-api-caller.ts +++ b/src/astro-typesafe-api-caller.ts @@ -5,7 +5,6 @@ export const createCaller = createCallerFactory({ "klimafaktoren": await import("../src/pages/api/klimafaktoren.ts"), "postleitzahlen": await import("../src/pages/api/postleitzahlen.ts"), "unterlage": await import("../src/pages/api/unterlage.ts"), - "aufnahme": await import("../src/pages/api/aufnahme/index.ts"), "admin/ausstellen": await import("../src/pages/api/admin/ausstellen.ts"), "admin/bestellbestaetigung": await import("../src/pages/api/admin/bestellbestaetigung.ts"), "admin/erinnern": await import("../src/pages/api/admin/erinnern.ts"), @@ -14,6 +13,7 @@ export const createCaller = createCallerFactory({ "admin/registriernummer": await import("../src/pages/api/admin/registriernummer.ts"), "admin/stornieren": await import("../src/pages/api/admin/stornieren.ts"), "ausweise": await import("../src/pages/api/ausweise/index.ts"), + "aufnahme": await import("../src/pages/api/aufnahme/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"), diff --git a/src/cypress/e2e/VerbrauchsausweisWohnen/erstellen.cy.ts b/src/cypress/e2e/VerbrauchsausweisWohnen/erstellen.cy.ts index 86d1f1e6..a0ce8e9e 100644 --- a/src/cypress/e2e/VerbrauchsausweisWohnen/erstellen.cy.ts +++ b/src/cypress/e2e/VerbrauchsausweisWohnen/erstellen.cy.ts @@ -1,13 +1,27 @@ import fuelList from "#components/Ausweis/brennstoffListe.js"; import { faker } from "@faker-js/faker"; import { Enums } from "#lib/client/prisma.js"; - - import "cypress-file-upload" 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() + + const strasse = faker.location.streetAddress({ useFullAddress: true }) + const plz = faker.location.zipCode("#####") + + const preLogin = Math.random() > 0.5; + + if (preLogin) { + cy.signup(email, passwort, vorname, nachname) + cy.login(email, passwort) + } + cy.visit("/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"); cy.wait(2000); @@ -241,42 +255,42 @@ describe("Verbrauchsausweis erstellen Schritt 1", () => { 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}`); + 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("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(); + 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); + // 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.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 diff --git a/src/cypress/support/commands.ts b/src/cypress/support/commands.ts index 698b01a4..71650262 100644 --- a/src/cypress/support/commands.ts +++ b/src/cypress/support/commands.ts @@ -1,37 +1,40 @@ /// -// *********************************************** -// This example commands.ts shows you how to -// create various custom commands and overwrite -// existing commands. -// -// For more comprehensive examples of custom -// commands please read more here: -// https://on.cypress.io/custom-commands -// *********************************************** -// -// -// -- This is a parent command -- -// Cypress.Commands.add('login', (email, password) => { ... }) -// -// -// -- This is a child command -- -// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) -// -// -// -- This is a dual command -- -// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) -// -// -// -- This will overwrite an existing command -- -// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) -// -// declare global { -// namespace Cypress { -// interface Chainable { -// login(email: string, password: string): Chainable -// drag(subject: string, options?: Partial): Chainable -// dismiss(subject: string, options?: Partial): Chainable -// visit(originalFn: CommandOriginalFn, url: string, options: Partial): Chainable -// } -// } -// } \ No newline at end of file + +import { API_ACCESS_TOKEN_COOKIE_NAME, API_REFRESH_TOKEN_COOKIE_NAME } from "#lib/constants.js" + +Cypress.Commands.add("login", (email, passwort) => { + cy.visit("/auth/login") + + cy.get('input[name="email"]').type(email) + cy.get('input[name="passwort"]').type(passwort) + + cy.get('button[type="submit"]').click() + + cy.url().should("include", "/dashboard") + + // Wir sollten nun einen Access Token und Refresh Token in unseren Cookies sehen. + cy.getCookie(API_ACCESS_TOKEN_COOKIE_NAME).should("exist") + cy.getCookie(API_REFRESH_TOKEN_COOKIE_NAME).should("exist") +}) + +Cypress.Commands.add("signup", (email, passwort, vorname, name) => { + cy.visit("/auth/signup") + + cy.get('input[name="email"]').type(email) + cy.get('input[name="passwort"]').type(passwort) + cy.get('input[name="vorname"]').type(vorname) + cy.get('input[name="name"]').type(name) + + cy.get('button[type="submit"]').click() + + cy.url().should("include", "/auth/login") +}) + +declare global { + namespace Cypress { + interface Chainable { + login(email: string, passwort: string): Chainable + signup(email: string, passwort: string, vorname: string, name: string): Chainable + } + } +} \ No newline at end of file diff --git a/src/pages/dashboard/index.astro b/src/pages/dashboard/index.astro index 084d60c0..96b86f45 100644 --- a/src/pages/dashboard/index.astro +++ b/src/pages/dashboard/index.astro @@ -1,3 +1,4 @@ --- return Astro.redirect("/dashboard/objekte/1", 301); + --- \ No newline at end of file