1b24bb2157
- Added functions for creating, updating, deleting, and listing collection entries in admin API. - Introduced seed data management for consistent test content across tests. - Updated global setup and teardown processes to ensure seeded content is created and cleaned up. - Refactored existing tests to utilize seeded content for improved reliability and maintainability.
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import fs from "node:fs"
|
|
import path from "node:path"
|
|
|
|
/**
|
|
* Zentrale Test-Konstanten für alle Tests.
|
|
*
|
|
* Passe diese Werte an dein Projekt an:
|
|
* - TEST_USER: E-Mail/Passwort für den E2E-Test-User
|
|
* - ADMIN_TOKEN: Token aus api/config.yml.env
|
|
* - API_BASE: API-Pfad (Standard: /api)
|
|
*/
|
|
|
|
export const TEST_USER = {
|
|
email: "playwright-e2e@test.example.com",
|
|
password: "PlaywrightTest1",
|
|
firstName: "Playwright",
|
|
lastName: "E2E",
|
|
} as const
|
|
|
|
function loadAdminTokenFromEnvFile(): string | undefined {
|
|
const envFilePath = path.resolve(process.cwd(), "api/config.yml.env")
|
|
if (!fs.existsSync(envFilePath)) return undefined
|
|
|
|
const raw = fs.readFileSync(envFilePath, "utf8")
|
|
const line = raw
|
|
.split(/\r?\n/)
|
|
.find((entry) => entry.startsWith("ADMIN_TOKEN=") && entry.trim().length > "ADMIN_TOKEN=".length)
|
|
|
|
return line ? line.slice("ADMIN_TOKEN=".length).trim() : undefined
|
|
}
|
|
|
|
function loadProjectEnvValue(key: string): string | undefined {
|
|
const envFilePath = path.resolve(process.cwd(), ".env")
|
|
if (!fs.existsSync(envFilePath)) return undefined
|
|
|
|
const raw = fs.readFileSync(envFilePath, "utf8")
|
|
const prefix = `${key}=`
|
|
const line = raw.split(/\r?\n/).find((entry) => entry.startsWith(prefix) && entry.trim().length > prefix.length)
|
|
if (!line) return undefined
|
|
|
|
return line.slice(prefix.length).trim()
|
|
}
|
|
|
|
export const ADMIN_TOKEN = process.env.ADMIN_TOKEN || loadAdminTokenFromEnvFile() || "CHANGE_ME"
|
|
export const API_BASE = "/api"
|
|
export const TEST_BASE_URL = process.env.CODING_URL || loadProjectEnvValue("CODING_URL") || "http://localhost:3000"
|
|
|
|
export const SEEDED_TEST_CONTENT = {
|
|
home: {
|
|
translationKey: "pw-e2e-home",
|
|
path: "/playwright-e2e-home",
|
|
},
|
|
contact: {
|
|
translationKey: "pw-e2e-contact",
|
|
path: "/playwright-e2e-contact",
|
|
},
|
|
inactive: {
|
|
translationKey: "pw-e2e-inactive",
|
|
path: "/playwright-e2e-inactive",
|
|
},
|
|
} as const
|
|
|
|
export const BASIC_AUTH = {
|
|
username: process.env.BASIC_AUTH_USER || "web",
|
|
password: process.env.BASIC_AUTH_PASS || "web",
|
|
} as const
|