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:
2026-05-12 20:36:06 +00:00
parent 491f495c66
commit 1b24bb2157
17 changed files with 697 additions and 444 deletions
+17 -25
View File
@@ -1,21 +1,10 @@
/**
* Playwright Global Setup
*
* Runs once before all tests. Use this to:
* - Seed test data via API action hooks
* - Create test users
* - Verify the dev environment is accessible
*
* Customize the setup_testing action call for your project,
* or remove it if not needed.
*/
import { request } from "@playwright/test"
import { API_BASE } from "./fixtures/test-constants"
import { ensureSeededTestContent } from "./api/helpers/seed-data"
import { TEST_BASE_URL } from "./fixtures/test-constants"
async function globalSetup() {
const baseURL = process.env.CODING_URL || "https://localhost:3000"
const baseURL = TEST_BASE_URL
// Verify dev environment is reachable
const ctx = await request.newContext({
baseURL,
ignoreHTTPSErrors: true,
@@ -27,20 +16,23 @@ async function globalSetup() {
try {
const res = await ctx.get("/")
if (!res.ok()) {
console.warn(`⚠️ Dev environment at ${baseURL} returned ${res.status()}`)
throw new Error(`Dev environment at ${baseURL} returned ${res.status()}`)
} else {
console.log(`✅ Dev environment reachable at ${baseURL}`)
console.log(`Playwright setup: dev environment reachable at ${baseURL}`)
}
// Uncomment and adapt for project-specific test data seeding:
// const seedRes = await ctx.post(`${API_BASE}/action`, {
// params: { cmd: "setup_testing" },
// data: { scope: "all" },
// headers: { Token: ADMIN_TOKEN },
// })
// if (seedRes.ok()) {
// console.log("✅ Test data seeded")
// }
const apiProbe = await ctx.get("/api/content?limit=1")
const contentType = apiProbe.headers()["content-type"] || ""
if (!apiProbe.ok() || contentType.includes("text/html")) {
throw new Error(
`Playwright seed setup needs a base URL with working /api access. Current base URL ${baseURL} returned ${apiProbe.status()} ${contentType || "without content-type"} for /api/content.`
)
}
const result = await ensureSeededTestContent(baseURL)
console.log(
`Playwright setup: seeded deterministic content (deleted ${result.deleted}, created ${result.created})`
)
} finally {
await ctx.dispose()
}