import {api, DatetimeRegex} from "./restful"; import {Resp} from "@util/Resp"; import {models} from "@core-models/Models"; const globalAny: any = global; export const acs_user_test = () => { beforeAll(async (done) => { globalAny.user_id = 'admin'; await globalAny.svr.init_data_models(models); done(); }, 30000); test('获取账号列表', async () => { let result = await api('/api/acs.user.get_list', { domain_id: 100 }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.users).toBeDefined(); expect(result.data.users.length).toBe(0); }); test('添加用户', async () => { let result = await api('/api/acs.user.add', { domain_id: 100, user_id: 'user', name: 'user name', pass: 'pass', mobile: '13857100000', email: 'email@test.com', status: 1 }); expect(result.code).toBe(Resp.OK.code); }); test('获取用户列表', async () => { let result = await api('/api/acs.user.get_list', { domain_id: 100 }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.page_count).toBe(1); expect(result.data.total).toBe(1); expect(result.data.users).toBeDefined(); expect(result.data.users.length).toBe(1); expect(result.data.users[0].id).toBe('user'); expect(result.data.users[0].name).toBe('user name'); expect(result.data.users[0].mobile).toBe('13857100000'); expect(result.data.users[0].email).toBe('email@test.com'); expect(result.data.users[0].reg_time).toMatch(DatetimeRegex); expect(result.data.users[0].act_time).toMatch(DatetimeRegex); }); test('修改用户', async () => { let result = await api('/api/acs.user.modify', { user_id: 'user', name: 'user name new', pass: 'pass new ', mobile: '13857100001', email: 'email_new@test.com', status: 0 }); expect(result.code).toBe(Resp.OK.code); }); test('获取用户列表', async () => { let result = await api('/api/acs.user.get_list', { page_no: 1, page_size: 100, domain_id: 100 }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.page_count).toBe(1); expect(result.data.total).toBe(1); expect(result.data.users).toBeDefined(); expect(result.data.users.length).toBe(1); expect(result.data.users[0].id).toBe('user'); expect(result.data.users[0].name).toBe('user name new'); expect(result.data.users[0].mobile).toBe('13857100001'); expect(result.data.users[0].email).toBe('email_new@test.com'); expect(result.data.users[0].reg_time).toMatch(DatetimeRegex); expect(result.data.users[0].act_time).toMatch(DatetimeRegex); }); test('获取账号列表, 条件查询 ', async () => { let result = await api('/api/acs.user.get_list', { domain_id: 100, keyword: 'user' }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.users).toBeDefined(); expect(result.data.users.length).toBe(1); }); test('获取账号列表, 条件查询 ', async () => { let result = await api('/api/acs.user.get_list', { domain_id: 100, keyword: 'assssssssss' }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.users).toBeDefined(); expect(result.data.users.length).toBe(0); }); test('获取账号角色', async () => { let result = await api('/api/acs.user.get_roles', { user_id: 'user' }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.roles).toBeDefined(); expect(result.data.roles).toContainEqual({ id: 'admin', name: '系统管理员', enabled: false }) }); test('设置账号角色', async () => { let result = await api('/api/acs.user.set_roles', { user_id: 'user', roles: [{ id: 'admin', enabled: true }] }); expect(result.code).toBe(Resp.OK.code); }); test('获取账号角色', async () => { let result = await api('/api/acs.user.get_roles', { user_id: 'user' }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.roles).toBeDefined(); expect(result.data.roles).toContainEqual({ id: 'admin', name: '系统管理员', enabled: true }) }); test('获取账号域范围', async () => { let result = await api('/api/acs.user.get_domains', { user_id: 'user' }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.list).toBeDefined(); expect(result.data.list).toContainEqual({ id: 100, name: '分组' }); }); test('设置账号域范围', async () => { let result = await api('/api/acs.user.set_domains', { user_id: 'user', domains: [ { id: 100, enabled: false },{ id: 1, enabled: true } ] }); expect(result.code).toBe(Resp.Forbidden.code); }); test('设置账号域范围', async () => { let result = await api('/api/acs.user.set_domains', { user_id: 'user', domains: [ { id: 100, enabled: false },{ id: 2, enabled: true } ] }); expect(result.code).toBe(Resp.OK.code); }); test('获取账号域范围', async () => { let result = await api('/api/acs.user.get_domains', { user_id: 'user' }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.list).toBeDefined(); expect(result.data.list).toContainEqual({ id: 2, name: '系统运维域' }); }); test('获取账号列表, 条件查询 ', async () => { let result = await api('/api/acs.user.get_list', { domain_id: 2 }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.users).toBeDefined(); expect(result.data.users.length).toBe(1); }); test('删除用户', async () => { let result = await api('/api/acs.user.remove', { user_id: 'user' }); expect(result.code).toBe(Resp.OK.code); }); test('获取账号列表, 条件查询 ', async () => { let result = await api('/api/acs.user.get_list', { domain_id: 2 }); expect(result.code).toBe(Resp.OK.code); expect(result.data).toBeDefined(); expect(result.data.users).toBeDefined(); expect(result.data.users.length).toBe(0); }); }