- 移除 LeaiTokenVO.h5Url 字段、LeaiConfig.h5Url 配置及 yml 中的 h5-url - 删除 LeaiAuthController.authRedirect() 方法和 LeaiAuthRedirectDTO - 移除前端 authRedirectUrl 状态及 WelcomeView 企业认证按钮死代码 - 修复 LeaiProxyController 返回 text/plain 导致前端无法解析 JSON 的问题 (改用 ResponseEntity<String> + application/json Content-Type) - 修复前端 aicreate 所有视图组件中 res.data 双重取值问题 (publicApi 拦截器已自动解包,无需再取 .data) - 同步更新 E2E 测试 mock 数据移除 h5Url Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
77 lines
2.5 KiB
TypeScript
77 lines
2.5 KiB
TypeScript
import { test, expect } from '../fixtures/auth.fixture'
|
||
|
||
/**
|
||
* P0: 认证 API 测试
|
||
*
|
||
* 测试 LeaiAuthController 的两个接口:
|
||
* - GET /leai-auth/token(iframe 主入口)
|
||
* - GET /leai-auth/refresh-token(Token 刷新)
|
||
*/
|
||
|
||
const API_BASE = process.env.API_BASE_URL || 'http://localhost:8580/api'
|
||
|
||
test.describe('乐读派认证 API', () => {
|
||
|
||
test.describe('GET /leai-auth/token', () => {
|
||
test('未登录 — 返回 401', async ({ request }) => {
|
||
const resp = await request.get(`${API_BASE}/leai-auth/token`)
|
||
expect(resp.status()).toBe(401)
|
||
})
|
||
|
||
test('已登录 — 返回 token + orgId', async ({ authedApi }) => {
|
||
const resp = await authedApi.get(`${API_BASE}/leai-auth/token`)
|
||
expect(resp.status()).toBe(200)
|
||
|
||
const json = await resp.json()
|
||
expect(json.code).toBe(200)
|
||
expect(json.data).toBeDefined()
|
||
|
||
const data = json.data
|
||
expect(data).toHaveProperty('token')
|
||
expect(data).toHaveProperty('orgId')
|
||
expect(data.token).toBeTruthy()
|
||
expect(data.orgId).toBeTruthy()
|
||
})
|
||
|
||
test('返回的 token 为非空字符串', async ({ authedApi }) => {
|
||
const resp = await authedApi.get(`${API_BASE}/leai-auth/token`)
|
||
const json = await resp.json()
|
||
expect(typeof json.data.token).toBe('string')
|
||
expect(json.data.token.length).toBeGreaterThan(10)
|
||
})
|
||
})
|
||
|
||
test.describe('GET /leai-auth/refresh-token', () => {
|
||
test('未登录 — 返回 401', async ({ request }) => {
|
||
const resp = await request.get(`${API_BASE}/leai-auth/refresh-token`)
|
||
expect(resp.status()).toBe(401)
|
||
})
|
||
|
||
test('已登录 — 刷新成功', async ({ authedApi }) => {
|
||
const resp = await authedApi.get(`${API_BASE}/leai-auth/refresh-token`)
|
||
expect(resp.status()).toBe(200)
|
||
|
||
const json = await resp.json()
|
||
expect(json.code).toBe(200)
|
||
expect(json.data).toHaveProperty('token')
|
||
expect(json.data).toHaveProperty('orgId')
|
||
})
|
||
|
||
test('连续两次刷新返回不同 token', async ({ authedApi }) => {
|
||
const resp1 = await authedApi.get(`${API_BASE}/leai-auth/refresh-token`)
|
||
const json1 = await resp1.json()
|
||
|
||
// 短暂等待确保时间戳不同
|
||
await new Promise((r) => setTimeout(r, 100))
|
||
|
||
const resp2 = await authedApi.get(`${API_BASE}/leai-auth/refresh-token`)
|
||
const json2 = await resp2.json()
|
||
|
||
expect(json1.data.token).toBeTruthy()
|
||
expect(json2.data.token).toBeTruthy()
|
||
// 两次 token 应不同(每次换新 session)
|
||
expect(json1.data.token).not.toBe(json2.data.token)
|
||
})
|
||
})
|
||
})
|