Files
SupplierSystem/server/tests/riskRadarRealSources.test.ts
T
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库:jxc/ai-fresh-delivery
来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d
快照树:  09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件)

按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据
(生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、
deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

97 lines
3.9 KiB
TypeScript

import { readFileSync } from 'fs';
import path from 'path';
import { describe, expect, it } from 'vitest';
/**
* 风险雷达必须每条都有服务端真实数据源:
* - 删除查 notifications(timeout_alert) 的前端实现(该 notify_type 全仓无写入方,恒 0);
* - 逾期未送达改用 orders 真实字段(配送日已过且未完成);
* - 临期/过期只有在确实跟踪效期时才显示,避免把"没数据"显示成"没风险"。
* 背景见 docs/design/20260914-risk-radar-real-sources.md
*/
const readSource = (rel: string) => readFileSync(path.join(__dirname, '..', rel), 'utf8');
describe('服务端:风险雷达真实字段', () => {
const src = readSource('src/services/dashboardService.ts');
it('逾期未送达按 orders 真实字段统计(含未发车/配送中拆分)', () => {
expect(src).toContain('AS overdue,');
expect(src).toContain('AS not_shipped,');
expect(src).toContain('AS in_transit');
expect(src).toContain('overdueOrders:');
expect(src).toContain('overdueNotShipped:');
expect(src).toContain('overdueInTransit:');
expect(src).toContain("o.delivery_date < (NOW() AT TIME ZONE 'Asia/Shanghai')::date");
expect(src).toContain('o.order_status < 90');
});
it('售后进行中按 after_sales.status IN (10,20) 统计', () => {
expect(src).toContain('FROM after_sales a');
expect(src).toContain('COALESCE(a.status, 0) IN (10, 20)');
});
it('临期/过期只统计有可用量的行,并给出效期跟踪行数', () => {
expect(src).toContain('AS expiring_soon,');
expect(src).toContain('AS expired');
expect(src).toContain('AS tracked,');
expect(src).toContain('expiryTrackedCount:');
expect(src).toContain('COALESCE(i.available_qty, 0) > 0');
});
it('不再依赖通知表的超时预警(注释里的历史说明不算)', () => {
expect(src).not.toContain('FROM notifications');
expect(src).not.toContain("from('notifications')");
});
});
describe('前端:雷达条目都有真实来源', () => {
const page = readSource('../src/pages/Dashboard.tsx');
it('删除了查通知表超时预警的前端实现(注释里保留历史说明不算)', () => {
// 断言的是"查询行为"已移除:不再 from('notifications') / notify_type 过滤 / 该 state
expect(page).not.toContain("from('notifications')");
expect(page).not.toContain('notify_type');
expect(page).not.toContain('loadTimeoutAlertCount');
expect(page).not.toContain('setTimeoutAlertCount');
expect(page).not.toMatch(/const \[timeoutAlertCount/);
});
it('逾期/售后/临期/过期都读服务端字段', () => {
for (const field of [
'stats.overdueOrders',
'stats.overdueNotShipped',
'stats.overdueInTransit',
'stats.openAfterSalesCount',
'stats.expiredCount',
'stats.expiryTrackedCount',
]) {
expect(page, field).toContain(field);
}
});
it('临期/过期条目受"是否跟踪效期"约束', () => {
expect(page).toContain('expiryTracked > 0 && expiringSoon > 0');
expect(page).toContain('expiryTracked > 0 && expired > 0');
});
});
describe('i18n:雷达文案三语齐备', () => {
for (const loc of ['zh-CN', 'en', 'id']) {
it(`${loc} 有 overdue/afterSales/expired 且已无 timeout 文案`, () => {
const text = readFileSync(
path.join(__dirname, '..', '..', 'src', 'i18n', 'locales', loc, 'dashboard.ts'),
'utf8'
);
expect(text).toContain("'alert.overdue'");
expect(text).toContain("'alert.afterSales'");
expect(text).toContain("'alert.expired'");
expect(text).not.toContain("'alert.timeout'");
const overdueBlock = text.slice(text.indexOf("'alert.overdue'"), text.indexOf("'alert.overdue'") + 300);
for (const holder of ['{count}', '{notShipped}', '{inTransit}']) {
expect(overdueBlock, `${loc} ${holder}`).toContain(holder);
}
});
}
});