continuousProfileProvider.spec.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import {uuid4} from '@sentry/core';
  2. import * as Sentry from '@sentry/react';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, waitFor} from 'sentry-test/reactTestingLibrary';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import ContinuosProfileProvider from './continuousProfileProvider';
  7. describe('ContinuousProfileProvider', () => {
  8. beforeEach(() => {
  9. MockApiClient.clearMockResponses();
  10. });
  11. it('fetches chunk', async () => {
  12. const {organization, project, router} = initializeOrg({
  13. router: {
  14. location: {
  15. query: {
  16. start: new Date().toISOString(),
  17. end: new Date().toISOString(),
  18. profilerId: uuid4(),
  19. eventId: '1',
  20. },
  21. },
  22. },
  23. });
  24. ProjectsStore.loadInitialData([project]);
  25. const captureMessage = jest.spyOn(Sentry, 'captureMessage');
  26. const chunkRequest = MockApiClient.addMockResponse({
  27. url: `/organizations/${organization.slug}/profiling/chunks/`,
  28. body: {},
  29. });
  30. MockApiClient.addMockResponse({
  31. url: `/projects/${organization.slug}/${project.slug}/events/1/`,
  32. body: {},
  33. });
  34. render(<ContinuosProfileProvider>{null}</ContinuosProfileProvider>, {
  35. router,
  36. organization,
  37. });
  38. await waitFor(() => expect(chunkRequest).toHaveBeenCalled());
  39. expect(captureMessage).not.toHaveBeenCalled();
  40. });
  41. it('requires start, end and profilerId', async () => {
  42. for (const [start, end, profilerId] of [
  43. [undefined, new Date().toISOString(), uuid4()],
  44. [new Date().toISOString(), undefined, uuid4()],
  45. [new Date().toISOString(), new Date().toISOString(), undefined],
  46. ]) {
  47. const {organization, project, router} = initializeOrg({
  48. // params: {orgId: organization.slug, projectId: project.slug},
  49. router: {
  50. location: {
  51. query: {
  52. start,
  53. end,
  54. profilerId,
  55. eventId: '1',
  56. },
  57. },
  58. },
  59. });
  60. MockApiClient.addMockResponse({
  61. url: `/projects/${organization.slug}/${project.slug}/events/1/`,
  62. body: {},
  63. });
  64. const captureMessage = jest.spyOn(Sentry, 'captureMessage');
  65. render(<ContinuosProfileProvider>{null}</ContinuosProfileProvider>, {
  66. router,
  67. organization,
  68. });
  69. await waitFor(() =>
  70. expect(captureMessage).toHaveBeenCalledWith(
  71. expect.stringContaining(
  72. 'Failed to fetch continuous profile - invalid chunk parameters.'
  73. )
  74. )
  75. );
  76. }
  77. });
  78. });