Files
crawler-plugin/admin-frontend-vue/tests/task-36.test.ts
T
huangzd1997 837fc9bcc0 task-40(会话/菜单/权限): 真实登录态 smoke 收口本模块
用真实 admin 凭据打本地后端完成登录/cookie 会话/current-user/菜单树/401/
权限路由 smoke(8 场景全过)。smoke 暴露前端登出 URL 错误:session.ts 走
/api/admin/logout(后端无此映射,500),改为 auth 模块根端点 POST /logout;
同步修正 task-25/36 断言。注:当前本地后端 POST /logout 亦返回 500,属
Java 侧缺陷,待后端模块修复后补登出 E2E。
2026-09-05 14:43:59 +08:00

67 lines
2.9 KiB
TypeScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
import { runLogout } from '../src/layout/logout.ts'
test('test_task_036_logout_clear_state_normal_primary_path', async () => {
// 正常主路径:确认退出后调用 signOut(清态 + 跳登录)。
let called = 0
const signOut = async () => { called += 1 }
await runLogout({ confirm: async () => true, signOut })
assert.equal(called, 1)
})
test('test_task_036_logout_clear_state_normal_variant_input', async () => {
// 正常变体:确认返回 false 时取消退出,不调用 signOut。
let called = 0
await runLogout({ confirm: async () => false, signOut: async () => { called += 1 } })
assert.equal(called, 0)
})
test('test_task_036_logout_clear_state_normal_repeated_operation_is_idempotent', async () => {
// 正常重复:取消多次不触发退出;仅确认那次生效。
let called = 0
for (let i = 0; i < 3; i += 1) {
await runLogout({ confirm: async () => false, signOut: async () => { called += 1 } })
}
assert.equal(called, 0)
})
test('test_task_036_logout_clear_state_boundary_empty_input', async () => {
// 边界空值:confirm 未传/异常类型按 false 处理——不误退出。
let called = 0
await runLogout({ confirm: async () => false, signOut: async () => { called += 1 } })
assert.equal(called, 0)
})
test('test_task_036_logout_clear_state_boundary_single_item', async () => {
// 边界单元素:单次确认即完成一次完整退出。
let called = 0
await runLogout({ confirm: async () => true, signOut: async () => { called += 1 } })
assert.equal(called, 1)
})
test('test_task_036_logout_clear_state_boundary_limit_or_missing_field', async () => {
// 边界上限/缺字段:signOut 异常向上抛出,由调用方反馈(不清一半状态)。
await assert.rejects(
runLogout({ confirm: async () => true, signOut: async () => { throw new Error('登出失败') } }),
/登出失败/,
)
})
test('test_task_036_logout_clear_state_invalid_input_rejected', async () => {
// 异常输入:confirm 本身 reject 也向上抛,不静默吞掉。
await assert.rejects(runLogout({ confirm: async () => { throw new Error('弹窗异常') }, signOut: async () => {} }), /弹窗异常/)
})
test('test_task_036_logout_clear_state_dependency_failure_returns_actionable_message', async () => {
// 依赖失败:store.signOut 清态($reset)并跳登录页,会话模块先走后端 logout。
const store = readSource('src/stores/admin-session.ts')
assert.match(store, /async signOut\(\)/)
assert.match(store, /\$reset\(\)/)
assert.match(store, /location\.assign\('\/login'\)/)
const session = readSource('src/api/session.ts')
assert.match(session, /\/logout/, '登出走 auth 模块根端点 POST /logout')
assert.equal(session.includes('/api/admin/logout'), false, '不应指向不存在的 /api/admin/logout')
})