import test from 'node:test' import assert from 'node:assert/strict' import { readSource } from './helpers.ts' import { HISTORY_DEFAULT_PAGE_SIZE, emptyHistoryPage, normalizeHistoryParams, toHistoryListQuery, } from '../src/pages/records/history-dto.ts' test('test_task_121_history_dto_normal_primary_path', () => { // 正常主路径:历史筛选归一并序列化为 snake 查询参数。 const params = normalizeHistoryParams({ page: 2, pageSize: 20, userId: 3, timeStart: '2026-01-01 00:00:00', timeEnd: '2026-01-31 23:59:59' }) assert.equal(params.page, 2) const query = toHistoryListQuery(params) assert.equal(query.page, 2) assert.equal(query.page_size, 20) assert.equal(query.user_id, 3) assert.equal(query.time_start, '2026-01-01 00:00:00') assert.equal(query.time_end, '2026-01-31 23:59:59') }) test('test_task_121_history_dto_normal_variant_input', () => { // 正常变体:仅时间起始筛选;空 userId 不下发。 const query = toHistoryListQuery(normalizeHistoryParams({ page: 1, pageSize: 15, userId: null, timeStart: '2026-02-01' })) assert.equal('user_id' in query, false) assert.equal(query.time_start, '2026-02-01') }) test('test_task_121_history_dto_repeated_is_idempotent', () => { // 正常重复:归一不改输入、结果稳定。 const input = { page: 1, pageSize: 15, timeStart: ' a ' } assert.deepEqual(normalizeHistoryParams(input), normalizeHistoryParams(input)) assert.equal((input as { timeStart: string }).timeStart, ' a ') }) test('test_task_121_history_dto_boundary_empty_input', () => { // 边界空值:空入参回默认分页。 const params = normalizeHistoryParams({}) assert.equal(params.page, 1) assert.equal(params.pageSize, HISTORY_DEFAULT_PAGE_SIZE) assert.equal(params.userId, null) }) test('test_task_121_history_dto_boundary_single_item', () => { // 边界单元素:单记录空结果 DTO 结构完整。 const page = emptyHistoryPage() assert.deepEqual(page.items, []) assert.equal(page.total, 0) assert.equal(page.page, 1) }) test('test_task_121_history_dto_boundary_limit_or_missing_field', () => { // 边界上限/缺字段:页码/页大小钳制;非法 userId 忽略。 const params = normalizeHistoryParams({ page: 0, pageSize: 999, userId: -1 }) assert.equal(params.page, 1) assert.equal(params.pageSize, 200) assert.equal(params.userId, null) }) test('test_task_121_history_dto_invalid_input_rejected', () => { // 异常输入:NaN 回默认。 const params = normalizeHistoryParams({ page: Number.NaN, pageSize: Number.NaN }) assert.equal(params.page, 1) assert.equal(params.pageSize, HISTORY_DEFAULT_PAGE_SIZE) }) test('test_task_121_history_dto_dependency_failure_returns_actionable_message', () => { // 依赖失败/可操作:DTO 纯逻辑、无框架/http;历史页与版本/公开接口分离。 const mod = readSource('src/pages/records/history-dto.ts') assert.equal(/axios|http\.|vue/.test(mod), false, '历史 DTO 保持纯逻辑') assert.match(mod, /HistoryRecord/) assert.match(mod, /page_size/) })