group.spec.jsx 4.8 KB

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