✨ feat: enhance admin API helpers with CRUD operations for collections and seed data management
- 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.
This commit is contained in:
Vendored
+44
-1
@@ -1,3 +1,6 @@
|
||||
import fs from "node:fs"
|
||||
import path from "node:path"
|
||||
|
||||
/**
|
||||
* Zentrale Test-Konstanten für alle Tests.
|
||||
*
|
||||
@@ -14,8 +17,48 @@ export const TEST_USER = {
|
||||
lastName: "E2E",
|
||||
} as const
|
||||
|
||||
export const ADMIN_TOKEN = process.env.ADMIN_TOKEN || "CHANGE_ME"
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user