auditLogView.spec.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import {AuditLogs} from 'sentry-fixture/auditLogs';
  2. import {AuditLogsApiEventNames} from 'sentry-fixture/auditLogsApiEventNames';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {
  5. render,
  6. screen,
  7. userEvent,
  8. waitForElementToBeRemoved,
  9. } from 'sentry-test/reactTestingLibrary';
  10. import OrganizationAuditLog from 'sentry/views/settings/organizationAuditLog';
  11. // XXX(epurkhiser): This appears to also be tested by ./index.spec.tsx
  12. describe('OrganizationAuditLog', function () {
  13. const {routerContext, organization, router} = initializeOrg({
  14. projects: [],
  15. router: {
  16. params: {orgId: 'org-slug'},
  17. },
  18. });
  19. const ENDPOINT = `/organizations/${organization.slug}/audit-logs/`;
  20. beforeEach(function () {
  21. MockApiClient.clearMockResponses();
  22. MockApiClient.addMockResponse({
  23. url: ENDPOINT,
  24. body: {rows: AuditLogs(), options: AuditLogsApiEventNames()},
  25. });
  26. });
  27. it('renders', async function () {
  28. render(<OrganizationAuditLog location={router.location} />, {
  29. context: routerContext,
  30. });
  31. expect(await screen.findByRole('heading')).toHaveTextContent('Audit Log');
  32. expect(screen.getByRole('textbox')).toBeInTheDocument();
  33. expect(screen.getByText('Member')).toBeInTheDocument();
  34. expect(screen.getByText('Action')).toBeInTheDocument();
  35. expect(screen.getByText('IP')).toBeInTheDocument();
  36. expect(screen.getByText('Time')).toBeInTheDocument();
  37. expect(screen.queryByText('No audit entries available')).not.toBeInTheDocument();
  38. expect(screen.getByText('edited project ludic-science')).toBeInTheDocument();
  39. });
  40. it('renders empty', async function () {
  41. MockApiClient.clearMockResponses();
  42. MockApiClient.addMockResponse({
  43. url: ENDPOINT,
  44. body: {rows: [], options: AuditLogsApiEventNames()},
  45. });
  46. render(<OrganizationAuditLog location={router.location} />, {
  47. context: routerContext,
  48. });
  49. expect(await screen.findByText('No audit entries available')).toBeInTheDocument();
  50. });
  51. it('displays whether an action was done by a superuser', async () => {
  52. render(<OrganizationAuditLog location={router.location} />, {
  53. context: routerContext,
  54. });
  55. expect(await screen.findByText('Sentry Staff')).toBeInTheDocument();
  56. expect(screen.getAllByText('Foo Bar')).toHaveLength(2);
  57. });
  58. it('replaces rule and alertrule audit types in dropdown', async function () {
  59. MockApiClient.clearMockResponses();
  60. MockApiClient.addMockResponse({
  61. url: ENDPOINT,
  62. body: {
  63. rows: AuditLogs(),
  64. options: ['rule.edit', 'alertrule.edit', 'member.add'],
  65. },
  66. });
  67. render(<OrganizationAuditLog location={router.location} />, {
  68. context: routerContext,
  69. });
  70. await userEvent.click(screen.getByText('Select Action:'));
  71. expect(screen.getByText('issue-alert.edit')).toBeInTheDocument();
  72. expect(screen.getByText('metric-alert.edit')).toBeInTheDocument();
  73. expect(screen.getByText('member.add')).toBeInTheDocument();
  74. });
  75. it('replaces text in rule and alertrule entries', async function () {
  76. MockApiClient.clearMockResponses();
  77. MockApiClient.addMockResponse({
  78. url: `/organizations/org-slug/audit-logs/`,
  79. method: 'GET',
  80. body: {
  81. rows: [
  82. {
  83. actor: TestStubs.User(),
  84. event: 'rule.edit',
  85. ipAddress: '127.0.0.1',
  86. id: '214',
  87. note: 'edited rule "New issue"',
  88. targetObject: 123,
  89. targetUser: null,
  90. data: {},
  91. },
  92. {
  93. actor: TestStubs.User(),
  94. event: 'alertrule.edit',
  95. ipAddress: '127.0.0.1',
  96. id: '215',
  97. note: 'edited metric alert rule "Failure rate too high"',
  98. targetObject: 456,
  99. targetUser: null,
  100. data: {},
  101. },
  102. ],
  103. options: AuditLogsApiEventNames(),
  104. },
  105. });
  106. render(<OrganizationAuditLog location={router.location} />, {
  107. context: routerContext,
  108. });
  109. await waitForElementToBeRemoved(() => screen.getByTestId('loading-indicator'));
  110. // rule.edit -> issue-alert.edit
  111. expect(screen.getByText('issue-alert.edit')).toBeInTheDocument();
  112. expect(screen.getByText('edited issue alert rule "New issue"')).toBeInTheDocument();
  113. // alertrule.edit -> metric-alert.edit
  114. expect(screen.getByText('metric-alert.edit')).toBeInTheDocument();
  115. expect(
  116. screen.getByText('edited metric alert rule "Failure rate too high"')
  117. ).toBeInTheDocument();
  118. });
  119. });