acs_function.test.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import {api} from "./restful";
  2. import {Resp} from "@util/Resp";
  3. import {models} from "@core-models/Models";
  4. import {AcsModule} from "@core-models/AcsModule";
  5. const globalAny: any = global;
  6. let sqls = [
  7. `insert into ${AcsModule.table_name} (id, tag, name, pid, path, path_name)
  8. values (200000, 'test1', '一级', null, '200000', 'test1'),
  9. (200001, 'test2', '一级', 200000, '200000.200001', 'test1.test2') ON CONFLICT DO NOTHING`,
  10. ]
  11. export const acs_function_test = () => {
  12. let function_id;
  13. beforeAll(async (done) => {
  14. globalAny.user_id = 'admin';
  15. await globalAny.svr.init_data_models(models);
  16. let sequelize = AcsModule.sequelize!;
  17. for (let i = 0; i < sqls.length; i++) {
  18. await sequelize.query(sqls[i]);
  19. }
  20. done();
  21. }, 30000);
  22. test('添加功能项', async () => {
  23. let result = await api('/api/acs.function.add', {
  24. module_id: 200001,
  25. tag: 'function',
  26. name: '功能项',
  27. check_auth: true
  28. });
  29. expect(result.code).toBe(Resp.OK.code);
  30. expect(result.data).toBeDefined();
  31. expect(result.data.id).toBeDefined();
  32. function_id = result.data.id;
  33. });
  34. test('获取功能项列表', async () => {
  35. let result = await api('/api/acs.function.get_list', {
  36. module_id: 200001
  37. });
  38. expect(result.code).toBe(Resp.OK.code);
  39. expect(result.data).toBeDefined();
  40. expect(result.data.functions).toBeDefined();
  41. expect(result.data.functions.length).toBe(1);
  42. expect(result.data.functions[0].id).toBe(function_id);
  43. expect(result.data.functions[0].tag).toBe('function');
  44. expect(result.data.functions[0].name).toBe('功能项');
  45. expect(result.data.functions[0].api).toBe('test1.test2.function');
  46. expect(result.data.functions[0].check_auth).toBe(true);
  47. });
  48. test('修改功能项', async () => {
  49. let result = await api('/api/acs.function.modify', {
  50. id: function_id,
  51. name: '功能项new',
  52. check_auth: false
  53. });
  54. expect(result.code).toBe(Resp.OK.code);
  55. });
  56. test('获取功能项列表', async () => {
  57. let result = await api('/api/acs.function.get_list', {
  58. module_id: 200001
  59. });
  60. expect(result.code).toBe(Resp.OK.code);
  61. expect(result.data).toBeDefined();
  62. expect(result.data.functions).toBeDefined();
  63. expect(result.data.functions.length).toBe(1);
  64. expect(result.data.functions[0].id).toBe(function_id);
  65. expect(result.data.functions[0].tag).toBe('function');
  66. expect(result.data.functions[0].name).toBe('功能项new');
  67. expect(result.data.functions[0].api).toBe('test1.test2.function');
  68. expect(result.data.functions[0].check_auth).toBe(false);
  69. });
  70. test('删除功能项', async () => {
  71. let result = await api('/api/acs.function.remove', {
  72. id: function_id
  73. });
  74. expect(result.code).toBe(Resp.Forbidden.code);
  75. });
  76. test('删除功能项', async () => {
  77. globalAny.user_id = 'administrator';
  78. let result = await api('/api/acs.function.remove', {
  79. id: function_id
  80. });
  81. expect(result.code).toBe(Resp.OK.code);
  82. });
  83. test('获取功能项列表', async () => {
  84. let result = await api('/api/acs.function.get_list', {
  85. module_id: 200001
  86. });
  87. expect(result.code).toBe(Resp.OK.code);
  88. expect(result.data).toBeDefined();
  89. expect(result.data.functions).toBeDefined();
  90. expect(result.data.functions.length).toBe(0);
  91. });
  92. }