This commit is contained in:
@@ -40,3 +40,97 @@ test('dashboard and report endpoints enforce authentication, permissions, dates
|
||||
const trend=await(await app.request('/f/trend?start=2026-10-12&end=2026-10-13&level=未标注')).json();assert.equal(trend.totals.reported,0);
|
||||
const weekly=await(await app.request('/f/weekly-report?start=2026-10-12&end=2026-10-13&level=未标注')).json();assert.equal(weekly.totals.reported,0);
|
||||
});
|
||||
|
||||
test('focus contains only L1 unclosed faults across all dates and keeps totals and full drill consistent', () => {
|
||||
const focusRows = [
|
||||
fault('waiting', { reported_at: '2026-09-01 08:00:00' }),
|
||||
fault('processing', { handling_status: '处理中', deadline_at: '2026-10-12 15:00:00' }),
|
||||
fault('paused', { handling_status: '挂起', deadline_at: '2026-10-01 08:00:00' }),
|
||||
fault('review', { handling_status: '审核中' }),
|
||||
fault('unknown', { handling_status: '其他状态' }),
|
||||
fault('sixth'),
|
||||
fault('seventh'),
|
||||
fault('closed', { handling_status: '已归档' }),
|
||||
fault('l2-overdue', { fault_level: 2, deadline_at: '2026-10-01 08:00:00' }),
|
||||
fault('l3', { fault_level: 3 }),
|
||||
fault('l4', { fault_level: 4 }),
|
||||
fault('unmarked', { fault_level: null }),
|
||||
];
|
||||
const dashboard = faultDashboard(focusRows, q, updatedAt);
|
||||
assert.deepEqual(dashboard.focusTotals, { total: 7, overdue: 1 });
|
||||
assert.equal(dashboard.focus.length, 5);
|
||||
assert.equal(dashboard.focus[0].id, 'processing');
|
||||
assert.ok(dashboard.focus.every(row => row.level === 'L1-特急' && row.status !== '已归档'));
|
||||
const allFocus = dashboardAnalysis(focusRows, { ...q, scope: 'focus' }, updatedAt).rows;
|
||||
assert.equal(allFocus.length, dashboard.focusTotals.total);
|
||||
assert.ok(allFocus.some(row => row.id === 'waiting'));
|
||||
assert.ok(allFocus.some(row => row.id === 'paused'));
|
||||
assert.ok(allFocus.some(row => row.id === 'review'));
|
||||
assert.ok(allFocus.every(row => !('vehicleKey' in row) && !('managerId' in row)));
|
||||
assert.deepEqual(dashboardAnalysis(focusRows, { ...q, scope: 'focus', id: 'closed' }, updatedAt).rows, []);
|
||||
const filtered = faultDashboard(focusRows, { ...q, level: 'L2-紧急' }, updatedAt);
|
||||
assert.deepEqual(filtered.focus, []);
|
||||
assert.deepEqual(filtered.focusTotals, { total: 0, overdue: 0 });
|
||||
assert.deepEqual(dashboardAnalysis(focusRows, { ...q, scope: 'focus', level: 'L2-紧急' }, updatedAt).rows, []);
|
||||
});
|
||||
test('focus dashboard and full drill enforce permissions and business filters before selecting L1 faults', async () => {
|
||||
const scopedRows = [fault('allowed'), fault('outside', { business_dept: '部门B' }), fault('closed', { handling_status: '已归档' }), fault('lower', { fault_level: 2 })];
|
||||
const user: AuthUser = { userId: 'test', loginName: 'test', userName: '测试', roles: [], permissionLevel: 'department', depName: '部门A', depCode: 'a' };
|
||||
const app = new Hono<{ Variables: { user: AuthUser } }>();
|
||||
app.use('*', async (c, next) => { c.set('user', user); await next(); });
|
||||
app.route('/f', createFaultRouter(async () => ({ rows: scopedRows, updatedAt })));
|
||||
const report = await (await app.request('/f/dashboard?start=2026-10-12&end=2026-10-13')).json();
|
||||
assert.deepEqual(report.focus.map((row: { id: string }) => row.id), ['allowed']);
|
||||
assert.deepEqual(report.focusTotals, { total: 1, overdue: 0 });
|
||||
const response = await app.request('/f/dashboard-analysis?start=2026-10-12&end=2026-10-13&scope=focus');
|
||||
assert.equal(response.status, 200);
|
||||
const detail = await response.json();
|
||||
assert.deepEqual(detail.rows.map((row: { id: string }) => row.id), ['allowed']);
|
||||
const empty = await (await app.request('/f/dashboard-analysis?scope=focus&department=不存在')).json();
|
||||
assert.deepEqual(empty.rows, []);
|
||||
});
|
||||
|
||||
test('report source follows explicit OneOS report method before legacy task linkage', () => {
|
||||
const cases: [Record<string, unknown>, 'operations' | 'customer'][] = [
|
||||
[{ report_method: '运维上报', source_work_order_id: '9007199254740993' }, 'operations'],
|
||||
[{ report_method: '客户上报', source_work_order_id: null }, 'customer'],
|
||||
[{ report_method: ' 客户上报 ', source_work_order_id: '123' }, 'customer'],
|
||||
[{ report_method: null, source_work_order_id: '9007199254740993' }, 'customer'],
|
||||
[{ report_method: '', source_work_order_id: null }, 'operations'],
|
||||
[{ report_method: null, source_work_order_id: null, fault_source: 6 }, 'operations'],
|
||||
];
|
||||
for (const [raw, expected] of cases) assert.equal(fault('source', raw).reportMethod, expected);
|
||||
});
|
||||
test('reported source counts reconcile with cohort, filtered drills, permissions and export labels', async () => {
|
||||
const sourceRows = [
|
||||
fault('ops-linked', { report_method: '运维上报', source_work_order_id: '123' }),
|
||||
fault('ai-explicit', { report_method: '客户上报', source_work_order_id: null }),
|
||||
fault('ai-legacy', { report_method: null, source_work_order_id: '9007199254740993', handling_status: '已归档' }),
|
||||
fault('ops-legacy', { report_method: null, source_work_order_id: null }),
|
||||
fault('previous-ai', { report_method: '客户上报', reported_at: '2026-10-10 10:00:00' }),
|
||||
fault('hidden-ai', { report_method: '客户上报', business_dept: '部门B' }),
|
||||
];
|
||||
const user: AuthUser = { userId: 'test', loginName: 'test', userName: '测试', roles: [], permissionLevel: 'department', depName: '部门A', depCode: 'a' };
|
||||
const app = new Hono<{ Variables: { user: AuthUser } }>();
|
||||
app.use('*', async (c, next) => { c.set('user', user); await next(); });
|
||||
app.route('/f', createFaultRouter(async () => ({ rows: sourceRows, updatedAt })));
|
||||
const query = new URLSearchParams(q);
|
||||
const report = await (await app.request(`/f/dashboard?${query}`)).json();
|
||||
assert.equal(report.totals.reported, 4);
|
||||
assert.equal(report.totals.operationsReported, 2);
|
||||
assert.equal(report.totals.customerReported, 2);
|
||||
assert.equal(report.totals.operationsReported + report.totals.customerReported, report.totals.reported);
|
||||
assert.equal(report.options.reportMethod.find((o: { value: string }) => o.value === 'customer').label, 'AI提报');
|
||||
assert.equal(report.options.reportMethod.find((o: { value: string }) => o.value === 'operations').label, '运维提报');
|
||||
for (const [method, expected] of [['operations', ['ops-linked', 'ops-legacy']], ['customer', ['ai-explicit', 'ai-legacy']]] as const) {
|
||||
const response = await app.request(`/f/dashboard-analysis?${query}&scope=cohort&reportMethod=${method}`);
|
||||
assert.equal(response.status, 200);
|
||||
const detail = await response.json();
|
||||
assert.deepEqual(detail.rows.map((row: { id: string }) => row.id).sort(), [...expected].sort());
|
||||
const filtered = await (await app.request(`/f/dashboard?${query}&reportMethod=${method}`)).json();
|
||||
assert.equal(filtered.totals.reported, expected.length);
|
||||
assert.equal(filtered.totals.operationsReported + filtered.totals.customerReported, filtered.totals.reported);
|
||||
}
|
||||
const empty = await (await app.request(`/f/dashboard?${query}®ion=不存在`)).json();
|
||||
assert.equal(empty.totals.operationsReported, 0); assert.equal(empty.totals.customerReported, 0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user