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' }) })