Skip to content

Commit

Permalink
moved data deletion to after each hook and refactored helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jaggarnaut committed Nov 26, 2024
1 parent 827e6f2 commit 59cceea
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 39 deletions.
6 changes: 3 additions & 3 deletions base/api/testHelperPerson.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
export async function deletePerson(page: Page, personId: string): Promise<void> {
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<string> {
const response = await page.request.get(FRONTEND_URL + `api/personen-frontend?suchFilter=${Benutzername}`, {});
export async function getPersonId(page: Page, searchString: string): Promise<string> {
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;
Expand Down
17 changes: 11 additions & 6 deletions base/testHelperDeleteTestdata.ts
Original file line number Diff line number Diff line change
@@ -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]);
}
}

Expand All @@ -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]);
Expand Down
36 changes: 14 additions & 22 deletions tests/Import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -25,7 +26,7 @@ test.describe(`Testfälle für den Benutzerimport": Umgebung: ${process.env.UMGE
const csvAsArray: Array<string> = 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
Expand All @@ -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);

Expand Down Expand Up @@ -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();
}
});
});
});
4 changes: 2 additions & 2 deletions tests/Person.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 = [];
}

Expand Down
4 changes: 2 additions & 2 deletions tests/PersonBearbeiten.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 = [];
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Profile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [];
}

Expand Down
4 changes: 2 additions & 2 deletions tests/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 = [];
}

Expand Down

0 comments on commit 59cceea

Please sign in to comment.