99d6109bef
build / build (push) Successful in 1m12s
按稳定身份展示零使用人员、个人次数与最近提问时间,直接部门去重计算兼属数量;保留原分支统计、配置和源问答。 验证:396项前端测试及类型检查通过;隔离PG全mirror/org竞态回归通过,个人/别名/同名/零使用/未关联与原部门汇总回归通过。 正式同镜像及上线验证尚未执行。
70 lines
3.2 KiB
TypeScript
70 lines
3.2 KiB
TypeScript
import { it, expect } from 'vitest'
|
|
import { parseDepartmentStatistics } from './qaDepartmentStatistics'
|
|
import { departmentStatisticsFixture as fixture } from './qaDepartmentStatistics.fixture'
|
|
it('preserves source roster denominators, null zero-denominator ratio and exact cache identity', () => {
|
|
const data = parseDepartmentStatistics(fixture, { period: 'all' })
|
|
expect(data.snapshot?.rows[0].visitors).toBe(2)
|
|
expect(data.snapshot?.rows[0].total_people).toBe(3)
|
|
expect(data.snapshot?.rows[2].ratio).toBeNull()
|
|
expect(data.cache_key).toBe(fixture.cache_key)
|
|
})
|
|
it('preserves distinct personal row keys, direct multi-department memberships and zero-use roster people', () => {
|
|
const snapshot = parseDepartmentStatistics(fixture, { period: 'all' }).snapshot!
|
|
expect((snapshot as unknown as { people: unknown }).people).toEqual(fixture.snapshot.people)
|
|
})
|
|
it('rejects private identities, repeated keys/memberships, unknown departments and inflated personal totals', () => {
|
|
for (const mutate of [
|
|
(p: typeof fixture.snapshot.people) => {
|
|
Object.assign(p[0], { staff_id: 'forbidden' })
|
|
},
|
|
(p: typeof fixture.snapshot.people) => {
|
|
p[1].key = p[0].key
|
|
},
|
|
(p: typeof fixture.snapshot.people) => {
|
|
p[0].department_ids.push('child')
|
|
},
|
|
(p: typeof fixture.snapshot.people) => {
|
|
p[0].department_ids.push('missing')
|
|
},
|
|
(p: typeof fixture.snapshot.people) => {
|
|
p[0].visits++
|
|
},
|
|
(p: typeof fixture.snapshot.people) => {
|
|
p[2].last_asked_at = fixture.snapshot.people[0].last_asked_at
|
|
},
|
|
]) {
|
|
const copy = structuredClone(fixture)
|
|
mutate(copy.snapshot.people)
|
|
expect(() => parseDepartmentStatistics(copy, { period: 'all' })).toThrow()
|
|
}
|
|
})
|
|
it('keeps same-named distinct people separate and includes explicitly unassigned activity', () => {
|
|
const copy = structuredClone(fixture)
|
|
copy.snapshot.people[1].name = copy.snapshot.people[0].name
|
|
copy.snapshot.total_people++
|
|
copy.snapshot.people.push({
|
|
key: 'person-' + '4'.repeat(64),
|
|
name: 'Unassigned',
|
|
department_ids: [],
|
|
visits: 1,
|
|
last_asked_at: copy.snapshot.people[0].last_asked_at,
|
|
})
|
|
const data = parseDepartmentStatistics(copy, { period: 'all' }).snapshot!
|
|
expect(data.people).toHaveLength(4)
|
|
expect(data.rows[0].total_people).toBe(3)
|
|
expect(data.people.filter((p) => p.name === 'Fixture Alpha')).toHaveLength(2)
|
|
})
|
|
it('rejects fake zeros, invalid hierarchy, inconsistent ratios and wrong conditions', () => {
|
|
for (const rows of [
|
|
fixture.snapshot.rows.map((r) => (r.id === 'empty' ? { ...r, ratio: 0 } : r)),
|
|
fixture.snapshot.rows.map((r) => (r.id === 'child' ? { ...r, parent_id: 'missing' } : r)),
|
|
fixture.snapshot.rows.map((r) => (r.id === 'child' ? { ...r, visitors: 3 } : r)),
|
|
fixture.snapshot.rows.map((r) => (r.id === 'child' ? { ...r, ratio: 70 } : r)),
|
|
fixture.snapshot.rows.map((r) => (r.id === 'child' ? { ...r, last_asked_at: '2027-01-01T00:00:00Z' } : r)),
|
|
])
|
|
expect(() =>
|
|
parseDepartmentStatistics({ ...fixture, snapshot: { ...fixture.snapshot, rows } }, { period: 'all' })
|
|
).toThrow()
|
|
expect(() => parseDepartmentStatistics(fixture, { period: 'month', month: '2026-10' })).toThrow()
|
|
})
|