traceProfilingLink.spec.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import type {LocationDescriptor} from 'history';
  2. import type {TraceTree} from 'sentry/views/performance/newTraceDetails/traceModels/traceTree';
  3. import {TraceTreeNode} from 'sentry/views/performance/newTraceDetails/traceModels/traceTree';
  4. import {makeTraceContinuousProfilingLink} from './traceProfilingLink';
  5. function makeTransaction(
  6. overrides: Partial<TraceTree.Transaction> = {}
  7. ): TraceTree.Transaction {
  8. return {
  9. children: [],
  10. sdk_name: '',
  11. start_timestamp: 0,
  12. timestamp: 1,
  13. transaction: 'transaction',
  14. 'transaction.op': '',
  15. 'transaction.status': '',
  16. profiler_id: '',
  17. performance_issues: [],
  18. errors: [],
  19. ...overrides,
  20. } as TraceTree.Transaction;
  21. }
  22. describe('traceProfilingLink', () => {
  23. describe('required params', () => {
  24. const node = new TraceTreeNode(null, makeTransaction(), {
  25. project_slug: '',
  26. event_id: '',
  27. });
  28. it('requires projectSlug', () => {
  29. const event = makeTransaction();
  30. expect(
  31. makeTraceContinuousProfilingLink(node, event.profiler_id, {
  32. projectSlug: 'project',
  33. orgSlug: '',
  34. })
  35. ).toBeNull();
  36. });
  37. it('requires orgSlug', () => {
  38. const event = makeTransaction();
  39. expect(
  40. makeTraceContinuousProfilingLink(node, event.profiler_id, {
  41. projectSlug: '',
  42. orgSlug: 'sentry',
  43. })
  44. ).toBeNull();
  45. });
  46. it('requires profilerId', () => {
  47. expect(
  48. // @ts-expect-error missing profiler_id
  49. makeTraceContinuousProfilingLink(node, undefined, {
  50. projectSlug: 'project',
  51. orgSlug: 'sentry',
  52. })
  53. ).toBeNull();
  54. });
  55. });
  56. it('creates a window of time around end timestamp', () => {
  57. const timestamp = new Date().getTime();
  58. const node = new TraceTreeNode(
  59. null,
  60. makeTransaction({start_timestamp: undefined, timestamp: timestamp / 1e3}),
  61. {
  62. project_slug: '',
  63. event_id: '',
  64. }
  65. );
  66. const link: LocationDescriptor | null = makeTraceContinuousProfilingLink(
  67. node,
  68. 'profiler',
  69. {
  70. projectSlug: 'project',
  71. orgSlug: 'sentry',
  72. }
  73. );
  74. // @ts-expect-error mismatch in types?
  75. expect(link.query.start).toBe(new Date(timestamp - 100).toISOString());
  76. // @ts-expect-error mismatch in types?
  77. expect(link.query.end).toBe(new Date(timestamp + 100).toISOString());
  78. });
  79. });