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
+7 -41
View File
@@ -1,57 +1,23 @@
import { test as base, expect, APIRequestContext } from "@playwright/test"
import { ensureTestUser, type TestUserCredentials } from "./helpers/test-user"
import { test as base, expect, type APIRequestContext } from "@playwright/test"
import { getAdminContext } from "./helpers/admin-api"
import { TEST_BASE_URL } from "../fixtures/test-constants"
const API_BASE = "/api"
interface ActionSuccess {
success: true
[key: string]: unknown
}
interface ActionError {
error: string
}
type ApiWorkerFixtures = {
testUser: TestUserCredentials
}
type ApiFixtures = {
api: APIRequestContext
authedApi: APIRequestContext
accessToken: string
adminApi: APIRequestContext
}
export const test = base.extend<ApiFixtures, ApiWorkerFixtures>({
testUser: [
async ({ playwright }, use) => {
const baseURL = process.env.CODING_URL || "https://localhost:3000"
const user = await ensureTestUser(baseURL)
await use(user)
},
{ scope: "worker" },
],
export const test = base.extend<ApiFixtures>({
api: async ({ request }, use) => {
await use(request)
},
accessToken: async ({ testUser }, use) => {
await use(testUser.accessToken)
},
authedApi: async ({ playwright, baseURL, accessToken }, use) => {
const ctx = await playwright.request.newContext({
baseURL: baseURL!,
ignoreHTTPSErrors: true,
extraHTTPHeaders: {
Authorization: `Bearer ${accessToken}`,
},
})
adminApi: async ({ baseURL }, use) => {
const ctx = await getAdminContext(baseURL || TEST_BASE_URL)
await use(ctx)
await ctx.dispose()
},
})
export { expect, API_BASE }
export type { ActionSuccess, ActionError }