feat(admin): album management pages with members and categories

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-18 12:33:46 +08:00
parent a6cc190751
commit 50c59ca9d4
27 changed files with 2977 additions and 16 deletions
+37 -2
View File
@@ -1,7 +1,10 @@
// e2e 辅助:从仓库根 .env 读种子管理员凭据(global-setup 已跑过幂等 seed)。
// e2e 辅助:根 .env 凭据/环境读取、UI 登录、DB 直种夹具(seed-fixture.cjs)。
import { execSync } from 'node:child_process'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import type { Page } from '@playwright/test'
import { expect } from '@playwright/test'
const repoRoot = fileURLToPath(new URL('../../..', import.meta.url))
@@ -10,7 +13,7 @@ export interface AdminCredentials {
password: string
}
export function adminCredentials(): AdminCredentials {
function rootEnv(): Map<string, string> {
const envPath = join(repoRoot, '.env')
if (!existsSync(envPath)) {
throw new Error(`[admin e2e] 仓库根 .env 不存在(${envPath})`)
@@ -20,7 +23,39 @@ export function adminCredentials(): AdminCredentials {
const match = /^([A-Z0-9_]+)=(.*)$/.exec(line.trim())
if (match) vars.set(match[1], match[2])
}
return vars
}
export function adminCredentials(): AdminCredentials {
const vars = rootEnv()
const account = vars.get('ADMIN_ACCOUNT') ?? 'admin'
const password = vars.get('ADMIN_PASSWORD') ?? 'admin-secret-change-me'
return { account, password }
}
/** UI 登录(真实后端):填账号密码 → 落到 /albums/manage */
export async function loginAsAdmin(page: Page): Promise<void> {
const { account, password } = adminCredentials()
await page.goto('/#/auth/login')
await page.getByPlaceholder('请输入账号').fill(account)
await page.getByPlaceholder('请输入密码', { exact: false }).fill(password)
await page.getByRole('button', { name: '登录' }).click()
await expect(page).toHaveURL(/\/albums\/manage/, { timeout: 20_000 })
}
/** 直种夹具(seed-fixture.cjs):staff 账号 / 相册种子照片(幂等) */
export function seedFixture(mode: 'staff' | 'photos', ...args: string[]): void {
const vars = rootEnv()
const databaseUrl = vars.get('DATABASE_URL_CN')
if (!databaseUrl) {
throw new Error('[admin e2e] 根 .env 缺少 DATABASE_URL_CN')
}
// @photo/db-cn 绝对路径:apps/admin 不依赖该包,借 services/api 的 node_modules
const dbCn = join(repoRoot, 'services', 'api', 'node_modules', '@photo', 'db-cn')
execSync(`node seed-fixture.cjs ${mode} ${args.join(' ')}`, {
cwd: fileURLToPath(new URL('.', import.meta.url)),
stdio: 'inherit',
shell: true,
env: { ...process.env, PHOTO_DB_CN: dbCn, DATABASE_URL_CN: databaseUrl }
})
}