| 1234567891011121314151617181920212223242526272829 |
- import test from 'node:test';
- import assert from 'node:assert/strict';
- import { readFileSync } from 'node:fs';
- import { normalizeHistoricalReservationPreviewBase } from '../payroll-gateway-transform.mjs';
- const original = "async function historicalReservationPreview(context,input){return 'legacy';}\n";
- const legacy = "async function historicalReservationPreviewLegacy(context,input){return 'legacy';}\n";
- const broken = "async function historicalReservationPreviewLegacy(context,input){const co=payrollTenant(context,input),data=await historicalReservationPreviewLegacy(context,input),rows=await Psql.query('SELECT 1');return{...data,items:data.items.map(i=>i)};}\n";
- test('首次增量发布会保留一个旧预览入口', () => {
- const result = normalizeHistoricalReservationPreviewBase(original);
- assert.equal(result.includes('historicalReservationPreview(context,input)'), false);
- assert.equal(result.split('historicalReservationPreviewLegacy(context,input)').length - 1, 1);
- });
- test('重复增量发布会移除递归包装并保留真正的旧预览', () => {
- const result = normalizeHistoricalReservationPreviewBase(legacy + broken);
- assert.equal(result, legacy);
- assert.equal(result.includes('data=await historicalReservationPreviewLegacy'), false);
- });
- test('缺少历史预约预览入口时拒绝发布', () => {
- assert.throws(() => normalizeHistoricalReservationPreviewBase('function unrelated(){}'), /版本不兼容/);
- });
- test('历史预约预览保留数据库微秒精度,避免确认时误判预约已更新', () => {
- const integrity = readFileSync(new URL('../cloud/payroll-integrity.js', import.meta.url), 'utf8');
- assert.match(integrity, /a\."updatedAt"::text AS "updatedAt"/);
- });
|