Files
zkxw/web-admin/tests/project-management.test.ts
T
zlwu bd62416263 feat(project): add team attribution and business statistics
Add tenant-scoped teams and projects, order attribution across four businesses, conversion inheritance, scoped statistics and audited reassignment. Reuse existing Web and mobile UI patterns; team regions and hospitals remain informational.

Include incremental SQL and isolated regression coverage. Actual MySQL and browser/WebView integration validation remains pending; relates to issue #13.
2026-11-02 15:29:43 +08:00

76 lines
2.3 KiB
TypeScript

import assert from 'node:assert/strict'
import test from 'node:test'
import { buildDrillFilters, assignmentSnapshot } from '../src/utils/project-management'
test('drill preserves applied dates and selected project when a team is opened', () => {
assert.deepEqual(
buildDrillFilters(
{ groupBy: 'team', projectId: 'project-1', startDate: '2026-01-01', endDate: '2026-01-31' },
{ id: 'team-1' },
'cell_storage'
),
{
projectId: 'project-1',
teamId: 'team-1',
startDate: '2026-01-01',
endDate: '2026-01-31',
bizType: 'cell_storage',
unassigned: false
}
)
})
test('unassigned drill preserves active scope so detail counts match the filtered summary', () => {
assert.deepEqual(
buildDrillFilters(
{ groupBy: 'project', projectId: 'p', teamId: 't' },
{ id: 'unassigned' },
'research_donation'
),
{ projectId: 'p', teamId: 't', bizType: 'research_donation', unassigned: true }
)
})
test('assignment snapshot preserves nullable old ownership and excludes display-only data', () => {
assert.deepEqual(
assignmentSnapshot([
{ bizType: 'presign', id: 'a', projectId: null, projectName: 'old', secret: 'x' }
]),
[{ bizType: 'presign', id: 'a', projectId: null }]
)
})
test('management payload excludes readonly response fields and preserves child IDs', async () => {
const { managementPayload } = await import('../src/utils/project-management')
assert.deepEqual(
managementPayload('teams', {
id: 't',
teamName: 'Team',
leaderUserId: 'u',
leaderName: 'Name',
enabled: true,
remark: '',
members: [{ id: 'm', userId: 'u', name: 'Name' }],
regions: [],
hospitals: [],
createTime: 'today'
}),
{
teamName: 'Team',
leaderUserId: 'u',
enabled: true,
remark: '',
members: [{ id: 'm', userId: 'u' }],
regions: [],
hospitals: []
}
)
})
test('filter options use visible historical scope; create and reassignment remain strict', async () => {
const { projectOptionsParams } = await import('../src/utils/project-management')
assert.deepEqual(projectOptionsParams('cell_storage', true), {
bizType: 'cell_storage',
usage: 'filter'
})
assert.deepEqual(projectOptionsParams('cell_storage', false), { bizType: 'cell_storage' })
})