feat: create admin account on startup
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

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";
@ -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();