✨ 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:
+7
-41
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user