payroll-gateway-transform.test.mjs 1.7 KB

1234567891011121314151617181920212223242526272829
  1. import test from 'node:test';
  2. import assert from 'node:assert/strict';
  3. import { readFileSync } from 'node:fs';
  4. import { normalizeHistoricalReservationPreviewBase } from '../payroll-gateway-transform.mjs';
  5. const original = "async function historicalReservationPreview(context,input){return 'legacy';}\n";
  6. const legacy = "async function historicalReservationPreviewLegacy(context,input){return 'legacy';}\n";
  7. 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";
  8. test('首次增量发布会保留一个旧预览入口', () => {
  9. const result = normalizeHistoricalReservationPreviewBase(original);
  10. assert.equal(result.includes('historicalReservationPreview(context,input)'), false);
  11. assert.equal(result.split('historicalReservationPreviewLegacy(context,input)').length - 1, 1);
  12. });
  13. test('重复增量发布会移除递归包装并保留真正的旧预览', () => {
  14. const result = normalizeHistoricalReservationPreviewBase(legacy + broken);
  15. assert.equal(result, legacy);
  16. assert.equal(result.includes('data=await historicalReservationPreviewLegacy'), false);
  17. });
  18. test('缺少历史预约预览入口时拒绝发布', () => {
  19. assert.throws(() => normalizeHistoricalReservationPreviewBase('function unrelated(){}'), /版本不兼容/);
  20. });
  21. test('历史预约预览保留数据库微秒精度,避免确认时误判预约已更新', () => {
  22. const integrity = readFileSync(new URL('../cloud/payroll-integrity.js', import.meta.url), 'utf8');
  23. assert.match(integrity, /a\."updatedAt"::text AS "updatedAt"/);
  24. });