traceProfilingLink.spec.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. traceId: '',
  35. threadId: '0',
  36. })
  37. ).toBeNull();
  38. });
  39. it('requires orgSlug', () => {
  40. const event = makeTransaction();
  41. expect(
  42. makeTraceContinuousProfilingLink(node, event.profiler_id, {
  43. projectSlug: '',
  44. orgSlug: 'sentry',
  45. traceId: '',
  46. threadId: '0',
  47. })
  48. ).toBeNull();
  49. });
  50. it('requires profilerId', () => {
  51. expect(
  52. // @ts-expect-error missing profiler_id
  53. makeTraceContinuousProfilingLink(node, undefined, {
  54. projectSlug: 'project',
  55. orgSlug: 'sentry',
  56. })
  57. ).toBeNull();
  58. });
  59. });
  60. it('creates a window of time around end timestamp', () => {
  61. const timestamp = new Date().getTime();
  62. const node = new TraceTreeNode(
  63. null,
  64. makeTransaction({
  65. start_timestamp: undefined,
  66. timestamp: timestamp / 1e3,
  67. event_id: 'event',
  68. }),
  69. {
  70. project_slug: 'project',
  71. event_id: 'event',
  72. }
  73. );
  74. const link: LocationDescriptor | null = makeTraceContinuousProfilingLink(
  75. node,
  76. 'profiler',
  77. {
  78. projectSlug: 'project',
  79. orgSlug: 'sentry',
  80. traceId: 'trace',
  81. threadId: '0',
  82. }
  83. );
  84. // @ts-expect-error mismatch in types?
  85. expect(link.query.start).toBe(new Date(timestamp - 100).toISOString());
  86. // @ts-expect-error mismatch in types?
  87. expect(link.query.end).toBe(new Date(timestamp + 100).toISOString());
  88. });
  89. });