group.spec.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import {bulkUpdate, mergeGroups, paramsToQueryArgs} from 'sentry/actionCreators/group';
  2. import {Client} from 'sentry/api';
  3. import GroupStore from 'sentry/stores/groupStore';
  4. describe('group', () => {
  5. let api: Client;
  6. beforeEach(function () {
  7. api = new MockApiClient();
  8. });
  9. describe('paramsToQueryArgs()', function () {
  10. it('should convert itemIds properties to id array', function () {
  11. expect(
  12. paramsToQueryArgs({
  13. itemIds: ['1', '2', '3'],
  14. query: 'is:unresolved', // itemIds takes precedence
  15. })
  16. ).toEqual({id: ['1', '2', '3']});
  17. });
  18. it('should extract query property if no itemIds', function () {
  19. const invalidArgs: any = {
  20. foo: 'bar',
  21. };
  22. expect(paramsToQueryArgs({query: 'is:unresolved', ...invalidArgs})).toEqual({
  23. query: 'is:unresolved',
  24. });
  25. });
  26. it('should convert params w/o itemIds or query to empty object', function () {
  27. const invalidArgs: any = {
  28. foo: 'bar',
  29. bar: 'baz', // paramsToQueryArgs ignores these
  30. };
  31. expect(paramsToQueryArgs(invalidArgs)).toEqual({});
  32. });
  33. it('should keep environment when query is provided', function () {
  34. expect(
  35. paramsToQueryArgs({
  36. query: 'is:unresolved',
  37. environment: 'production',
  38. })
  39. ).toEqual({query: 'is:unresolved', environment: 'production'});
  40. });
  41. it('should exclude environment when it is null/undefined', function () {
  42. expect(
  43. paramsToQueryArgs({
  44. query: 'is:unresolved',
  45. environment: null,
  46. })
  47. ).toEqual({query: 'is:unresolved'});
  48. });
  49. it('should handle non-empty projects', function () {
  50. expect(
  51. paramsToQueryArgs({
  52. itemIds: ['1', '2', '3'],
  53. project: [1],
  54. })
  55. ).toEqual({id: ['1', '2', '3'], project: [1]});
  56. expect(
  57. paramsToQueryArgs({
  58. itemIds: ['1', '2', '3'],
  59. project: [],
  60. })
  61. ).toEqual({id: ['1', '2', '3']});
  62. expect(
  63. paramsToQueryArgs({
  64. itemIds: ['1', '2', '3'],
  65. project: null,
  66. })
  67. ).toEqual({id: ['1', '2', '3']});
  68. });
  69. });
  70. describe('bulkUpdate()', function () {
  71. beforeEach(function () {
  72. jest.spyOn(GroupStore, 'onUpdate'); // stub GroupStore.onUpdate call from update
  73. });
  74. it('should use itemIds as query if provided', function () {
  75. const request = MockApiClient.addMockResponse({
  76. url: '/projects/1337/1337/issues/',
  77. method: 'PUT',
  78. });
  79. bulkUpdate(
  80. api,
  81. {
  82. orgId: '1337',
  83. projectId: '1337',
  84. itemIds: ['1', '2', '3'],
  85. data: {status: 'unresolved'},
  86. query: 'is:resolved',
  87. },
  88. {}
  89. );
  90. expect(request).toHaveBeenCalledTimes(1);
  91. expect(request).toHaveBeenCalledWith(
  92. '/projects/1337/1337/issues/',
  93. expect.objectContaining({query: {id: ['1', '2', '3']}})
  94. );
  95. });
  96. it('should use query as query if itemIds are absent', function () {
  97. const request = MockApiClient.addMockResponse({
  98. url: '/projects/1337/1337/issues/',
  99. method: 'PUT',
  100. });
  101. bulkUpdate(
  102. api,
  103. {
  104. orgId: '1337',
  105. projectId: '1337',
  106. itemIds: undefined,
  107. data: {status: 'unresolved'},
  108. query: 'is:resolved',
  109. },
  110. {}
  111. );
  112. expect(request).toHaveBeenCalledTimes(1);
  113. expect(request).toHaveBeenCalledWith(
  114. '/projects/1337/1337/issues/',
  115. expect.objectContaining({query: {query: 'is:resolved'}})
  116. );
  117. });
  118. it('should apply project option', function () {
  119. const request = MockApiClient.addMockResponse({
  120. url: '/organizations/1337/issues/',
  121. method: 'PUT',
  122. });
  123. bulkUpdate(
  124. api,
  125. {
  126. orgId: '1337',
  127. project: [99],
  128. itemIds: ['1', '2', '3'],
  129. data: {status: 'unresolved'},
  130. },
  131. {}
  132. );
  133. expect(request).toHaveBeenCalledTimes(1);
  134. expect(request).toHaveBeenCalledWith(
  135. '/organizations/1337/issues/',
  136. expect.objectContaining({query: {id: ['1', '2', '3'], project: [99]}})
  137. );
  138. });
  139. });
  140. describe('mergeGroups()', function () {
  141. // TODO: this is totally copypasta from the test above. We need to refactor
  142. // these API methods/tests.
  143. beforeEach(function () {
  144. jest.spyOn(GroupStore, 'onMerge'); // stub GroupStore.onMerge call from mergeGroups
  145. });
  146. it('should use itemIds as query if provided', function () {
  147. const request = MockApiClient.addMockResponse({
  148. url: '/projects/1337/1337/issues/',
  149. method: 'PUT',
  150. });
  151. mergeGroups(
  152. api,
  153. {
  154. orgId: '1337',
  155. projectId: '1337',
  156. itemIds: ['1', '2', '3'],
  157. query: 'is:resolved',
  158. },
  159. {}
  160. );
  161. expect(request).toHaveBeenCalledTimes(1);
  162. expect(request).toHaveBeenCalledWith(
  163. '/projects/1337/1337/issues/',
  164. expect.objectContaining({query: {id: ['1', '2', '3']}})
  165. );
  166. });
  167. it('should use query as query if itemIds are absent', function () {
  168. const request = MockApiClient.addMockResponse({
  169. url: '/projects/1337/1337/issues/',
  170. method: 'PUT',
  171. });
  172. mergeGroups(
  173. api,
  174. {
  175. orgId: '1337',
  176. projectId: '1337',
  177. itemIds: undefined,
  178. query: 'is:resolved',
  179. },
  180. {}
  181. );
  182. expect(request).toHaveBeenCalledTimes(1);
  183. expect(request).toHaveBeenCalledWith(
  184. '/projects/1337/1337/issues/',
  185. expect.objectContaining({query: {query: 'is:resolved'}})
  186. );
  187. });
  188. });
  189. });