Skip to content

Commit

Permalink
SPSH-755 schulportal administration pruefen (#46)
Browse files Browse the repository at this point in the history
* Neuerr Testfall Schulportal-Adminsitration mit Testdaten via api

* Test Schulportal-Administration fertig

* fix

* testHelper umbenannt damit SonarCloud nicht wegen der Testabdeckung meckert

* Bennung der Testdaten laut Konvention aus der readme. Logout nach jedem Testfall um Probleme bei der parallelen Ausführung bei mehreren workers zu minimieren.

* Update base/testHelper.page.ts

Co-authored-by: Julian Aggarwal <[email protected]>

* Update base/testHelper.page.ts

Co-authored-by: Julian Aggarwal <[email protected]>

* User bzw Benutzer durch Person ersetzt

* testHelper auf mehrere Dateien  aufgesplittet

---------

Co-authored-by: Julian Aggarwal <[email protected]>
  • Loading branch information
jakobmadp and jaggarnaut authored Aug 5, 2024
1 parent 783dc5f commit 2dc442e
Show file tree
Hide file tree
Showing 14 changed files with 306 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ npm run lint

## Testdatenerstellung durch die Playwright-Tests

Neue Testdaten, die während der Testausführung erstellt werden, haben den Prefix 'TAuto-PW-', gefolgt von einem Buchstaben für den Typ + einen Zufallswert aus der Methode generateRandomString. Der Name einer Rolle ist z.B. TAuto-PW-R-xxxxxxxxx. Somit ist es einfacher, die Testdaten zu erkennen, die durch die Playwright-Tests erstellt wurden.
Neue Testdaten, die während der Testausführung erstellt werden, haben den Prefix 'TAuto-PW-', gefolgt von einem Buchstaben für den Typ des Objekts + einen Zufallswert aus faker oder einem festen Wert. Der Name einer Rolle ist z.B. TAuto-PW-R-xxxxxxxxx. Somit ist es einfacher, die Testdaten zu erkennen, die durch die Playwright-Tests erstellt wurden.

## Hinweise für die Entwicklung der Tests

Expand Down
7 changes: 7 additions & 0 deletions base/api/testHelper.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface UserInfo {
username: string,
password: string,
rolleId: string,
organisationId: string,
personId: string;
}
29 changes: 29 additions & 0 deletions base/api/testHelperOrganisation.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Page, expect } from '@playwright/test';
import { faker } from "@faker-js/faker/locale/de";

const FRONTEND_URL = process.env.FRONTEND_URL || "";

export async function createOrganisation(page: Page, name: string): Promise<string> {
const response = await page.request.post(FRONTEND_URL + 'api/organisationen/', {
data: {
"administriertVon": null,
"zugehoerigZu": null,
"kennung": faker.string.numeric({length: 6}),
"name": name,
"namensergaenzung": null,
"kuerzel": null,
"typ": "SCHULE",
"traegerschaft": null
}
});
expect(response.status()).toBe(201);
const json = await response.json();
return json.id;
}

export async function getOrganisationId(page: Page, nameOrganisation: string): Promise<string> {
const response = await page.request.get(FRONTEND_URL + `api/organisationen?name=${nameOrganisation}`, {});
expect(response.status()).toBe(200);
const json = await response.json();
return json[0].id;
}
40 changes: 40 additions & 0 deletions base/api/testHelperPerson.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Page, expect } from '@playwright/test';
import { getOrganisationId } from "./testHelperOrganisation.page";
import { createRolle, addSPToRolle } from "./testHelperRolle.page";
import { UserInfo } from "./testHelper.page";

const FRONTEND_URL = process.env.FRONTEND_URL || "";

export async function createPerson(page: Page, familienname: string, vorname: string, organisationId: string, rolleId: string): Promise<UserInfo> {
const response = await page.request.post(FRONTEND_URL + 'api/personenkontext-workflow/', {
data: {
"familienname": familienname,
"vorname": vorname,
"organisationId": organisationId,
"rolleId": rolleId
}
});
expect(response.status()).toBe(201);
const json = await response.json();
return {
username: json.person.referrer,
password: json.person.startpasswort,
rolleId: rolleId,
organisationId: organisationId,
personId: json.person.id
}
}

