Files
crawler-plugin/admin-frontend-vue/tests/align-history-clear.test.ts
T

35 lines
1.9 KiB
TypeScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
// 验收反馈:生成记录的数据要可清理。
// 契约:页面有「清理数据」入口(二次确认)、前端 DELETE /api/admin/history、后端清空端点与日志。
test('align_history_clear_normal_primary_path', () => {
const page = readSource('src/pages/records/RecordsHistoryPage.vue')
assert.match(page, /清理数据/, '页头有清理数据按钮')
assert.match(page, /确定清空全部生成记录吗/, '清理前需二次确认')
assert.match(page, /clearHistory\(\)/, '页面调用清理 API')
})
test('align_history_clear_normal_variant_input', () => {
const api = readSource('src/pages/records/history-api.ts')
assert.match(api, /http\.delete<unknown>\(HISTORY_ENDPOINT\)/, '清理走 DELETE /api/admin/history')
assert.match(api, /clearHistory/, '暴露 clearHistory 适配函数')
})
test('align_history_clear_boundary_empty_input', () => {
const page = readSource('src/pages/records/RecordsHistoryPage.vue')
assert.match(page, /已清空 \$\{removed\} 条生成记录/, '成功提示含清理条数')
})
test('align_history_clear_dependency_failure_returns_actionable_message', () => {
// 后端契约:DELETE /history 端点 + service 清空 + 中文排查日志。
const ctrl = readSource('../backend-java/src/main/java/com/nanri/aiimage/modules/imagehistory/controller/ImageHistoryController.java')
assert.match(ctrl, /@DeleteMapping\("\/history"\)/, '后端有 DELETE /api/admin/history 端点')
assert.match(ctrl, /admin_history/, '清理端点沿用生成记录模块权限')
const service = readSource('../backend-java/src/main/java/com/nanri/aiimage/modules/imagehistory/service/ImageHistoryService.java')
assert.match(service, /clearAllHistory/, 'service 有清空方法')
assert.match(service, /清空生成记录,共清理/, '清空操作留中文排查日志')
})