From 59cceea7bd037e146ad8d610a6e8ec36b0ce291d Mon Sep 17 00:00:00 2001 From: jaggarnaut Date: Tue, 26 Nov 2024 17:11:17 +0100 Subject: [PATCH] moved data deletion to after each hook and refactored helper methods --- base/api/testHelperPerson.page.ts | 6 +++--- base/testHelperDeleteTestdata.ts | 17 +++++++++------ tests/Import.spec.ts | 36 ++++++++++++------------------- tests/Person.spec.ts | 4 ++-- tests/PersonBearbeiten.spec.ts | 4 ++-- tests/Profile.spec.ts | 4 ++-- tests/login.spec.ts | 4 ++-- 7 files changed, 36 insertions(+), 39 deletions(-) diff --git a/base/api/testHelperPerson.page.ts b/base/api/testHelperPerson.page.ts index 4487f22..02966ba 100644 --- a/base/api/testHelperPerson.page.ts +++ b/base/api/testHelperPerson.page.ts @@ -83,13 +83,13 @@ export async function addSecondOrganisationToPerson(page: Page, personId: string expect(response.status()).toBe(200); } -export async function deletePersonen(page: Page, personId: string): Promise { +export async function deletePerson(page: Page, personId: string): Promise { const response = await page.request.delete(FRONTEND_URL + `api/personen/${personId}`, {}); expect(response.status()).toBe(204); } -export async function getPersonId(page: Page, Benutzername: string): Promise { - const response = await page.request.get(FRONTEND_URL + `api/personen-frontend?suchFilter=${Benutzername}`, {}); +export async function getPersonId(page: Page, searchString: string): Promise { + const response = await page.request.get(FRONTEND_URL + `api/personen-frontend?suchFilter=${searchString}`, {}); expect(response.status()).toBe(200); const json = await response.json(); return json.items[0].person.id; diff --git a/base/testHelperDeleteTestdata.ts b/base/testHelperDeleteTestdata.ts index 1452640..374c7a2 100644 --- a/base/testHelperDeleteTestdata.ts +++ b/base/testHelperDeleteTestdata.ts @@ -1,11 +1,11 @@ import { deleteRolle, getRolleId} from "./api/testHelperRolle.page"; -import { deletePersonen, getPersonId } from "./api/testHelperPerson.page"; +import { deletePerson, getPersonId } from "./api/testHelperPerson.page"; import { getKlasseId, deleteKlasse } from "./api/testHelperOrganisation.page"; export async function deletePersonById(personId, page){ // personId ist ein array mit allen zu löschenden Benutzern for (const item in personId){ - await deletePersonen(page, personId[item]); + await deletePerson(page, personId[item]); } } @@ -22,13 +22,18 @@ export async function deleteRolleByName(roleName, page){ // roleName ist ein ar } } -export async function deletePersonByUsername(username, page){ // username ist ein array mit allen zu löschenden Benutzern - for (const item in username){ - const personId = await getPersonId(page, username[item]); - await deletePersonen(page, personId); +export async function deletePersonenBySearchStrings(page, searchStringArray){ + for (const item in searchStringArray){ + const personId = await getPersonId(page, searchStringArray[item]); + await deletePerson(page, personId); } } +export async function deletePersonBySearchString(page, searchString){ + const personId = await getPersonId(page, searchString); + await deletePerson(page, personId); +} + export async function deleteKlasseByName(klassenName, page){ // klassenName ist ein array mit allen zu löschenden Klassen for (const item in klassenName){ const klassenId = await getKlasseId(page, klassenName[item]); diff --git a/tests/Import.spec.ts b/tests/Import.spec.ts index 5a069f5..0910582 100644 --- a/tests/Import.spec.ts +++ b/tests/Import.spec.ts @@ -8,6 +8,7 @@ import { PersonManagementViewPage } from "../pages/admin/PersonManagementView.pa import path from "path"; import fs from "fs"; import { fileURLToPath } from "url"; +import { deletePersonBySearchString } from "../base/testHelperDeleteTestdata.ts"; // schulen cannot be deleted yet, so we use this testschule, which should already exist import { testschule665 } from "../base/organisation.ts"; @@ -25,7 +26,7 @@ test.describe(`Testfälle für den Benutzerimport": Umgebung: ${process.env.UMGE const csvAsArray: Array = fs.readFileSync(csvPath).toString().split('\n').map(el => el.trim()).filter(e => e !== ''); test.beforeEach(async ({ page }) => { - await test.step(`Einloggen und zu Benutzerimport navigieren`, async () => { + await test.step('Einloggen und zu Benutzerimport navigieren', async () => { await page.goto(FRONTEND_URL); personImportPage = (await (await @@ -42,15 +43,23 @@ test.describe(`Testfälle für den Benutzerimport": Umgebung: ${process.env.UMGE }); test.afterEach(async ({ page }) => { + await test.step('Importierte Daten über die API löschen', async () => { + for (let index = 1; index < csvAsArray.length; index++) { + const person = csvAsArray[index]; + const nachname: string = person.split(';')[0]; + + await deletePersonBySearchString(page, nachname); + }; + }); + await test.step(`Abmelden`, async () => { const header = new HeaderPage(page); await header.logout(); }); }); - test("Als Landesadmin eine CSV-Datei mit Benutzerdaten hochladen und importieren", {tag: [LONG]}, async ({ page }) => { - await test.step(``, async () => { - + test('Als Landesadmin eine CSV-Datei mit Benutzerdaten hochladen und importieren', {tag: [LONG]}, async ({ page }) => { + await test.step('CSV-Datei hochladen, importieren und importierte Daten downloaden', async () => { // select schule await personImportPage.schuleSelectCombobox.searchByTitle(testschule665); @@ -89,25 +98,8 @@ test.describe(`Testfälle für den Benutzerimport": Umgebung: ${process.env.UMGE await page.waitForURL('**/admin/personen'); await personManagementPage.input_Suchfeld.fill(firstPersonLastName); await personManagementPage.button_Suchen.click(); - await expect(page.getByRole("cell", { name: firstPersonLastName, exact: true })).toBeVisible(); + await expect(page.getByRole('cell', { name: firstPersonLastName, exact: true })).toBeVisible(); await personManagementPage.input_Suchfeld.clear(); - - // delete imported users via UI to clean up - // index has to be greater than 0, because the first line is the header - for (let index = 1; index < csvAsArray.length; index++) { - const person = csvAsArray[index]; - const nachname: string = person.split(';')[0]; - - await personManagementPage.input_Suchfeld.clear(); - await personManagementPage.input_Suchfeld.fill(nachname); - await personManagementPage.button_Suchen.click(); - - await page.getByRole("cell", { name: nachname, exact: true }).isVisible(); - const personDetailsPage = await personManagementPage.navigateToPersonDetailsViewByNachname(nachname); - await personDetailsPage.button_deletePerson.click(); - await personDetailsPage.button_deletePersonConfirm.click(); - await personDetailsPage.button_closeDeletePersonConfirm.click(); - } }); }); }); \ No newline at end of file diff --git a/tests/Person.spec.ts b/tests/Person.spec.ts index 5fbcc32..2dfc86b 100644 --- a/tests/Person.spec.ts +++ b/tests/Person.spec.ts @@ -13,7 +13,7 @@ import { getSPId } from "../base/api/testHelperServiceprovider.page"; import { UserInfo } from "../base/api/testHelper.page"; import { addSystemrechtToRolle } from "../base/api/testHelperRolle.page"; import { LONG, SHORT, STAGE, BROWSER } from "../base/tags"; -import { deletePersonByUsername, deleteRolleById, deleteRolleByName } from "../base/testHelperDeleteTestdata.ts"; +import { deletePersonenBySearchStrings, deleteRolleById, deleteRolleByName } from "../base/testHelperDeleteTestdata.ts"; import { landesadminRolle, schuelerRolle, schuladminOeffentlichRolle } from "../base/rollen.ts"; import { generateLehrerNachname, generateLehrerVorname, generateRolleName } from "../base/testHelperGenerateTestdataNames.ts"; @@ -51,7 +51,7 @@ test.describe(`Testfälle für die Administration von Personen": Umgebung: ${pro await login.login(ADMIN, PW); await expect(startseite.text_h2_Ueberschrift).toBeVisible(); - await deletePersonByUsername(username, page); + await deletePersonenBySearchStrings(page, username); username = []; } diff --git a/tests/PersonBearbeiten.spec.ts b/tests/PersonBearbeiten.spec.ts index 9ce47c4..b3b4e27 100644 --- a/tests/PersonBearbeiten.spec.ts +++ b/tests/PersonBearbeiten.spec.ts @@ -11,7 +11,7 @@ import {getSPId} from "../base/api/testHelperServiceprovider.page.ts"; import {UserInfo} from "../base/api/testHelper.page.ts"; import {addSystemrechtToRolle} from "../base/api/testHelperRolle.page.ts"; import {LONG, STAGE} from "../base/tags.ts"; -import {deletePersonByUsername, deleteRolleById} from "../base/testHelperDeleteTestdata.ts"; +import {deletePersonenBySearchStrings, deleteRolleById} from "../base/testHelperDeleteTestdata.ts"; import {typelehrer} from "../base/rollentypen.ts"; import {testschule} from "../base/organisation.ts"; import {email} from "../base/sp.ts"; @@ -50,7 +50,7 @@ test.describe(`Testfälle für die Administration von Personen": Umgebung: ${pro await login.login(ADMIN, PW); await expect(startseite.text_h2_Ueberschrift).toBeVisible(); - await deletePersonByUsername(username, page); + await deletePersonenBySearchStrings(page, username); username = []; } diff --git a/tests/Profile.spec.ts b/tests/Profile.spec.ts index c29e560..eaff949 100644 --- a/tests/Profile.spec.ts +++ b/tests/Profile.spec.ts @@ -11,7 +11,7 @@ import { getOrganisationId } from "../base/api/testHelperOrganisation.page"; import { UserInfo } from "../base/api/testHelper.page"; import { addSystemrechtToRolle } from "../base/api/testHelperRolle.page"; import { LONG, SHORT, STAGE, BROWSER } from "../base/tags"; -import { deleteRolleById, deletePersonByUsername} from "../base/testHelperDeleteTestdata"; +import { deleteRolleById, deletePersonenBySearchStrings} from "../base/testHelperDeleteTestdata"; import { generateLehrerNachname, generateLehrerVorname, generateRolleName } from "../base/testHelperGenerateTestdataNames.ts"; const PW: string | undefined = process.env.PW; @@ -49,7 +49,7 @@ test.describe(`Testfälle für das eigene Profil anzeigen: Umgebung: ${process.e await expect(startseite.text_h2_Ueberschrift).toBeVisible(); await expect(startseite.card_item_schulportal_administration).toBeVisible(); - await deletePersonByUsername(username, page); + await deletePersonenBySearchStrings(page, username); username = []; } diff --git a/tests/login.spec.ts b/tests/login.spec.ts index 3f7b4d3..7a3b5b3 100644 --- a/tests/login.spec.ts +++ b/tests/login.spec.ts @@ -8,7 +8,7 @@ import { createRolleAndPersonWithUserContext, lockPerson } from "../base/api/tes import { getSPId } from "../base/api/testHelperServiceprovider.page.ts"; import { faker } from "@faker-js/faker/locale/de"; import { UserInfo } from "../base/api/testHelper.page.ts"; -import { deletePersonByUsername, deleteRolleById } from "../base/testHelperDeleteTestdata.ts"; +import { deletePersonenBySearchStrings, deleteRolleById } from "../base/testHelperDeleteTestdata.ts"; import { getOrganisationId } from "../base/api/testHelperOrganisation.page.ts"; import { generateRolleName } from '../base/testHelperGenerateTestdataNames.ts'; @@ -48,7 +48,7 @@ test.describe(`Testfälle für die Authentifizierung: Umgebung: ${process.env.UM await login.login(ADMIN, PW); await expect(startseite.text_h2_Ueberschrift).toBeVisible(); - await deletePersonByUsername(username, page); + await deletePersonenBySearchStrings(page, username); username = []; }