export async function createPersonWithUserContext(page: Page, organisationName: string, rollenArt: string, familienname: string, vorname: string, idSP: string, rolleName: string): Promise<UserInfo> {
// API-Calls machen und Benutzer mit Kontext anlegen
const organisationId: string = await getOrganisationId(page, organisationName);
const rolleId: string = await createRolle(page, rollenArt, organisationId, rolleName);
await addSPToRolle(page, rolleId, idSP);
const userInfo: UserInfo = await createPerson(page, familienname, vorname, organisationId, rolleId);
return userInfo;
}

export async function deletePersonen(page: Page, personId: string): Promise<void> {
const response = await page.request.delete(FRONTEND_URL + `api/personen/${personId}`, {});
expect(response.status()).toBe(204);
}
41 changes: 41 additions & 0 deletions base/api/testHelperRolle.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Page, expect } from '@playwright/test';

const FRONTEND_URL = process.env.FRONTEND_URL || "";

export async function createRolle(page: Page, rollenArt: string, organisationId: string, rolleName?: string): Promise<string> {
const response = await page.request.post(FRONTEND_URL + 'api/rolle/', {
data: {
"name": rolleName,
"administeredBySchulstrukturknoten": organisationId,
"rollenart": rollenArt,
"merkmale": [],
"systemrechte": []
}
});
expect(response.status()).toBe(201);
const json = await response.json();
return json.id;
}

export async function addSPToRolle(page: Page, rolleId: string, idSP: string): Promise<void> {
const response = await page.request.post(FRONTEND_URL + `api/rolle/${rolleId}/serviceProviders`, {
data: {
"serviceProviderId": idSP
}
});
expect(response.status()).toBe(201);
}

export async function addSystemrechtToRolle(page: Page, rolleId: string, systemrecht: string): Promise<void> {
const response = await page.request.patch(FRONTEND_URL + `api/rolle/${rolleId}`, {
data: {
"systemRecht": systemrecht
}
});
expect(response.status()).toBe(200);
}

export async function deleteRolle(page: Page, RolleId: string): Promise<void> {
const response = await page.request.delete(FRONTEND_URL + `api/rolle/${RolleId}`, {});
expect(response.status()).toBe(204);
}
18 changes: 18 additions & 0 deletions base/api/testHelperServiceprovider.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Page, expect } from '@playwright/test';

const FRONTEND_URL = process.env.FRONTEND_URL || "";

export async function getSPId(page: Page, nameSP: string): Promise<string> {
const response = await page.request.get(FRONTEND_URL + `api/provider/all`, {});
expect(response.status()).toBe(200);
const json = await response.json();
expect(response.status()).toBe(200);
let idSP = '';

json.forEach((element) => {
if (element.name === nameSP) {
idSP = element.id;
}
});
return idSP;
}
8 changes: 8 additions & 0 deletions tests/Klasse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MenuPage } from "../pages/MenuBar.page";
import { KlasseCreationViewPage } from "../pages/admin/KlasseCreationView.page";
import { KlasseManagementViewPage } from "../pages/admin/KlasseManagementView.page";
import { faker } from "@faker-js/faker/locale/de";
import { HeaderPage } from "../pages/Header.page";

const PW = process.env.PW;
const ADMIN = process.env.USER;
Expand All @@ -25,6 +26,13 @@ test.describe(`Testfälle für die Administration von Klassen: Umgebung: ${proce
});
});

test.afterEach(async ({ page }) => {
await test.step(`Abmelden`, async () => {
const Header = new HeaderPage(page);
await Header.button_logout.click();
});
});

test("Eine Klasse anlegen und die Klasse anschließend in der Ergebnisliste suchen", async ({ page }) => {
const Startseite = new StartPage(page);
const Menue = new MenuPage(page);
Expand Down
8 changes: 8 additions & 0 deletions tests/MenuBar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { LandingPage } from '../pages/LandingView.page';
import { StartPage } from '../pages/StartView.page';
import { LoginPage } from '../pages/LoginView.page';
import { MenuPage } from '../pages/MenuBar.page';
import { HeaderPage } from "../pages/Header.page";

const PW = process.env.PW;
const ADMIN = process.env.USER;
Expand All @@ -21,6 +22,13 @@ test.describe(`Testfälle für die Hauptmenue-Leiste: Umgebung: ${process.env.UM
await expect(Startseite.text_h2_Ueberschrift).toBeVisible();
});
});

test.afterEach(async ({ page }) => {
await test.step(`Abmelden`, async () => {
const Header = new HeaderPage(page);
await Header.button_logout.click();
});
});

