acs_user.test.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import {api, DatetimeRegex} from "./restful";
  2. import {Resp} from "@util/Resp";
  3. import {models} from "@core-models/Models";
  4. const globalAny: any = global;
  5. export const acs_user_test = () => {
  6. beforeAll(async (done) => {
  7. globalAny.user_id = 'admin';
  8. await globalAny.svr.init_data_models(models);
  9. done();
  10. }, 30000);
  11. test('获取账号列表', async () => {
  12. let result = await api('/api/acs.user.get_list', {
  13. domain_id: 100
  14. });
  15. expect(result.code).toBe(Resp.OK.code);
  16. expect(result.data).toBeDefined();
  17. expect(result.data.users).toBeDefined();
  18. expect(result.data.users.length).toBe(0);
  19. });
  20. test('添加用户', async () => {
  21. let result = await api('/api/acs.user.add', {
  22. domain_id: 100,
  23. user_id: 'user',
  24. name: 'user name',
  25. pass: 'pass',
  26. mobile: '13857100000',
  27. email: 'email@test.com',
  28. status: 1
  29. });
  30. expect(result.code).toBe(Resp.OK.code);
  31. });
  32. test('获取用户列表', async () => {
  33. let result = await api('/api/acs.user.get_list', {
  34. domain_id: 100
  35. });
  36. expect(result.code).toBe(Resp.OK.code);
  37. expect(result.data).toBeDefined();
  38. expect(result.data.page_count).toBe(1);
  39. expect(result.data.total).toBe(1);
  40. expect(result.data.users).toBeDefined();
  41. expect(result.data.users.length).toBe(1);
  42. expect(result.data.users[0].id).toBe('user');
  43. expect(result.data.users[0].name).toBe('user name');
  44. expect(result.data.users[0].mobile).toBe('13857100000');
  45. expect(result.data.users[0].email).toBe('email@test.com');
  46. expect(result.data.users[0].reg_time).toMatch(DatetimeRegex);
  47. expect(result.data.users[0].act_time).toMatch(DatetimeRegex);
  48. });
  49. test('修改用户', async () => {
  50. let result = await api('/api/acs.user.modify', {
  51. user_id: 'user',
  52. name: 'user name new',
  53. pass: 'pass new ',
  54. mobile: '13857100001',
  55. email: 'email_new@test.com',
  56. status: 0
  57. });
  58. expect(result.code).toBe(Resp.OK.code);
  59. });
  60. test('获取用户列表', async () => {
  61. let result = await api('/api/acs.user.get_list', {
  62. page_no: 1,
  63. page_size: 100,
  64. domain_id: 100
  65. });
  66. expect(result.code).toBe(Resp.OK.code);
  67. expect(result.data).toBeDefined();
  68. expect(result.data.page_count).toBe(1);
  69. expect(result.data.total).toBe(1);
  70. expect(result.data.users).toBeDefined();
  71. expect(result.data.users.length).toBe(1);
  72. expect(result.data.users[0].id).toBe('user');
  73. expect(result.data.users[0].name).toBe('user name new');
  74. expect(result.data.users[0].mobile).toBe('13857100001');
  75. expect(result.data.users[0].email).toBe('email_new@test.com');
  76. expect(result.data.users[0].reg_time).toMatch(DatetimeRegex);
  77. expect(result.data.users[0].act_time).toMatch(DatetimeRegex);
  78. });
  79. test('获取账号列表, 条件查询 ', async () => {
  80. let result = await api('/api/acs.user.get_list', {
  81. domain_id: 100,
  82. keyword: 'user'
  83. });
  84. expect(result.code).toBe(Resp.OK.code);
  85. expect(result.data).toBeDefined();
  86. expect(result.data.users).toBeDefined();
  87. expect(result.data.users.length).toBe(1);
  88. });
  89. test('获取账号列表, 条件查询 ', async () => {
  90. let result = await api('/api/acs.user.get_list', {
  91. domain_id: 100,
  92. keyword: 'assssssssss'
  93. });
  94. expect(result.code).toBe(Resp.OK.code);
  95. expect(result.data).toBeDefined();
  96. expect(result.data.users).toBeDefined();
  97. expect(result.data.users.length).toBe(0);
  98. });
  99. test('获取账号角色', async () => {
  100. let result = await api('/api/acs.user.get_roles', {
  101. user_id: 'user'
  102. });
  103. expect(result.code).toBe(Resp.OK.code);
  104. expect(result.data).toBeDefined();
  105. expect(result.data.roles).toBeDefined();
  106. expect(result.data.roles).toContainEqual({
  107. id: 'admin',
  108. name: '系统管理员',
  109. enabled: false
  110. })
  111. });
  112. test('设置账号角色', async () => {
  113. let result = await api('/api/acs.user.set_roles', {
  114. user_id: 'user',
  115. roles: [{
  116. id: 'admin',
  117. enabled: true
  118. }]
  119. });
  120. expect(result.code).toBe(Resp.OK.code);
  121. });
  122. test('获取账号角色', async () => {
  123. let result = await api('/api/acs.user.get_roles', {
  124. user_id: 'user'
  125. });
  126. expect(result.code).toBe(Resp.OK.code);
  127. expect(result.data).toBeDefined();
  128. expect(result.data.roles).toBeDefined();
  129. expect(result.data.roles).toContainEqual({
  130. id: 'admin',
  131. name: '系统管理员',
  132. enabled: true
  133. })
  134. });
  135. test('获取账号域范围', async () => {
  136. let result = await api('/api/acs.user.get_domains', {
  137. user_id: 'user'
  138. });
  139. expect(result.code).toBe(Resp.OK.code);
  140. expect(result.data).toBeDefined();
  141. expect(result.data.list).toBeDefined();
  142. expect(result.data.list).toContainEqual({
  143. id: 100,
  144. name: '分组'
  145. });
  146. });
  147. test('设置账号域范围', async () => {
  148. let result = await api('/api/acs.user.set_domains', {
  149. user_id: 'user',
  150. domains: [
  151. {
  152. id: 100, enabled: false
  153. },{
  154. id: 1, enabled: true
  155. }
  156. ]
  157. });
  158. expect(result.code).toBe(Resp.Forbidden.code);
  159. });
  160. test('设置账号域范围', async () => {
  161. let result = await api('/api/acs.user.set_domains', {
  162. user_id: 'user',
  163. domains: [
  164. {
  165. id: 100, enabled: false
  166. },{
  167. id: 2, enabled: true
  168. }
  169. ]
  170. });
  171. expect(result.code).toBe(Resp.OK.code);
  172. });
  173. test('获取账号域范围', async () => {
  174. let result = await api('/api/acs.user.get_domains', {
  175. user_id: 'user'
  176. });
  177. expect(result.code).toBe(Resp.OK.code);
  178. expect(result.data).toBeDefined();
  179. expect(result.data.list).toBeDefined();
  180. expect(result.data.list).toContainEqual({
  181. id: 2,
  182. name: '系统运维域'
  183. });
  184. });
  185. test('获取账号列表, 条件查询 ', async () => {
  186. let result = await api('/api/acs.user.get_list', {
  187. domain_id: 2
  188. });
  189. expect(result.code).toBe(Resp.OK.code);
  190. expect(result.data).toBeDefined();
  191. expect(result.data.users).toBeDefined();
  192. expect(result.data.users.length).toBe(1);
  193. });
  194. test('删除用户', async () => {
  195. let result = await api('/api/acs.user.remove', {
  196. user_id: 'user'
  197. });
  198. expect(result.code).toBe(Resp.OK.code);
  199. });
  200. test('获取账号列表, 条件查询 ', async () => {
  201. let result = await api('/api/acs.user.get_list', {
  202. domain_id: 2
  203. });
  204. expect(result.code).toBe(Resp.OK.code);
  205. expect(result.data).toBeDefined();
  206. expect(result.data.users).toBeDefined();
  207. expect(result.data.users.length).toBe(0);
  208. });
  209. }