feat(qaops): 增加版本化部门区域归属配置与预览
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { fetchOrganization, parseOrganization, changeRegionRule } from './qaOrg'
|
||||
|
||||
export const directoryFixture = {
|
||||
state: 'ready',
|
||||
directory_id: 'dir-fixture',
|
||||
directory_source: 'weekly_report_snapshot',
|
||||
directory_synced_at: '2026-09-27T14:03:44Z',
|
||||
revision_id: '',
|
||||
updated_by: '',
|
||||
updated_at: null,
|
||||
rules: [],
|
||||
view: {
|
||||
departments: [
|
||||
{
|
||||
id: 'root',
|
||||
parent_id: '',
|
||||
name: '示例公司',
|
||||
path: '示例公司',
|
||||
region: '',
|
||||
explicit: false,
|
||||
inherited_from: '',
|
||||
},
|
||||
],
|
||||
regions: { 国内工业: 0, APAC: 0, EMEA: 0, America: 0 },
|
||||
total_people: 1,
|
||||
unassigned_people: 1,
|
||||
conflicting_people: 0,
|
||||
missing_departments: [],
|
||||
},
|
||||
}
|
||||
describe('department region configuration', () => {
|
||||
it('parses an honest dated snapshot without exposing employee identities', () => {
|
||||
const state = parseOrganization(directoryFixture)
|
||||
expect(state.directory_source).toBe('weekly_report_snapshot')
|
||||
expect(state.view.unassigned_people).toBe(1)
|
||||
expect(() =>
|
||||
parseOrganization({ ...directoryFixture, view: { ...directoryFixture.view, total_people: 0 } })
|
||||
).toThrow()
|
||||
expect(() =>
|
||||
parseOrganization({ ...directoryFixture, view: { ...directoryFixture.view, departments: [{}, {}] } })
|
||||
).toThrow()
|
||||
})
|
||||
it('changes only a direct stable ID rule, leaving sibling and child overrides alone', () => {
|
||||
const rules = [
|
||||
{ department_id: 'parent', region: '国内工业' },
|
||||
{ department_id: 'child', region: 'APAC' },
|
||||
]
|
||||
expect(changeRegionRule(rules, 'parent', 'EMEA', true)).toEqual([
|
||||
{ department_id: 'child', region: 'APAC' },
|
||||
{ department_id: 'parent', region: 'EMEA' },
|
||||
])
|
||||
expect(changeRegionRule(rules, 'parent', '国内工业', false)).toEqual([{ department_id: 'child', region: 'APAC' }])
|
||||
})
|
||||
it('surfaces store errors rather than displaying an empty directory', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn().mockResolvedValue({ ok: false, status: 503, json: async () => ({ error: '通讯录不可用' }) })
|
||||
)
|
||||
await expect(fetchOrganization()).rejects.toThrow('通讯录不可用')
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user