details.spec.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import ApiApplicationDetails from 'sentry/views/settings/account/apiApplications/details';
  9. describe('ApiApplications', function () {
  10. it('renders basic details for newly created App', function () {
  11. const {router} = initializeOrg();
  12. MockApiClient.addMockResponse({
  13. url: '/api-applications/abcd/',
  14. body: {
  15. allowedOrigins: ['http://example.com'],
  16. clientID: 'abcd',
  17. clientSecret: '1234',
  18. homepageUrl: 'http://example.com/homepage',
  19. id: 'abcd',
  20. name: 'Example App Name',
  21. privacyUrl: 'http://example.com/privacy',
  22. redirectUris: ['http://example.com/redirect'],
  23. termsUrl: ['http://example.com/terms'],
  24. },
  25. });
  26. render(
  27. <ApiApplicationDetails
  28. router={router}
  29. location={router.location}
  30. routes={router.routes}
  31. route={{}}
  32. routeParams={{}}
  33. params={{
  34. appId: 'abcd',
  35. }}
  36. />
  37. );
  38. expect(screen.getByDisplayValue('http://example.com')).toBeInTheDocument();
  39. expect(screen.getByDisplayValue('http://example.com/redirect')).toBeInTheDocument();
  40. expect(screen.getByDisplayValue('http://example.com/privacy')).toBeInTheDocument();
  41. expect(screen.getByDisplayValue('http://example.com/terms')).toBeInTheDocument();
  42. expect(screen.getByDisplayValue('abcd')).toBeInTheDocument();
  43. expect(screen.getByDisplayValue('1234')).toBeInTheDocument();
  44. expect(screen.getByDisplayValue('Example App Name')).toBeInTheDocument();
  45. expect(screen.getByLabelText('Name')).toBeInTheDocument();
  46. expect(screen.getByLabelText('Homepage')).toBeInTheDocument();
  47. expect(screen.getByLabelText('Privacy Policy')).toBeInTheDocument();
  48. expect(screen.getByLabelText('Terms of Service')).toBeInTheDocument();
  49. expect(screen.getByLabelText('Authorized Redirect URIs')).toBeInTheDocument();
  50. expect(screen.getByLabelText('Authorized JavaScript Origins')).toBeInTheDocument();
  51. expect(screen.getByLabelText('Client ID')).toBeInTheDocument();
  52. expect(screen.getByLabelText('Client Secret')).toBeInTheDocument();
  53. expect(screen.getByLabelText('Authorization URL')).toBeInTheDocument();
  54. expect(screen.getByLabelText('Token URL')).toBeInTheDocument();
  55. });
  56. it('handles client secret rotation', async function () {
  57. const {router} = initializeOrg();
  58. MockApiClient.addMockResponse({
  59. url: '/api-applications/abcd/',
  60. body: {
  61. allowedOrigins: ['http://example.com'],
  62. clientID: 'abcd',
  63. clientSecret: null,
  64. homepageUrl: 'http://example.com/homepage',
  65. id: 'abcd',
  66. name: 'Example App Name',
  67. privacyUrl: 'http://example.com/privacy',
  68. redirectUris: ['http://example.com/redirect'],
  69. termsUrl: ['http://example.com/terms'],
  70. },
  71. });
  72. const rotateSecretApiCall = MockApiClient.addMockResponse({
  73. method: 'POST',
  74. url: '/api-applications/abcd/rotate-secret/',
  75. body: {
  76. clientSecret: 'newSecret!',
  77. },
  78. });
  79. render(
  80. <ApiApplicationDetails
  81. router={router}
  82. location={router.location}
  83. routes={router.routes}
  84. route={{}}
  85. routeParams={{}}
  86. params={{
  87. appId: 'abcd',
  88. }}
  89. />
  90. );
  91. renderGlobalModal();
  92. expect(screen.getByText('hidden')).toBeInTheDocument();
  93. expect(
  94. screen.getByRole('button', {name: 'Rotate client secret'})
  95. ).toBeInTheDocument();
  96. await userEvent.click(screen.getByRole('button', {name: 'Rotate client secret'}));
  97. expect(
  98. screen.getByText('This will be the only time your client secret is visible!')
  99. ).toBeInTheDocument();
  100. expect(screen.getByText('Rotated Client Secret')).toBeInTheDocument();
  101. expect(screen.getByText('Your client secret is:')).toBeInTheDocument();
  102. expect(screen.getByText('newSecret!')).toBeInTheDocument();
  103. expect(rotateSecretApiCall).toHaveBeenCalledTimes(1);
  104. });
  105. });