Files
syops/frontend/src/features/admin/e2e/shipping-audit.spec.ts
T
hugo d0fe084999 feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全
- 引入审计事件的哈希链校验机制,支持数据完整性验证
- 增强订单抽取与审计功能,支持敏感快照的访问控制
- 更新相关模型与服务,确保新功能的完整性与可追溯性
- 完善文档与代码注释,反映新的业务逻辑与审计要求
2026-07-31 08:59:44 +08:00

127 lines
4.1 KiB
TypeScript

/**
* features/admin/e2e/shipping-audit.spec.ts
* 用途:阶段 4 管理员审计中心契约冒烟——权限脱敏、Diff、关联链与哈希校验 DTO。
* 依赖:Vitest、shipping-audit.api 类型约定。
* 逻辑:断言列表不含快照;筛选含 Workflow/Item/Run/PDF/Case/Task;敏感脱敏字段存在。
*/
import { describe, expect, it } from 'vitest';
import type {
ShippingAuditAssociationChain,
ShippingAuditDiffRow,
ShippingAuditEventDetail,
ShippingAuditEventSummary,
ShippingAuditFilters,
ShippingAuditHashVerifyResult,
} from '@/features/admin/api/shipping-audit.api';
describe('shipping audit center e2e contract', () => {
it('list summary must not carry snapshot bodies', () => {
const summary: ShippingAuditEventSummary = {
id: 1,
event_type: 'candidate_promoted',
aggregate_type: 'shipping_task',
aggregate_id: 'ST-1',
actor_type: 'user',
has_snapshots: true,
run_no: 'SNER-1',
task_no: 'ST-1',
workflow_id: 'WF-1',
workflow_item_id: 'WFI-1',
operation_id: 'op-1',
};
// 关键断言:列表 DTO 无 before/after 快照字段,避免误渲染正文。
expect('before_snapshot' in summary).toBe(false);
expect('after_snapshot' in summary).toBe(false);
expect(summary.has_snapshots).toBe(true);
});
it('detail diff only exposes whitelist change rows', () => {
const detail: ShippingAuditEventDetail = {
id: 2,
event_type: 'order_extraction_run_status_changed',
aggregate_type: 'order_extraction_run',
aggregate_id: 'SNER-2',
actor_type: 'system',
has_snapshots: true,
sensitive_redacted: false,
before_snapshot: { status: 'queued' },
after_snapshot: { status: 'processing' },
diff: [
{ key: 'status', change: 'changed', before: 'queued', after: 'processing' },
] satisfies ShippingAuditDiffRow[],
};
expect(detail.diff?.[0]?.key).toBe('status');
expect(JSON.stringify(detail)).not.toContain('email_body');
expect(JSON.stringify(detail)).not.toContain('https://');
});
it('sensitive detail can be redacted by permission', () => {
const detail: ShippingAuditEventDetail = {
id: 4,
event_type: 'order_review_confirmed',
aggregate_type: 'shipping_order_review_case',
aggregate_id: 'SRC-4',
actor_type: 'user',
has_snapshots: true,
sensitivity_level: 'sensitive',
sensitive_redacted: true,
before_snapshot: null,
after_snapshot: null,
diff: [],
};
// 关键断言:无 audit_sensitive_read 时敏感正文脱敏。
expect(detail.sensitive_redacted).toBe(true);
expect(detail.before_snapshot).toBeNull();
expect(detail.diff).toEqual([]);
});
it('export disabled error code is stable for i18n', () => {
const code = 'SHIPPING_NOTICE.AUDIT_EXPORT_FEATURE_DISABLED';
expect(code.startsWith('SHIPPING_NOTICE.')).toBe(true);
});
it('audit filters carry workflow association query keys', () => {
const filters: ShippingAuditFilters = {
workflow_id: 'WF-1',
workflow_item_id: 'WFI-1',
run_no: 'SNER-1',
document_id: '42',
review_case_no: 'SRC-1',
task_no: 'ST-1',
actor_id: '9',
result: 'success',
};
// 关键断言:前端筛选 DTO 与 admin API _audit_filters_from_request 键对齐。
expect(Object.keys(filters).sort()).toEqual([
'actor_id',
'document_id',
'result',
'review_case_no',
'run_no',
'task_no',
'workflow_id',
'workflow_item_id',
]);
});
it('association chain and hash verify DTOs expose integrity fields', () => {
const chain: ShippingAuditAssociationChain = {
items: [],
total: 0,
association_keys: { workflow_id: ['WF-1'], task_no: ['ST-1'] },
truncated: false,
limit: 500,
};
const verify: ShippingAuditHashVerifyResult = {
ok: true,
checked_chains: 3,
failed_chains: 0,
failures_sample: [],
mode: 'sample',
};
expect(chain.association_keys.workflow_id).toEqual(['WF-1']);
expect(verify.failed_chains).toBe(0);
expect(verify.ok).toBe(true);
});
});