Files
knowledge-governance/web/src/scopeRules.test.ts
T
zheromiku f6cb90cd70 feat(web): login gate, session identity UI and member management
- main.tsx 挂 AuthProvider 门控:未登录→登录页;must_change_password→强制改密页
- 登录页/改密页/顶栏身份(头像+姓名+角色徽章+退出)按 A·Data-console token 样式
- 全局 fetch 拦截器:任意业务请求 401 自动回登录页(会话过期/被撤销不留死表单)
- 系统设置新增「成员与角色」分区(仅 admin 可见):名单、角色调整、启停、重置临时密码、新增成员
- 消灭全部手填操作人:审核/封批/确认计划集/范围规则/来源调度/UI 设置/开始处理/批量重试/
  目录差异确认共 9 处输入框删除,请求体不再携带 actor 字段(服务端从会话注入)
- 测试断言方向翻转:显式验证请求体不含 operator_ref/created_by 等字段
- 附带修复:登录失败计数 SQL 参数类型无法推断导致 500(pgx 扩展协议),显式 cast 解决

前端门禁:tsc 0 错、125 用例全绿、build 通过
2026-09-30 10:54:07 +08:00

26 lines
1.9 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest'
import { clearScopeRule, fetchScopeRules, setScopeRule } from './scopeRules'
afterEach(()=>vi.unstubAllGlobals())
describe('scope rule API',()=>{
it('lists rules for exactly one configured connection',async()=>{
const fetchMock=vi.fn().mockResolvedValue(new Response(JSON.stringify({data:[{target_type:'directory',connection_id:'conn-1',directory_path:'产品',visibility:'internal',updated_by:'engineer',reason:'内部资料',updated_at:'2026-09-08T00:00:00Z'}],summary:{total:1}})))
vi.stubGlobal('fetch',fetchMock)
const rules=await fetchScopeRules('conn-1')
expect(rules).toHaveLength(1)
expect(fetchMock).toHaveBeenCalledWith('/api/v1/scope-rules?connection_id=conn-1',expect.objectContaining({headers:{Accept:'application/json'}}))
})
it('sets and clears rules with explicit audited payloads',async()=>{
const fetchMock=vi.fn().mockImplementation(()=>Promise.resolve(new Response(JSON.stringify({data:{target_type:'directory',connection_id:'conn-1',directory_path:'产品',visibility:'internal'}}))))
vi.stubGlobal('fetch',fetchMock)
const target={target_type:'directory' as const,connection_id:'conn-1',directory_path:'产品',source_item_id:''}
await setScopeRule({...target,visibility:'internal',reason:'内部资料'})
await clearScopeRule({...target,reason:'恢复来源设置'})
expect(fetchMock.mock.calls[0][1]).toMatchObject({method:'PUT',headers:{Accept:'application/json','Content-Type':'application/json','Idempotency-Key':expect.any(String)}})
expect(JSON.parse(fetchMock.mock.calls[0][1].body)).toEqual({...target,visibility:'internal',reason:'内部资料'})
expect(fetchMock.mock.calls[1][1]).toMatchObject({method:'DELETE',headers:{Accept:'application/json','Content-Type':'application/json','Idempotency-Key':expect.any(String)}})
expect(JSON.parse(fetchMock.mock.calls[1][1].body)).not.toHaveProperty('visibility')
})
})