import {api} from "./restful"; import {Resp} from "@util/Resp"; import {models} from "@core-models/Models"; const globalAny: any = global; export const acs_domain_test = () => { let domain_id1, domain_id2: number; beforeAll(async (done) => { globalAny.user_id = 'admin'; await globalAny.svr.init_data_models(models); done(); }, 30000); test('获取组织机构树', async () => { let result = await api('/api/acs.domain.get_tree', { }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.tree).toBeDefined(); }); test('获取组织机构树', async () => { let result = await api('/api/acs.domain.get_tree', { pid: 100 }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.tree).toBeDefined(); }); test('添加组织机构', async () => { let result = await api('/api/acs.domain.add', { pid: 100, name: 'domain', tag: 'tag', memo: 'memo' }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.id).toBeDefined(); domain_id1 = result.data.id; }); test('添加组织机构1', async () => { let result = await api('/api/acs.domain.add', { pid: domain_id1, name: 'domain2', tag: 'tag2', memo: 'memo2' }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.id).toBeDefined(); domain_id2 = result.data.id; }); test('修改组织机构2', async () => { let result = await api('/api/acs.domain.modify', { id: domain_id2, name: 'domain2new', tag: 'tag2new', memo: 'memo2new' }); expect(result.code).toBe(Resp.OK.code); }); test('获取组织机构树', async () => { let result = await api('/api/acs.domain.get_tree', { pid: 100 }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.tree).toBeDefined(); expect(result.data.tree[0].children).toContainEqual({ id: domain_id1, name: 'domain', tag: 'tag', memo: 'memo', children: [ { id: domain_id2, name: 'domain2new', tag: 'tag2new', memo: 'memo2new', children: [] } ] }) }); test('删除组织机构 ', async () => { let result = await api('/api/acs.domain.remove', { id: domain_id1 }); expect(result.code).toBe(Resp.KeyStillReferenced.code); }); test('删除组织机构 ', async () => { let result = await api('/api/acs.domain.remove', { id: domain_id2 }); expect(result.code).toBe(Resp.OK.code); }); test('获取组织机构树', async () => { let result = await api('/api/acs.domain.get_tree', { pid: 100 }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.tree).toBeDefined(); console.log(result.data.tree); expect(result.data.tree[0].children).toContainEqual({ id: domain_id1, name: 'domain', tag: 'tag', memo: 'memo', children: [] }) }); }