group.spec.jsx 5.3 KB

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