group.spec.tsx 5.6 KB

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