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
+24 -17
View File
@@ -1,36 +1,43 @@
/**
* Playwright Global Teardown
*
* Runs once after all tests. Use this to:
* - Clean up test data
* - Dispose singleton API contexts
*
* Customize for your project's cleanup needs.
*/
import { cleanupAllTestData, disposeAdminApi } from "./api/helpers/admin-api"
import { deleteAllEmails, disposeMailDev } from "./api/helpers/maildev"
import { cleanupSeededTestContent } from "./api/helpers/seed-data"
import { TEST_BASE_URL } from "./fixtures/test-constants"
async function globalTeardown() {
const baseURL = process.env.CODING_URL || "https://localhost:3000"
const baseURL = TEST_BASE_URL
// Clean up test users
try {
const probeContext = await import("@playwright/test").then(({ request }) =>
request.newContext({ baseURL, ignoreHTTPSErrors: true })
)
const apiProbe = await probeContext.get("/api/content?limit=1")
const contentType = apiProbe.headers()["content-type"] || ""
await probeContext.dispose()
if (!apiProbe.ok() || contentType.includes("text/html")) {
console.warn(
`Playwright teardown: skipped seeded cleanup because ${baseURL} has no usable /api endpoint (${apiProbe.status()} ${contentType || "without content-type"})`
)
return
}
const deletedSeedEntries = await cleanupSeededTestContent(baseURL)
const result = await cleanupAllTestData(baseURL)
if (result.users > 0) {
console.log(`🧹 Cleanup: ${result.users} test users deleted`)
if (deletedSeedEntries > 0 || result.users > 0) {
console.log(
`Playwright teardown: deleted ${deletedSeedEntries} seeded content entries and ${result.users} test users`
)
}
} catch (err) {
console.warn("⚠️ Test data cleanup failed:", err)
console.warn("Playwright teardown: test data cleanup failed:", err)
}
// Clean up MailDev emails (optional)
try {
await deleteAllEmails()
} catch {
// MailDev cleanup is optional
// MailDev cleanup is optional.
}
// Dispose singleton API contexts
await Promise.all([disposeAdminApi(), disposeMailDev()])
}