import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' import test from 'node:test' test('第三方卡券面板提供安全删除入口并格式化生效时间', async () => { const [panel, service] = await Promise.all([ readFile( new URL('../src/pages/admin/cost-center/VoucherSkuPanel.tsx', import.meta.url), 'utf8', ), readFile(new URL('../src/services/admin/cost-center.ts', import.meta.url), 'utf8'), ]) assert.ok(panel.includes('deleteAdminVoucherProduct')) assert.ok(panel.includes('DeleteOutlined')) assert.ok(panel.includes('Popconfirm')) assert.ok(panel.includes('已有历史订单或成本快照时会自动归档')) assert.ok(panel.includes('formatAdminDateTime(value)')) assert.ok(service.includes('/api/v1/admin/cost-center/voucher-products/${productId}')) assert.ok(service.includes("action: 'deleted' | 'archived'")) }) test('第三方卡券新增 SKU 一次完成商品、规则和采购价', async () => { const [panel, service, productCatalog] = await Promise.all([ readFile( new URL('../src/pages/admin/cost-center/VoucherSkuPanel.tsx', import.meta.url), 'utf8', ), readFile(new URL('../src/services/admin/cost-center.ts', import.meta.url), 'utf8'), readFile( new URL('../src/pages/admin/cost-center/ProductCatalogPanel.tsx', import.meta.url), 'utf8', ), ]) assert.ok(panel.includes('新增卡券 SKU')) assert.ok(panel.includes('saveAdminVoucherProduct')) assert.ok(panel.includes('保存后自动生成 tpv:<内部 SKU> 标准商品和卡券渠道规则')) assert.ok(panel.includes('补建成本快照')) assert.ok(!panel.includes('批量生成渠道规则')) assert.ok(!panel.includes('ensureVoucherChannelRules')) assert.ok(service.includes('apiPost<')) assert.ok(service.includes("'/api/v1/admin/cost-center/voucher-products'")) assert.ok(!service.includes('/voucher-products/ensure-rules')) assert.ok(panel.includes("searchParams.get('voucherNew')")) assert.ok(productCatalog.includes("channelFilter === 'third_party_voucher'")) assert.ok(productCatalog.includes('voucherNew=1')) })