test('Test der Hauptmenue-Leiste und Untermenues auf Vollständigkeit', async ({ page }) => {
const Startseite = new StartPage(page)
Expand Down
7 changes: 7 additions & 0 deletions tests/Person.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ test.describe(`Testfälle für die Administration von Personen": Umgebung: ${pro
});
});

test.afterEach(async ({ page }) => {
await test.step(`Login`, async () => {
const Header = new HeaderPage(page);
await Header.button_logout.click();
});
});

test("Einen Benutzer mit der Rolle Lehrkraft anlegen und anschließend mit diesem Benutzer anmelden", async ({
page,
}) => {
Expand Down
8 changes: 8 additions & 0 deletions tests/Rolle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MenuPage } from "../pages/MenuBar.page";
import { RolleCreationViewPage } from "../pages/admin/RolleCreationView.page";
import { RolleManagementViewPage } from "../pages/admin/RolleManagementView.page";
import { faker } from "@faker-js/faker/locale/de";
import { HeaderPage } from "../pages/Header.page";

const PW = process.env.PW;
const ADMIN = process.env.USER;
Expand All @@ -25,6 +26,13 @@ test.describe(`Testfälle für die Administration von Rollen: Umgebung: ${proces
});
});

test.afterEach(async ({ page }) => {
await test.step(`Abmelden`, async () => {
const Header = new HeaderPage(page);
await Header.button_logout.click();
});
});

