init: 2026Technology-Competition initial commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { APIRequestContext } from '@playwright/test'
|
||||
import { API_BASE, apiLogin, authHeaders } from './auth'
|
||||
|
||||
export interface CreatedIssue {
|
||||
id: number
|
||||
issueNo: string
|
||||
title: string
|
||||
}
|
||||
|
||||
export async function createIssueViaApi(
|
||||
request: APIRequestContext,
|
||||
overrides: Record<string, unknown> = {},
|
||||
): Promise<{ issue: CreatedIssue; token: string }> {
|
||||
const token = (await apiLogin(request)).accessToken
|
||||
const payload = {
|
||||
title: `E2E-${Date.now()}-自动化测试`,
|
||||
description: 'Playwright 自动化测试创建的指摘',
|
||||
phase: '编码',
|
||||
subProject: '后端开发',
|
||||
category: '功能缺陷',
|
||||
impactLevel: '中',
|
||||
assigneeId: 2,
|
||||
reviewerId: 1,
|
||||
priority: 'medium',
|
||||
status: 'draft',
|
||||
departmentId: 2,
|
||||
...overrides,
|
||||
}
|
||||
const res = await request.post(`${API_BASE}/issues`, {
|
||||
data: payload,
|
||||
headers: authHeaders(token),
|
||||
})
|
||||
if (!res.ok()) {
|
||||
throw new Error(`create issue failed: ${res.status()} ${await res.text()}`)
|
||||
}
|
||||
const json = await res.json()
|
||||
return { issue: json.data, token }
|
||||
}
|
||||
|
||||
export async function deleteIssueViaApi(request: APIRequestContext, issueId: number, token: string) {
|
||||
const res = await request.delete(`${API_BASE}/issues/${issueId}`, { headers: authHeaders(token) })
|
||||
if (!res.ok()) {
|
||||
throw new Error(`delete issue failed: ${res.status()} ${await res.text()}`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function getIssueViaApi(request: APIRequestContext, issueId: number, token: string) {
|
||||
const res = await request.get(`${API_BASE}/issues/${issueId}`, { headers: authHeaders(token) })
|
||||
return res.ok() ? (await res.json()).data : null
|
||||
}
|
||||
|
||||
export async function changeStatusViaApi(
|
||||
request: APIRequestContext,
|
||||
issueId: number,
|
||||
token: string,
|
||||
status: string,
|
||||
remark = 'E2E 状态变更',
|
||||
) {
|
||||
const res = await request.patch(`${API_BASE}/issues/${issueId}/status`, {
|
||||
data: { status, remark },
|
||||
headers: authHeaders(token),
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
export async function getDashboardViaApi(request: APIRequestContext, token: string) {
|
||||
const res = await request.get(`${API_BASE}/dashboard/stats`, { headers: authHeaders(token) })
|
||||
return res.ok() ? (await res.json()).data : null
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { APIRequestContext } from '@playwright/test'
|
||||
|
||||
export const ADMIN = { username: 'admin', password: 'Admin@2026' }
|
||||
export const API_BASE = 'http://localhost:8080/api/v1'
|
||||
|
||||
export interface LoginData {
|
||||
accessToken: string
|
||||
refreshToken?: string
|
||||
username?: string
|
||||
roleName?: string
|
||||
userId?: number
|
||||
}
|
||||
|
||||
export async function apiLogin(request: APIRequestContext, user = ADMIN): Promise<LoginData> {
|
||||
const res = await request.post(`${API_BASE}/auth/login`, {
|
||||
data: { username: user.username, password: user.password },
|
||||
})
|
||||
if (!res.ok()) {
|
||||
throw new Error(`login failed: ${res.status()} ${await res.text()}`)
|
||||
}
|
||||
const json = await res.json()
|
||||
return json.data
|
||||
}
|
||||
|
||||
export async function uiLogin(page: import('@playwright/test').Page, user = ADMIN) {
|
||||
await page.goto('/login')
|
||||
await page.getByPlaceholder(/用户名|账号|username/i).fill(user.username)
|
||||
await page.getByPlaceholder(/密码|password/i).fill(user.password)
|
||||
await page.getByRole('button', { name: /登\s*录/i }).click()
|
||||
await page.waitForURL(/\/dashboard/)
|
||||
}
|
||||
|
||||
export function authHeaders(token: string) {
|
||||
return { Authorization: `Bearer ${token}` }
|
||||
}
|
||||
Reference in New Issue
Block a user