acs_domain.test.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import {api} from "./restful";
  2. import {Resp} from "@util/Resp";
  3. import {models} from "@core-models/Models";
  4. const globalAny: any = global;
  5. export const acs_domain_test = () => {
  6. let domain_id1, domain_id2: number;
  7. beforeAll(async (done) => {
  8. globalAny.user_id = 'admin';
  9. await globalAny.svr.init_data_models(models);
  10. done();
  11. }, 30000);
  12. test('获取组织机构树', async () => {
  13. let result = await api('/api/acs.domain.get_tree', {
  14. });
  15. expect(result.code).toBe(Resp.OK.code);
  16. expect(result.data).toBeDefined();
  17. expect(result.data.tree).toBeDefined();
  18. });
  19. test('获取组织机构树', async () => {
  20. let result = await api('/api/acs.domain.get_tree', {
  21. pid: 100
  22. });
  23. expect(result.code).toBe(Resp.OK.code);
  24. expect(result.data).toBeDefined();
  25. expect(result.data.tree).toBeDefined();
  26. });
  27. test('添加组织机构', async () => {
  28. let result = await api('/api/acs.domain.add', {
  29. pid: 100,
  30. name: 'domain',
  31. tag: 'tag',
  32. memo: 'memo'
  33. });
  34. expect(result.code).toBe(Resp.OK.code);
  35. expect(result.data).toBeDefined();
  36. expect(result.data.id).toBeDefined();
  37. domain_id1 = result.data.id;
  38. });
  39. test('添加组织机构1', async () => {
  40. let result = await api('/api/acs.domain.add', {
  41. pid: domain_id1,
  42. name: 'domain2',
  43. tag: 'tag2',
  44. memo: 'memo2'
  45. });
  46. expect(result.code).toBe(Resp.OK.code);
  47. expect(result.data).toBeDefined();
  48. expect(result.data.id).toBeDefined();
  49. domain_id2 = result.data.id;
  50. });
  51. test('修改组织机构2', async () => {
  52. let result = await api('/api/acs.domain.modify', {
  53. id: domain_id2,
  54. name: 'domain2new',
  55. tag: 'tag2new',
  56. memo: 'memo2new'
  57. });
  58. expect(result.code).toBe(Resp.OK.code);
  59. });
  60. test('获取组织机构树', async () => {
  61. let result = await api('/api/acs.domain.get_tree', {
  62. pid: 100
  63. });
  64. expect(result.code).toBe(Resp.OK.code);
  65. expect(result.data).toBeDefined();
  66. expect(result.data.tree).toBeDefined();
  67. expect(result.data.tree[0].children).toContainEqual({
  68. id: domain_id1,
  69. name: 'domain',
  70. tag: 'tag',
  71. memo: 'memo',
  72. children: [
  73. {
  74. id: domain_id2,
  75. name: 'domain2new',
  76. tag: 'tag2new',
  77. memo: 'memo2new',
  78. children: []
  79. }
  80. ]
  81. })
  82. });
  83. test('删除组织机构 ', async () => {
  84. let result = await api('/api/acs.domain.remove', {
  85. id: domain_id1
  86. });
  87. expect(result.code).toBe(Resp.KeyStillReferenced.code);
  88. });
  89. test('删除组织机构 ', async () => {
  90. let result = await api('/api/acs.domain.remove', {
  91. id: domain_id2
  92. });
  93. expect(result.code).toBe(Resp.OK.code);
  94. });
  95. test('获取组织机构树', async () => {
  96. let result = await api('/api/acs.domain.get_tree', {
  97. pid: 100
  98. });
  99. expect(result.code).toBe(Resp.OK.code);
  100. expect(result.data).toBeDefined();
  101. expect(result.data.tree).toBeDefined();
  102. console.log(result.data.tree);
  103. expect(result.data.tree[0].children).toContainEqual({
  104. id: domain_id1,
  105. name: 'domain',
  106. tag: 'tag',
  107. memo: 'memo',
  108. children: []
  109. })
  110. });
  111. }