test("2 Rollen nacheinander anlegen", async ({ page }) => {
const Startseite = new StartPage(page);
const Menue = new MenuPage(page);
Expand Down
8 changes: 8 additions & 0 deletions tests/Schule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MenuPage } from "../pages/MenuBar.page";
import { SchuleCreationViewPage } from "../pages/admin/SchuleCreationView.page";
import { SchuleManagementViewPage } from "../pages/admin/SchuleManagementView.page";
import { faker } from "@faker-js/faker/locale/de";
import { HeaderPage } from "../pages/Header.page";

const PW = process.env.PW;
const ADMIN = process.env.USER;
Expand All @@ -25,6 +26,13 @@ test.describe(`Testfälle für die Administration von Schulen: Umgebung: ${proce
});
});

test.afterEach(async ({ page }) => {
await test.step(`Abmelden`, async () => {
const Header = new HeaderPage(page);
await Header.button_logout.click();
});
});

test("2 Schulen nacheinander anlegen", async ({ page }) => {
const Startseite = new StartPage(page);
const Menue = new MenuPage(page);
Expand Down
120 changes: 120 additions & 0 deletions tests/SchulportalAdministration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { expect, test } from "@playwright/test";
import { LandingPage } from "../pages/LandingView.page";
import { StartPage } from "../pages/StartView.page";
import { LoginPage } from "../pages/LoginView.page";
import { HeaderPage } from "../pages/Header.page";
import { getSPId } from "../base/api/testHelperServiceprovider.page";
import { createPersonWithUserContext, deletePersonen } from "../base/api/testHelperPerson.page";
import { addSystemrechtToRolle, deleteRolle } from "../base/api/testHelperRolle.page";
import { UserInfo } from "../base/api/testHelper.page";

const PW = process.env.PW;
const ADMIN = process.env.USER;
const FRONTEND_URL = process.env.FRONTEND_URL || "";

test.describe(`Testfälle für Schulportal Administration": Umgebung: ${process.env.UMGEBUNG}: URL: ${process.env.FRONTEND_URL}:`, () => {
test.afterEach(async ({ page }) => {
await test.step(`Abmelden`, async () => {
const Header = new HeaderPage(page);
await Header.button_logout.click();
});
});

test("Prüfen, dass die Schulportal-Administration Kachel nicht sichtbar ist für Lehrkräfte", async ({page}) => {
const Landing = new LandingPage(page);
const Login = new LoginPage(page);
const Header = new HeaderPage(page);

// Testdaten erstellen
await page.goto(FRONTEND_URL);
await Landing.button_Anmelden.click();
await Login.login(ADMIN, PW);

const idSP = await getSPId(page, 'E-Mail');
const userInfo: UserInfo = await createPersonWithUserContext(page, 'Testschule Schulportal', 'LEHR', 'TAuto-PW-B-MeierLehrer', 'TAuto-PW-B-Hans', idSP, 'TAuto-PW-R-RolleLehrer');
await Header.button_logout.click();

// Test durchführen
await Landing.button_Anmelden.click();
await Login.login(userInfo.username, userInfo.password);
await Login.UpdatePW();
const Startseite = new StartPage(page);
await test.step(`Prüfen, dass die Kachel E-Mail angezeigt wird und die Kachel Schulportal-Administration nicht angezeigt wird`, async () => {
await expect(Startseite.card_item_schulportal_administration).toBeHidden();
await expect(Startseite.card_item_email).toBeVisible();
});
await Header.button_logout.click();

// Testdaten löschen
await Landing.button_Anmelden.click();
await Login.login(ADMIN, PW);
await deletePersonen(page, userInfo.personId);
await deleteRolle(page, userInfo.rolleId);
});

test("Prüfen, dass die Schulportal-Administration Kachel nicht sichtbar ist für Schüler", async ({page}) => {
const Landing = new LandingPage(page);
const Login = new LoginPage(page);
const Header = new HeaderPage(page);

// Testdaten erstellen
await page.goto(FRONTEND_URL);
await Landing.button_Anmelden.click();
await Login.login(ADMIN, PW);

const idSP = await getSPId(page, 'itslearning');
const userInfo: UserInfo = await createPersonWithUserContext(page, 'Testschule Schulportal', 'LERN', 'TAuto-PW-B-JansenSchüler', 'TAuto-PW-B-Helga', idSP, 'TAuto-PW-R-RolleSuS');
await Header.button_logout.click();

// Test durchführen
await Landing.button_Anmelden.click();
await Login.login(userInfo.username, userInfo.password);
await Login.UpdatePW();
const Startseite = new StartPage(page);
await test.step(`Prüfen, dass die Kachel E-Mail angezeigt wird und die Kachel Schulportal-Administration nicht angezeigt wird`, async () => {
await expect(Startseite.card_item_schulportal_administration).toBeHidden();
await expect(Startseite.card_item_itslearning).toBeVisible();
});
await Header.button_logout.click();

// Testdaten löschen
await Landing.button_Anmelden.click();
await Login.login(ADMIN, PW);
await deletePersonen(page, userInfo.personId);
await deleteRolle(page, userInfo.rolleId);
});

test("Prüfen, dass die Schulportal-Administration Kachel sichtbar ist für Schuladmins", async ({page}) => {
const Landing = new LandingPage(page);
const Login = new LoginPage(page);
const Header = new HeaderPage(page);

// Testdaten erstellen
await page.goto(FRONTEND_URL);
await Landing.button_Anmelden.click();
await Login.login(ADMIN, PW);

const idSP = await getSPId(page, 'Schulportal-Administration');
const userInfo: UserInfo = await createPersonWithUserContext(page, 'Testschule Schulportal', 'LEIT', 'TAuto-PW-B-MeierAdmin', 'TAuto-PW-B-Peter', idSP, 'TAuto-PW-R-RolleSchuladmin');

await addSystemrechtToRolle(page, userInfo.rolleId, 'PERSONEN_VERWALTEN');
await Header.button_logout.click();

// Test durchführen
await Landing.button_Anmelden.click();
await Login.login(userInfo.username, userInfo.password);
await Login.UpdatePW();
const Startseite = new StartPage(page);
await test.step(`Prüfen, dass die Kachel E-Mail nicht angezeigt wird und die Kachel Schulportal-Administration angezeigt wird`, async () => {
await expect(Startseite.card_item_schulportal_administration).toBeVisible();
await expect(Startseite.card_item_email).toBeHidden();
});
await Header.button_logout.click();

// Testdaten löschen
await Landing.button_Anmelden.click();
await Login.login(ADMIN, PW);
await deletePersonen(page, userInfo.personId);
await deleteRolle(page, userInfo.rolleId);
});
});
8 changes: 8 additions & 0 deletions tests/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ import { LandingPage } from '../pages/LandingView.page';
import { StartPage } from '../pages/StartView.page';
import { faker } from "@faker-js/faker/locale/de";
import { PersonManagementViewPage } from "../pages/admin/PersonManagementView.page";
import { HeaderPage } from "../pages/Header.page";

const PW = process.env.PW;
const USER = process.env.USER;
const FRONTEND_URL = process.env.FRONTEND_URL || '';

test.describe(`Spike um die API anzusprechen: Umgebung: ${process.env.UMGEBUNG}: URL: ${process.env.FRONTEND_URL}:`, () => {
test.afterEach(async ({ page }) => {
await test.step(`Abmelden`, async () => {
const Header = new HeaderPage(page);
await Header.button_logout.click();
});
});

test('GET und Post request', async ({ page}) => {
const Login = new LoginPage(page);
const Landing = new LandingPage(page);
Expand Down
Loading

0 comments on commit 2dc442e

Please sign in to comment.