auditLogView.spec.tsx 4.5 KB

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