feat: create admin account on startup
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Aravinth Manivannan 2024-01-10 17:49:14 +05:30
parent 28cfa742f2
commit 958773125d
Signed by: realaravinth
GPG Key ID: F8F50389936984FF
5 changed files with 41 additions and 4 deletions

View File

@ -6,7 +6,8 @@ steps:
commands:
- npm ci
- npx playwright install --with-deps
- npx playwright test --project=firefox
- npx playwright test --project=firefox --grep @setup
- npx playwright test --project=firefox --grep-invert @setup
services:
forgejo:

3
Makefile Normal file
View File

@ -0,0 +1,3 @@
setup:
npx playwright test --project=firefox --grep @setup
npx playwright test --project=firefox --grep-invert @setup

View File

@ -3,3 +3,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
export const INSTANCE_URL = new URL(process.env.INSTANCE_URL)
export const ADMIN_USERNAME = "admin";

View File

@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import { test, expect } from "@playwright/test";
import * as config from "./config";
import User from "./user";
test("Create admin fixture @setup", async ({ page }) => {
const admin = new User(config.ADMIN_USERNAME);
admin.setAdmin();
try {
await admin.register(page);
await admin.logout(page);
await expect(page).toHaveTitle("Forgejo: Beyond coding. We forge.");
} catch {
console.log("looks like admin is already registered");
}
});

View File

@ -12,7 +12,20 @@ export default class User {
this.name = name;
this.username = `plw_${getRandomString(6)}_${name}`;
if (this.username.length > 40) {
throw Error(`username must be less than 40 char. Reduse length of ${name}`)
throw Error(
`username must be less than 40 char. Reduse length of ${name}`
);
}
this.email = `${this.username}@playwright.local`;
this.password = "628acdbd8b7b3f";
}
setAdmin() {
this.username = `plw_${this.name}`;
if (this.username.length > 40) {
throw Error(
`username must be less than 40 char. Reduse length of ${name}`
);
}
this.email = `${this.username}@playwright.local`;
this.password = "628acdbd8b7b3f";
@ -27,7 +40,7 @@ export default class User {
let dropdown = page.locator("div.dropdown:nth-child(4)");
await dropdown.click();
// await dropdown.getByRole("link", { name: "Sign Out" }).click();
// await dropdown.getByRole("link", { name: "Sign Out" }).click();
await dropdown.getByText("Sign Out").click();
await page.waitForURL(config.INSTANCE_URL.toString());
@ -49,7 +62,6 @@ export default class User {
);
}
async register(page: Page) {
await page.goto(config.INSTANCE_URL.toString());
await page.getByRole("link", { name: "Register" }).click();