group.spec.jsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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(api, 'request');
  74. jest.spyOn(GroupStore, 'onUpdate'); // stub GroupStore.onUpdate call from update
  75. });
  76. it('should use itemIds as query if provided', function () {
  77. MockApiClient.warnOnMissingMocks();
  78. bulkUpdate(api, {
  79. orgId: '1337',
  80. projectId: '1337',
  81. itemIds: [1, 2, 3],
  82. data: {status: 'unresolved'},
  83. query: 'is:resolved',
  84. });
  85. expect(api.request).toHaveBeenCalledTimes(1);
  86. expect(api.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. MockApiClient.warnOnMissingMocks();
  93. bulkUpdate(api, {
  94. orgId: '1337',
  95. projectId: '1337',
  96. itemIds: undefined,
  97. data: {status: 'unresolved'},
  98. query: 'is:resolved',
  99. });
  100. expect(api.request).toHaveBeenCalledTimes(1);
  101. expect(api.request).toHaveBeenCalledWith(
  102. '/projects/1337/1337/issues/',
  103. expect.objectContaining({query: {query: 'is:resolved'}})
  104. );
  105. });
  106. it('should apply project option', function () {
  107. MockApiClient.warnOnMissingMocks();
  108. bulkUpdate(api, {
  109. orgId: '1337',
  110. project: [99],
  111. itemIds: [1, 2, 3],
  112. data: {status: 'unresolved'},
  113. });
  114. expect(api.request).toHaveBeenCalledTimes(1);
  115. expect(api.request).toHaveBeenCalledWith(
  116. '/organizations/1337/issues/',
  117. expect.objectContaining({query: {id: [1, 2, 3], project: [99]}})
  118. );
  119. });
  120. });
  121. describe('mergeGroups()', function () {
  122. // TODO: this is totally copypasta from the test above. We need to refactor
  123. // these API methods/tests.
  124. beforeEach(function () {
  125. jest.spyOn(api, 'request');
  126. jest.spyOn(GroupStore, 'onMerge'); // stub GroupStore.onMerge call from mergeGroups
  127. });
  128. it('should use itemIds as query if provided', function () {
  129. MockApiClient.warnOnMissingMocks();
  130. mergeGroups(api, {
  131. orgId: '1337',
  132. projectId: '1337',
  133. itemIds: [1, 2, 3],
  134. data: {status: 'unresolved'},
  135. query: 'is:resolved',
  136. });
  137. expect(api.request).toHaveBeenCalledTimes(1);
  138. expect(api.request).toHaveBeenCalledWith(
  139. '/projects/1337/1337/issues/',
  140. expect.objectContaining({query: {id: [1, 2, 3]}})
  141. );
  142. });
  143. it('should use query as query if itemIds are absent', function () {
  144. MockApiClient.warnOnMissingMocks();
  145. mergeGroups(api, {
  146. orgId: '1337',
  147. projectId: '1337',
  148. itemIds: undefined,
  149. data: {status: 'unresolved'},
  150. query: 'is:resolved',
  151. });
  152. expect(api.request).toHaveBeenCalledTimes(1);
  153. expect(api.request).toHaveBeenCalledWith(
  154. '/projects/1337/1337/issues/',
  155. expect.objectContaining({query: {query: 'is:resolved'}})
  156. );
  157. });
  158. });
  159. });