index.spec.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import {ReleaseFixture} from 'sentry-fixture/release';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {getReleaseBounds, getReleaseParams, searchReleaseVersion} from './index';
  4. describe('releases/utils', () => {
  5. describe('getReleaseBounds', () => {
  6. it('returns start and end of a release', () => {
  7. expect(getReleaseBounds(ReleaseFixture())).toEqual({
  8. releaseStart: '2020-03-23T01:02:00Z',
  9. releaseEnd: '2020-03-24T02:04:59Z',
  10. type: 'normal',
  11. });
  12. });
  13. it('higher last session takes precendence over last event', () => {
  14. expect(
  15. getReleaseBounds(
  16. ReleaseFixture({
  17. currentProjectMeta: {
  18. sessionsUpperBound: '2020-03-24T03:04:55Z',
  19. firstReleaseVersion: null,
  20. lastReleaseVersion: null,
  21. nextReleaseVersion: null,
  22. prevReleaseVersion: null,
  23. sessionsLowerBound: null,
  24. },
  25. })
  26. )
  27. ).toEqual({
  28. releaseStart: '2020-03-23T01:02:00Z',
  29. releaseEnd: '2020-03-24T03:04:59Z',
  30. type: 'normal',
  31. });
  32. });
  33. it('there is no last session/event, it fallbacks to now', () => {
  34. expect(getReleaseBounds(ReleaseFixture({lastEvent: undefined}))).toEqual({
  35. releaseStart: '2020-03-23T01:02:00Z',
  36. releaseEnd: '2017-10-17T02:41:59Z',
  37. type: 'normal',
  38. });
  39. });
  40. it('adds 1 minute to end if start and end are within same minute', () => {
  41. expect(
  42. getReleaseBounds(
  43. ReleaseFixture({
  44. dateCreated: '2020-03-23T01:02:30Z',
  45. lastEvent: '2020-03-23T01:02:39Z',
  46. })
  47. )
  48. ).toEqual({
  49. releaseStart: '2020-03-23T01:02:00Z',
  50. releaseEnd: '2020-03-23T01:03:59Z',
  51. type: 'normal',
  52. });
  53. });
  54. it('clamps active releases lasting longer than 90 days', () => {
  55. expect(
  56. getReleaseBounds(
  57. ReleaseFixture({
  58. dateCreated: '2017-05-17T02:41:20Z',
  59. lastEvent: '2017-10-12T02:41:20Z',
  60. })
  61. )
  62. ).toEqual({
  63. releaseStart: '2017-07-19T02:41:20Z',
  64. releaseEnd: '2017-10-12T02:41:59Z',
  65. type: 'clamped',
  66. });
  67. });
  68. it('defaults ancient releases to last 90 days', () => {
  69. expect(
  70. getReleaseBounds(
  71. ReleaseFixture({
  72. dateCreated: '2010-05-17T02:41:20Z',
  73. lastEvent: '2011-10-17T02:41:20Z',
  74. })
  75. )
  76. ).toEqual({
  77. releaseStart: '2017-07-19T02:41:20Z',
  78. releaseEnd: '2017-10-17T02:41:20Z',
  79. type: 'ancient',
  80. });
  81. });
  82. it('handles no lastEvent for ancient releases', () => {
  83. expect(
  84. getReleaseBounds(
  85. ReleaseFixture({
  86. dateCreated: '2010-05-17T02:41:20Z',
  87. lastEvent: undefined,
  88. })
  89. )
  90. ).toEqual({
  91. releaseStart: '2017-07-19T02:41:20Z',
  92. releaseEnd: '2017-10-17T02:41:20Z',
  93. type: 'ancient',
  94. });
  95. });
  96. });
  97. describe('getReleaseParams', () => {
  98. const {router} = initializeOrg();
  99. const releaseBounds = getReleaseBounds(ReleaseFixture());
  100. it('returns params related to a release', () => {
  101. const location = {
  102. ...router.location,
  103. query: {
  104. pageStatsPeriod: '30d',
  105. project: ['456'],
  106. environment: ['prod'],
  107. somethingBad: 'meh',
  108. },
  109. };
  110. expect(
  111. getReleaseParams({
  112. location,
  113. releaseBounds,
  114. })
  115. ).toEqual({
  116. statsPeriod: '30d',
  117. project: ['456'],
  118. environment: ['prod'],
  119. });
  120. });
  121. it('returns release start/end if no other datetime is present', () => {
  122. expect(
  123. getReleaseParams({
  124. location: {...router.location, query: {}},
  125. releaseBounds,
  126. })
  127. ).toEqual({
  128. start: '2020-03-23T01:02:00Z',
  129. end: '2020-03-24T02:04:59Z',
  130. });
  131. });
  132. it('returns correct start/end when zoomed in', () => {
  133. expect(
  134. getReleaseParams({
  135. location: {
  136. ...router.location,
  137. query: {pageStart: '2021-03-23T01:02:30Z', pageEnd: '2022-03-23T01:02:30Z'},
  138. },
  139. releaseBounds,
  140. })
  141. ).toEqual({
  142. start: '2021-03-23T01:02:30.000',
  143. end: '2022-03-23T01:02:30.000',
  144. });
  145. });
  146. });
  147. });
  148. describe('searchReleaseVersion()', function () {
  149. it('should escape quotes', function () {
  150. expect(searchReleaseVersion('com.sentry.go_app@"1.0.0-chore"')).toBe(
  151. 'release:"com.sentry.go_app@\\"1.0.0-chore\\""'
  152. );
  153. });
  154. });