Files
railwaysystem/build_ui/tests/unit/accommodationStatusEnum.spec.mjs
T
wangzhibiaoandCursor aeb76ce35a 修复住宿:统一住宿生命周期状态与状态变更入口
住宿状态在数据库与业务上只有 0 预分配 / 1 已入住 / 2 已退宿三种,不存在 3 已调房。
调房是业务操作,真实语义为旧记录置退宿、新记录置在住,不应表现为独立状态值。

- 前端住宿页面移除筛选项与两处状态标签中的"已调房"(status=3),补齐历史表格缺失的预分配标签
- 后端通用 PUT /train/accommodation 封死 accommodation_status 写入路径,
  状态变更只能经办理入住、办理退宿、调房等专属业务操作
- 新增住宿状态白名单守卫,非法整数与新增即退宿一律拒绝入库

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-22 17:03:43 +08:00

41 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const pagePath = path.resolve(__dirname, '../../src/views/train/accommodation/index.vue');
const source = fs.readFileSync(pagePath, 'utf8');
console.log('=== Running Accommodation Status Enum Tests (FIX-04) ===');
// Runtime Truth:train_accommodation.accommodation_status 仅有 0=预分配 / 1=在住 / 2=已退宿。
// 不存在 3=已调房;调房的真实语义是旧记录置 2、新记录置 1。
{
assert.strictEqual(source.includes('已调房'), false, '页面不得再出现「已调房」状态文案');
assert.strictEqual(/accommodationStatus\s*===\s*3/.test(source), false, '页面不得再存在 accommodationStatus === 3 分支');
assert.strictEqual(/<el-option[^>]*:value="3"/.test(source), false, '筛选项不得再提供 value=3 的住宿状态');
console.log('✔ PASS: no phantom status 3 (已调房) remains in the accommodation page');
}
// 合法状态枚举必须完整保留
{
assert.strictEqual(/<el-option label="预分配" :value="0" \/>/.test(source), true, '筛选项必须保留 0=预分配');
assert.strictEqual(/<el-option label="在住" :value="1" \/>/.test(source), true, '筛选项必须保留 1=在住');
assert.strictEqual(/<el-option label="已退宿" :value="2" \/>/.test(source), true, '筛选项必须保留 2=已退宿');
const statusOptions = source.match(/<el-option label="[^"]+" :value="\d" \/>/g) || [];
assert.strictEqual(statusOptions.length, 3, '住宿状态筛选项必须恰好为 3 个合法枚举值');
console.log('✔ PASS: legal status enum 0/1/2 fully preserved');
}
// 调房仍然是业务操作,不得被误删
{
assert.strictEqual(source.includes('handleOpenTransfer'), true, '调房业务操作入口必须保留');
assert.strictEqual(source.includes('transferAccommodation'), true, '调房后端调用必须保留');
assert.strictEqual(source.includes('getAccommodationHistory'), true, '住宿履历查询必须保留');
console.log('✔ PASS: room transfer stays a business operation, not a fake status');
}
console.log('=== All Accommodation Status Enum Unit Tests Passed ===');