37 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import {
 | |
|   test, expect, isLoggedIn, OIDC_BASE_URL,
 | |
| } from "./_test";
 | |
| 
 | |
| test("login", async ({ login: page, account }) => {
 | |
|   await page.goto("/");
 | |
|   await expect(page).toHaveTitle("Visitenbuch");
 | |
|   await expect(page.locator("h1.heading")).toHaveText("Hallo, " + account.name);
 | |
|   // Test cases may create more entries
 | |
|   expect(parseInt(await page.getByTestId("n-entries-todo").innerText()))
 | |
|     .toBeGreaterThanOrEqual(193);
 | |
| });
 | |
| 
 | |
| test("logout", async ({ login: page, baseURL }) => {
 | |
|   await page.goto("/");
 | |
| 
 | |
|   await page.goto("/logout");
 | |
|   await page.getByTestId("btn-logout").click();
 | |
| 
 | |
|   // Sometimes the OIDC provider asks for login confirmation
 | |
|   if (page.url().startsWith(OIDC_BASE_URL)) {
 | |
|     await page.locator('button[value="yes"]').click();
 | |
|   }
 | |
| 
 | |
|   await page.waitForURL("/login?noAuto=1");
 | |
|   await expect(page.getByTestId("btn-login")).toBeVisible();
 | |
|   expect(await isLoggedIn(page)).toBe(false);
 | |
| 
 | |
|   // Check if application is not accessible if unauthorized
 | |
|   await page.goto("/plan");
 | |
|   expect(page.url() === baseURL + "/login?returnURL=%2Fplan" || page.url().startsWith(OIDC_BASE_URL)).toBe(true);
 | |
| 
 | |
|   // Check if TRPC API is not accessible if unauthorized
 | |
|   const apiResponse = await page.context().request.get("/trpc/savedFilter.getAll");
 | |
|   expect(apiResponse.status()).toBe(401);
 | |
|   expect(await apiResponse.json()).toMatchObject({ error: { message: "not logged in" } });
 | |
| });
 |