continuousProfileProvider.spec.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. });
  23. const captureMessage = jest.spyOn(Sentry, 'captureMessage');
  24. const chunkRequest = MockApiClient.addMockResponse({
  25. url: `/organizations/${organization.slug}/profiling/chunks/`,
  26. body: {},
  27. });
  28. render(<ContinuosProfileProvider>{null}</ContinuosProfileProvider>, {
  29. router: {
  30. params: {orgId: organization.slug, projectId: project.slug},
  31. },
  32. organization,
  33. });
  34. await waitFor(() => expect(chunkRequest).toHaveBeenCalled());
  35. expect(captureMessage).not.toHaveBeenCalled();
  36. });
  37. it('requires start, end and profilerId', async () => {
  38. for (const [start, end, profilerId] of [
  39. [undefined, new Date().toISOString(), uuid4()],
  40. [new Date().toISOString(), undefined, uuid4()],
  41. [new Date().toISOString(), new Date().toISOString(), undefined],
  42. ]) {
  43. window.location.search = qs.stringify({start, end, profilerId});
  44. const captureMessage = jest.spyOn(Sentry, 'captureMessage');
  45. render(<ContinuosProfileProvider>{null}</ContinuosProfileProvider>, {
  46. router: {
  47. params: {orgId: OrganizationFixture().slug, projectId: ProjectFixture().slug},
  48. },
  49. organization: OrganizationFixture(),
  50. });
  51. await waitFor(() =>
  52. expect(captureMessage).toHaveBeenCalledWith(
  53. expect.stringContaining(
  54. 'Failed to fetch continuous profile - invalid query parameters.'
  55. )
  56. )
  57. );
  58. }
  59. });
  60. });