traceProfilingLink.spec.tsx 2.7 KB

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