auditLogView.spec.tsx 4.4 KB

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