123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- 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);
- });
- }
|