continuousProfileProvider.spec.tsx 2.7 KB

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