suggestedOwners.spec.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import SuggestedOwners from 'app/components/group/suggestedOwners';
  4. import MemberListStore from 'app/stores/memberListStore';
  5. import {Client} from 'app/api';
  6. describe('SuggestedOwners', function() {
  7. const event = TestStubs.Event();
  8. const user = TestStubs.User();
  9. const organization = TestStubs.Organization();
  10. const project = TestStubs.Project();
  11. const group = TestStubs.Group({firstRelease: {}});
  12. const routerContext = TestStubs.routerContext([
  13. {
  14. organization,
  15. },
  16. ]);
  17. const endpoint = `/projects/${organization.slug}/${project.slug}/events/${event.id}`;
  18. beforeEach(function() {
  19. MemberListStore.loadInitialData([user, TestStubs.CommitAuthor()]);
  20. });
  21. afterEach(function() {
  22. Client.clearMockResponses();
  23. });
  24. it('Renders suggested owners', function() {
  25. Client.addMockResponse({
  26. url: `${endpoint}/committers/`,
  27. body: {
  28. committers: [
  29. {
  30. author: TestStubs.CommitAuthor(),
  31. commits: [TestStubs.Commit()],
  32. },
  33. ],
  34. },
  35. });
  36. Client.addMockResponse({
  37. url: `${endpoint}/owners/`,
  38. body: {
  39. owners: [{type: 'user', ...user}],
  40. rules: [[['path', 'sentry/tagstore/*'], [['user', user.email]]]],
  41. },
  42. });
  43. const wrapper = mountWithTheme(
  44. <SuggestedOwners project={project} group={group} event={event} />,
  45. routerContext
  46. );
  47. expect(wrapper.find('ActorAvatar')).toHaveLength(2);
  48. // One includes committers, the other includes ownership rules
  49. expect(
  50. wrapper
  51. .find('SuggestedOwnerHovercard')
  52. .map(node => node.props())
  53. .some(p => p.commits === undefined && p.rules !== undefined)
  54. ).toBe(true);
  55. expect(
  56. wrapper
  57. .find('SuggestedOwnerHovercard')
  58. .map(node => node.props())
  59. .some(p => p.commits !== undefined && p.rules === undefined)
  60. ).toBe(true);
  61. });
  62. it('does not call committers endpoint if `group.firstRelease` does not exist', function() {
  63. const committers = Client.addMockResponse({
  64. url: `${endpoint}/committers/`,
  65. body: {
  66. committers: [
  67. {
  68. author: TestStubs.CommitAuthor(),
  69. commits: [TestStubs.Commit()],
  70. },
  71. ],
  72. },
  73. });
  74. Client.addMockResponse({
  75. url: `${endpoint}/owners/`,
  76. body: {
  77. owners: [{type: 'user', ...user}],
  78. rules: [[['path', 'sentry/tagstore/*'], [['user', user.email]]]],
  79. },
  80. });
  81. const wrapper = mountWithTheme(
  82. <SuggestedOwners project={project} group={TestStubs.Group()} event={event} />,
  83. routerContext
  84. );
  85. expect(committers).not.toHaveBeenCalled();
  86. expect(wrapper.find('ActorAvatar')).toHaveLength(1);
  87. });
  88. it('Merges owner matching rules and having suspect commits', function() {
  89. const author = TestStubs.CommitAuthor();
  90. Client.addMockResponse({
  91. url: `${endpoint}/committers/`,
  92. body: {
  93. committers: [{author, commits: [TestStubs.Commit()]}],
  94. },
  95. });
  96. Client.addMockResponse({
  97. url: `${endpoint}/owners/`,
  98. body: {
  99. owners: [{type: 'user', ...author}],
  100. rules: [[['path', 'sentry/tagstore/*'], [['user', author.email]]]],
  101. },
  102. });
  103. const wrapper = mountWithTheme(
  104. <SuggestedOwners project={project} group={group} event={event} />,
  105. routerContext
  106. );
  107. expect(wrapper.find('ActorAvatar')).toHaveLength(1);
  108. const hovercardProps = wrapper.find('SuggestedOwnerHovercard').props();
  109. expect(hovercardProps.commits).not.toBeUndefined();
  110. expect(hovercardProps.rules).not.toBeUndefined();
  111. });
  112. });