releaseHealthRequest.spec.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. import isEqual from 'lodash/isEqual';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {HealthStatsPeriodOption} from 'app/types';
  5. import {DisplayOption} from 'app/views/releases/list/utils';
  6. import ReleaseHealthRequest from 'app/views/releases/utils/releaseHealthRequest';
  7. describe('ReleaseHealthRequest', function () {
  8. const {organization, routerContext, router} = initializeOrg();
  9. const projectId = 123;
  10. const selection = {
  11. projects: [projectId],
  12. environments: [],
  13. datetime: {
  14. period: '14d',
  15. start: null,
  16. end: null,
  17. utc: false,
  18. },
  19. };
  20. // @ts-expect-error
  21. MockApiClient.addMockResponse(
  22. {
  23. url: `/organizations/org-slug/sessions/`,
  24. // @ts-ignore Cannot find TestStubs
  25. body: TestStubs.SessionStatusCountByReleaseInPeriod(),
  26. },
  27. {
  28. predicate(_url, {query}) {
  29. return isEqual(query, {
  30. query:
  31. 'release:7a82c130be9143361f20bc77252df783cf91e4fc OR release:e102abb2c46e7fe8686441091005c12aed90da99',
  32. interval: '1d',
  33. statsPeriod: '14d',
  34. project: [projectId],
  35. field: ['sum(session)'],
  36. groupBy: ['project', 'release', 'session.status'],
  37. });
  38. },
  39. }
  40. );
  41. // @ts-expect-error
  42. const requestForAutoHealthStatsPeriodSessionHistogram = MockApiClient.addMockResponse(
  43. {
  44. url: `/organizations/org-slug/sessions/`,
  45. // @ts-ignore Cannot find TestStubs
  46. body: TestStubs.SessionStatusCountByProjectInPeriod(),
  47. },
  48. {
  49. predicate(_url, {query}) {
  50. return isEqual(query, {
  51. query: undefined,
  52. interval: '1d',
  53. statsPeriod: '14d',
  54. project: [projectId],
  55. field: ['sum(session)'],
  56. groupBy: ['project', 'session.status'],
  57. });
  58. },
  59. }
  60. );
  61. // @ts-expect-error
  62. const requestForAutoTotalCountByProjectInPeriod = MockApiClient.addMockResponse(
  63. {
  64. url: `/organizations/org-slug/sessions/`,
  65. // @ts-expect-error
  66. body: TestStubs.SessionTotalCountByProjectIn24h(),
  67. },
  68. {
  69. predicate(_url, {query}) {
  70. return isEqual(query, {
  71. query: undefined,
  72. interval: '1d',
  73. statsPeriod: '14d',
  74. project: [123],
  75. field: ['sum(session)'],
  76. groupBy: ['project'],
  77. });
  78. },
  79. }
  80. );
  81. // @ts-expect-error
  82. const requestForAutoTotalCountByReleaseInPeriod = MockApiClient.addMockResponse(
  83. {
  84. url: `/organizations/org-slug/sessions/`,
  85. // @ts-expect-error
  86. body: TestStubs.SesssionTotalCountByReleaseIn24h(),
  87. },
  88. {
  89. predicate(_url, {query}) {
  90. return isEqual(query, {
  91. query:
  92. 'release:7a82c130be9143361f20bc77252df783cf91e4fc OR release:e102abb2c46e7fe8686441091005c12aed90da99',
  93. interval: '1d',
  94. statsPeriod: '14d',
  95. project: [123],
  96. field: ['sum(session)'],
  97. groupBy: ['project', 'release'],
  98. });
  99. },
  100. }
  101. );
  102. // @ts-expect-error
  103. MockApiClient.addMockResponse(
  104. {
  105. url: `/organizations/${organization.slug}/sessions/`,
  106. // @ts-ignore Cannot find TestStubs
  107. body: TestStubs.SesssionTotalCountByReleaseIn24h(),
  108. },
  109. {
  110. predicate(_url, {query}) {
  111. return isEqual(query, {
  112. query:
  113. 'release:7a82c130be9143361f20bc77252df783cf91e4fc OR release:e102abb2c46e7fe8686441091005c12aed90da99',
  114. interval: '1h',
  115. statsPeriod: '24h',
  116. project: [projectId],
  117. field: ['sum(session)'],
  118. groupBy: ['project', 'release'],
  119. });
  120. },
  121. }
  122. );
  123. // @ts-expect-error
  124. MockApiClient.addMockResponse(
  125. {
  126. url: `/organizations/org-slug/sessions/`,
  127. // @ts-ignore Cannot find TestStubs
  128. body: TestStubs.SessionTotalCountByProjectIn24h(),
  129. },
  130. {
  131. predicate(_url, {query}) {
  132. return isEqual(query, {
  133. query: undefined,
  134. interval: '1h',
  135. statsPeriod: '24h',
  136. project: [projectId],
  137. field: ['sum(session)'],
  138. groupBy: ['project'],
  139. });
  140. },
  141. }
  142. );
  143. // @ts-expect-error
  144. MockApiClient.addMockResponse(
  145. {
  146. url: `/organizations/org-slug/sessions/`,
  147. // @ts-ignore Cannot find TestStubs
  148. body: TestStubs.SessionUserStatusCountByReleaseInPeriod(),
  149. },
  150. {
  151. predicate(_url, {query}) {
  152. return isEqual(query, {
  153. query:
  154. 'release:7a82c130be9143361f20bc77252df783cf91e4fc OR release:e102abb2c46e7fe8686441091005c12aed90da99',
  155. interval: '1d',
  156. statsPeriod: '14d',
  157. project: [projectId],
  158. field: ['count_unique(user)', 'sum(session)'],
  159. groupBy: ['project', 'release', 'session.status'],
  160. });
  161. },
  162. }
  163. );
  164. // @ts-expect-error
  165. MockApiClient.addMockResponse(
  166. {
  167. url: `/organizations/${organization.slug}/sessions/`,
  168. // @ts-ignore Cannot find TestStubs
  169. body: TestStubs.UserTotalCountByReleaseIn24h(),
  170. },
  171. {
  172. predicate(_url, {query}) {
  173. return isEqual(query, {
  174. query:
  175. 'release:7a82c130be9143361f20bc77252df783cf91e4fc OR release:e102abb2c46e7fe8686441091005c12aed90da99',
  176. interval: '1h',
  177. statsPeriod: '24h',
  178. project: [projectId],
  179. field: ['count_unique(user)'],
  180. groupBy: ['project', 'release'],
  181. });
  182. },
  183. }
  184. );
  185. // @ts-expect-error
  186. MockApiClient.addMockResponse(
  187. {
  188. url: `/organizations/org-slug/sessions/`,
  189. // @ts-ignore Cannot find TestStubs
  190. body: TestStubs.UserTotalCountByProjectIn24h(),
  191. },
  192. {
  193. predicate(_url, {query}) {
  194. return isEqual(query, {
  195. query: undefined,
  196. interval: '1h',
  197. statsPeriod: '24h',
  198. project: [projectId],
  199. field: ['count_unique(user)'],
  200. groupBy: ['project'],
  201. });
  202. },
  203. }
  204. );
  205. it('calculates correct session health data', async function () {
  206. let healthData;
  207. const wrapper = mountWithTheme(
  208. <ReleaseHealthRequest
  209. releases={[
  210. '7a82c130be9143361f20bc77252df783cf91e4fc',
  211. 'e102abb2c46e7fe8686441091005c12aed90da99',
  212. ]}
  213. organization={organization}
  214. location={{
  215. ...router.location,
  216. query: {
  217. project: [projectId],
  218. },
  219. }}
  220. display={[DisplayOption.SESSIONS]}
  221. selection={selection}
  222. >
  223. {({getHealthData}) => {
  224. healthData = getHealthData;
  225. return null;
  226. }}
  227. </ReleaseHealthRequest>,
  228. routerContext
  229. );
  230. // @ts-expect-error
  231. await tick();
  232. wrapper.update();
  233. expect(
  234. healthData.getCrashCount(
  235. '7a82c130be9143361f20bc77252df783cf91e4fc',
  236. projectId,
  237. DisplayOption.SESSIONS
  238. )
  239. ).toBe(492);
  240. expect(
  241. healthData.getCrashFreeRate(
  242. '7a82c130be9143361f20bc77252df783cf91e4fc',
  243. projectId,
  244. DisplayOption.SESSIONS
  245. )
  246. ).toBe(99.76);
  247. expect(
  248. healthData.get24hCountByRelease(
  249. '7a82c130be9143361f20bc77252df783cf91e4fc',
  250. projectId,
  251. DisplayOption.SESSIONS
  252. )
  253. ).toBe(219826);
  254. expect(healthData.get24hCountByProject(projectId, DisplayOption.SESSIONS)).toBe(
  255. 835965
  256. );
  257. expect(
  258. healthData.getTimeSeries(
  259. '7a82c130be9143361f20bc77252df783cf91e4fc',
  260. projectId,
  261. DisplayOption.SESSIONS
  262. )
  263. ).toEqual([
  264. {
  265. data: [
  266. {name: 1615975200000, value: 0},
  267. {name: 1615978800000, value: 0},
  268. {name: 1615982400000, value: 0},
  269. {name: 1615986000000, value: 0},
  270. {name: 1615989600000, value: 0},
  271. {name: 1615993200000, value: 0},
  272. {name: 1615996800000, value: 0},
  273. {name: 1616000400000, value: 0},
  274. {name: 1616004000000, value: 0},
  275. {name: 1616007600000, value: 0},
  276. {name: 1616011200000, value: 0},
  277. {name: 1616014800000, value: 0},
  278. {name: 1616018400000, value: 0},
  279. {name: 1616022000000, value: 3444},
  280. {name: 1616025600000, value: 14912},
  281. {name: 1616029200000, value: 15649},
  282. {name: 1616032800000, value: 18019},
  283. {name: 1616036400000, value: 16726},
  284. {name: 1616040000000, value: 17540},
  285. {name: 1616043600000, value: 16970},
  286. {name: 1616047200000, value: 25015},
  287. {name: 1616050800000, value: 34686},
  288. {name: 1616054400000, value: 46434},
  289. {name: 1616058000000, value: 10431},
  290. ],
  291. seriesName: 'This Release',
  292. },
  293. {
  294. data: [
  295. {name: 1615975200000, value: 51284},
  296. {name: 1615978800000, value: 43820},
  297. {name: 1615982400000, value: 46981},
  298. {name: 1615986000000, value: 56929},
  299. {name: 1615989600000, value: 59999},
  300. {name: 1615993200000, value: 60476},
  301. {name: 1615996800000, value: 54145},
  302. {name: 1616000400000, value: 52642},
  303. {name: 1616004000000, value: 42917},
  304. {name: 1616007600000, value: 35787},
  305. {name: 1616011200000, value: 35036},
  306. {name: 1616014800000, value: 29287},
  307. {name: 1616018400000, value: 24815},
  308. {name: 1616022000000, value: 19815},
  309. {name: 1616025600000, value: 16334},
  310. {name: 1616029200000, value: 16415},
  311. {name: 1616032800000, value: 18961},
  312. {name: 1616036400000, value: 17512},
  313. {name: 1616040000000, value: 18149},
  314. {name: 1616043600000, value: 17585},
  315. {name: 1616047200000, value: 25725},
  316. {name: 1616050800000, value: 36365},
  317. {name: 1616054400000, value: 48104},
  318. {name: 1616058000000, value: 6882},
  319. ],
  320. seriesName: 'Total Project',
  321. z: 0,
  322. },
  323. ]);
  324. expect(
  325. healthData.getAdoption(
  326. '7a82c130be9143361f20bc77252df783cf91e4fc',
  327. projectId,
  328. DisplayOption.SESSIONS
  329. )
  330. ).toBe(26.29607698886915);
  331. expect(
  332. healthData.getCrashCount(
  333. 'e102abb2c46e7fe8686441091005c12aed90da99',
  334. projectId,
  335. DisplayOption.SESSIONS
  336. )
  337. ).toBe(5);
  338. expect(
  339. healthData.getCrashFreeRate(
  340. 'e102abb2c46e7fe8686441091005c12aed90da99',
  341. projectId,
  342. DisplayOption.SESSIONS
  343. )
  344. ).toBe(99.921);
  345. expect(
  346. healthData.get24hCountByRelease(
  347. 'e102abb2c46e7fe8686441091005c12aed90da99',
  348. projectId,
  349. DisplayOption.SESSIONS
  350. )
  351. ).toBe(6320);
  352. expect(healthData.get24hCountByProject(projectId, DisplayOption.SESSIONS)).toBe(
  353. 835965
  354. );
  355. expect(
  356. healthData.getTimeSeries(
  357. 'e102abb2c46e7fe8686441091005c12aed90da99',
  358. projectId,
  359. DisplayOption.SESSIONS
  360. )
  361. ).toEqual([
  362. {
  363. data: [
  364. {name: 1615975200000, value: 0},
  365. {name: 1615978800000, value: 0},
  366. {name: 1615982400000, value: 0},
  367. {name: 1615986000000, value: 0},
  368. {name: 1615989600000, value: 0},
  369. {name: 1615993200000, value: 0},
  370. {name: 1615996800000, value: 0},
  371. {name: 1616000400000, value: 0},
  372. {name: 1616004000000, value: 0},
  373. {name: 1616007600000, value: 0},
  374. {name: 1616011200000, value: 0},
  375. {name: 1616014800000, value: 0},
  376. {name: 1616018400000, value: 0},
  377. {name: 1616022000000, value: 5809},
  378. {name: 1616025600000, value: 400},
  379. {name: 1616029200000, value: 22},
  380. {name: 1616032800000, value: 26},
  381. {name: 1616036400000, value: 12},
  382. {name: 1616040000000, value: 19},
  383. {name: 1616043600000, value: 8},
  384. {name: 1616047200000, value: 0},
  385. {name: 1616050800000, value: 19},
  386. {name: 1616054400000, value: 5},
  387. {name: 1616058000000, value: 0},
  388. ],
  389. seriesName: 'This Release',
  390. },
  391. {
  392. data: [
  393. {name: 1615975200000, value: 51284},
  394. {name: 1615978800000, value: 43820},
  395. {name: 1615982400000, value: 46981},
  396. {name: 1615986000000, value: 56929},
  397. {name: 1615989600000, value: 59999},
  398. {name: 1615993200000, value: 60476},
  399. {name: 1615996800000, value: 54145},
  400. {name: 1616000400000, value: 52642},
  401. {name: 1616004000000, value: 42917},
  402. {name: 1616007600000, value: 35787},
  403. {name: 1616011200000, value: 35036},
  404. {name: 1616014800000, value: 29287},
  405. {name: 1616018400000, value: 24815},
  406. {name: 1616022000000, value: 19815},
  407. {name: 1616025600000, value: 16334},
  408. {name: 1616029200000, value: 16415},
  409. {name: 1616032800000, value: 18961},
  410. {name: 1616036400000, value: 17512},
  411. {name: 1616040000000, value: 18149},
  412. {name: 1616043600000, value: 17585},
  413. {name: 1616047200000, value: 25725},
  414. {name: 1616050800000, value: 36365},
  415. {name: 1616054400000, value: 48104},
  416. {name: 1616058000000, value: 6882},
  417. ],
  418. seriesName: 'Total Project',
  419. z: 0,
  420. },
  421. ]);
  422. expect(
  423. healthData.getAdoption(
  424. 'e102abb2c46e7fe8686441091005c12aed90da99',
  425. projectId,
  426. DisplayOption.SESSIONS
  427. )
  428. ).toBe(0.7560125124855706);
  429. expect(requestForAutoHealthStatsPeriodSessionHistogram).toHaveBeenCalledTimes(0);
  430. });
  431. it('calculates correct user health data', async function () {
  432. let healthData;
  433. const wrapper = mountWithTheme(
  434. <ReleaseHealthRequest
  435. releases={[
  436. '7a82c130be9143361f20bc77252df783cf91e4fc',
  437. 'e102abb2c46e7fe8686441091005c12aed90da99',
  438. ]}
  439. organization={organization}
  440. location={{
  441. ...router.location,
  442. query: {
  443. project: [projectId],
  444. },
  445. }}
  446. display={[DisplayOption.USERS]}
  447. selection={selection}
  448. >
  449. {({getHealthData}) => {
  450. healthData = getHealthData;
  451. return null;
  452. }}
  453. </ReleaseHealthRequest>,
  454. routerContext
  455. );
  456. // @ts-expect-error
  457. await tick();
  458. wrapper.update();
  459. expect(
  460. healthData.getCrashCount(
  461. '7a82c130be9143361f20bc77252df783cf91e4fc',
  462. projectId,
  463. DisplayOption.SESSIONS
  464. )
  465. ).toBe(492);
  466. expect(
  467. healthData.getCrashFreeRate(
  468. '7a82c130be9143361f20bc77252df783cf91e4fc',
  469. projectId,
  470. DisplayOption.USERS
  471. )
  472. ).toBe(99.908);
  473. expect(
  474. healthData.get24hCountByRelease(
  475. '7a82c130be9143361f20bc77252df783cf91e4fc',
  476. projectId,
  477. DisplayOption.USERS
  478. )
  479. ).toBe(56826);
  480. expect(healthData.get24hCountByProject(projectId, DisplayOption.USERS)).toBe(140965);
  481. expect(
  482. healthData.getTimeSeries(
  483. '7a82c130be9143361f20bc77252df783cf91e4fc',
  484. projectId,
  485. DisplayOption.USERS
  486. )
  487. ).toEqual([
  488. {
  489. data: [
  490. {name: 1615975200000, value: 0},
  491. {name: 1615978800000, value: 0},
  492. {name: 1615982400000, value: 0},
  493. {name: 1615986000000, value: 0},
  494. {name: 1615989600000, value: 0},
  495. {name: 1615993200000, value: 0},
  496. {name: 1615996800000, value: 0},
  497. {name: 1616000400000, value: 0},
  498. {name: 1616004000000, value: 0},
  499. {name: 1616007600000, value: 0},
  500. {name: 1616011200000, value: 0},
  501. {name: 1616014800000, value: 0},
  502. {name: 1616018400000, value: 0},
  503. {name: 1616022000000, value: 444},
  504. {name: 1616025600000, value: 4912},
  505. {name: 1616029200000, value: 5649},
  506. {name: 1616032800000, value: 8019},
  507. {name: 1616036400000, value: 6726},
  508. {name: 1616040000000, value: 7540},
  509. {name: 1616043600000, value: 6970},
  510. {name: 1616047200000, value: 5015},
  511. {name: 1616050800000, value: 4686},
  512. {name: 1616054400000, value: 6434},
  513. {name: 1616058000000, value: 431},
  514. ],
  515. seriesName: 'This Release',
  516. },
  517. {
  518. data: [
  519. {name: 1615975200000, value: 1284},
  520. {name: 1615978800000, value: 3820},
  521. {name: 1615982400000, value: 6981},
  522. {name: 1615986000000, value: 6929},
  523. {name: 1615989600000, value: 9999},
  524. {name: 1615993200000, value: 1476},
  525. {name: 1615996800000, value: 4145},
  526. {name: 1616000400000, value: 2642},
  527. {name: 1616004000000, value: 2917},
  528. {name: 1616007600000, value: 5787},
  529. {name: 1616011200000, value: 5036},
  530. {name: 1616014800000, value: 9287},
  531. {name: 1616018400000, value: 4815},
  532. {name: 1616022000000, value: 9815},
  533. {name: 1616025600000, value: 6334},
  534. {name: 1616029200000, value: 6415},
  535. {name: 1616032800000, value: 8961},
  536. {name: 1616036400000, value: 7512},
  537. {name: 1616040000000, value: 8149},
  538. {name: 1616043600000, value: 7585},
  539. {name: 1616047200000, value: 5725},
  540. {name: 1616050800000, value: 6365},
  541. {name: 1616054400000, value: 8104},
  542. {name: 1616058000000, value: 882},
  543. ],
  544. seriesName: 'Total Project',
  545. z: 0,
  546. },
  547. ]);
  548. expect(
  549. healthData.getAdoption(
  550. '7a82c130be9143361f20bc77252df783cf91e4fc',
  551. projectId,
  552. DisplayOption.USERS
  553. )
  554. ).toBe(40.31213421771362);
  555. expect(
  556. healthData.getCrashCount(
  557. 'e102abb2c46e7fe8686441091005c12aed90da99',
  558. projectId,
  559. DisplayOption.SESSIONS
  560. )
  561. ).toBe(5);
  562. expect(
  563. healthData.getCrashFreeRate(
  564. 'e102abb2c46e7fe8686441091005c12aed90da99',
  565. projectId,
  566. DisplayOption.USERS
  567. )
  568. ).toBe(99.87);
  569. expect(
  570. healthData.get24hCountByRelease(
  571. 'e102abb2c46e7fe8686441091005c12aed90da99',
  572. projectId,
  573. DisplayOption.USERS
  574. )
  575. ).toBe(850);
  576. expect(healthData.get24hCountByProject(projectId, DisplayOption.USERS)).toBe(140965);
  577. expect(
  578. healthData.getTimeSeries(
  579. 'e102abb2c46e7fe8686441091005c12aed90da99',
  580. projectId,
  581. DisplayOption.USERS
  582. )
  583. ).toEqual([
  584. {
  585. data: [
  586. {name: 1615975200000, value: 0},
  587. {name: 1615978800000, value: 0},
  588. {name: 1615982400000, value: 0},
  589. {name: 1615986000000, value: 0},
  590. {name: 1615989600000, value: 0},
  591. {name: 1615993200000, value: 0},
  592. {name: 1615996800000, value: 0},
  593. {name: 1616000400000, value: 0},
  594. {name: 1616004000000, value: 0},
  595. {name: 1616007600000, value: 0},
  596. {name: 1616011200000, value: 0},
  597. {name: 1616014800000, value: 0},
  598. {name: 1616018400000, value: 0},
  599. {name: 1616022000000, value: 809},
  600. {name: 1616025600000, value: 0},
  601. {name: 1616029200000, value: 2},
  602. {name: 1616032800000, value: 6},
  603. {name: 1616036400000, value: 2},
  604. {name: 1616040000000, value: 9},
  605. {name: 1616043600000, value: 8},
  606. {name: 1616047200000, value: 0},
  607. {name: 1616050800000, value: 9},
  608. {name: 1616054400000, value: 5},
  609. {name: 1616058000000, value: 0},
  610. ],
  611. seriesName: 'This Release',
  612. },
  613. {
  614. data: [
  615. {name: 1615975200000, value: 1284},
  616. {name: 1615978800000, value: 3820},
  617. {name: 1615982400000, value: 6981},
  618. {name: 1615986000000, value: 6929},
  619. {name: 1615989600000, value: 9999},
  620. {name: 1615993200000, value: 1476},
  621. {name: 1615996800000, value: 4145},
  622. {name: 1616000400000, value: 2642},
  623. {name: 1616004000000, value: 2917},
  624. {name: 1616007600000, value: 5787},
  625. {name: 1616011200000, value: 5036},
  626. {name: 1616014800000, value: 9287},
  627. {name: 1616018400000, value: 4815},
  628. {name: 1616022000000, value: 9815},
  629. {name: 1616025600000, value: 6334},
  630. {name: 1616029200000, value: 6415},
  631. {name: 1616032800000, value: 8961},
  632. {name: 1616036400000, value: 7512},
  633. {name: 1616040000000, value: 8149},
  634. {name: 1616043600000, value: 7585},
  635. {name: 1616047200000, value: 5725},
  636. {name: 1616050800000, value: 6365},
  637. {name: 1616054400000, value: 8104},
  638. {name: 1616058000000, value: 882},
  639. ],
  640. seriesName: 'Total Project',
  641. z: 0,
  642. },
  643. ]);
  644. expect(
  645. healthData.getAdoption(
  646. 'e102abb2c46e7fe8686441091005c12aed90da99',
  647. projectId,
  648. DisplayOption.USERS
  649. )
  650. ).toBe(0.6029865569467598);
  651. });
  652. it('calculates correct session count histogram (auto period)', async function () {
  653. let healthData;
  654. const wrapper = mountWithTheme(
  655. <ReleaseHealthRequest
  656. releases={[
  657. '7a82c130be9143361f20bc77252df783cf91e4fc',
  658. 'e102abb2c46e7fe8686441091005c12aed90da99',
  659. ]}
  660. organization={organization}
  661. location={{
  662. ...router.location,
  663. query: {
  664. project: [projectId],
  665. },
  666. }}
  667. display={[DisplayOption.SESSIONS]}
  668. selection={selection}
  669. healthStatsPeriod={HealthStatsPeriodOption.AUTO}
  670. >
  671. {({getHealthData}) => {
  672. healthData = getHealthData;
  673. return null;
  674. }}
  675. </ReleaseHealthRequest>,
  676. routerContext
  677. );
  678. // @ts-expect-error
  679. await tick();
  680. wrapper.update();
  681. expect(
  682. healthData.getTimeSeries(
  683. '7a82c130be9143361f20bc77252df783cf91e4fc',
  684. projectId,
  685. DisplayOption.SESSIONS
  686. )
  687. ).toEqual([
  688. {
  689. data: [
  690. {name: 1614902400000, value: 0},
  691. {name: 1614988800000, value: 0},
  692. {name: 1615075200000, value: 0},
  693. {name: 1615161600000, value: 0},
  694. {name: 1615248000000, value: 0},
  695. {name: 1615334400000, value: 0},
  696. {name: 1615420800000, value: 0},
  697. {name: 1615507200000, value: 0},
  698. {name: 1615593600000, value: 0},
  699. {name: 1615680000000, value: 0},
  700. {name: 1615766400000, value: 0},
  701. {name: 1615852800000, value: 0},
  702. {name: 1615939200000, value: 3446},
  703. {name: 1616025600000, value: 201136},
  704. ],
  705. seriesName: 'This Release',
  706. },
  707. {
  708. data: [
  709. {name: 1614902400000, value: 0},
  710. {name: 1614988800000, value: 0},
  711. {name: 1615075200000, value: 0},
  712. {name: 1615161600000, value: 0},
  713. {name: 1615248000000, value: 0},
  714. {name: 1615334400000, value: 0},
  715. {name: 1615420800000, value: 0},
  716. {name: 1615507200000, value: 0},
  717. {name: 1615593600000, value: 0},
  718. {name: 1615680000000, value: 0},
  719. {name: 1615766400000, value: 0},
  720. {name: 1615852800000, value: 0},
  721. {name: 1615939200000, value: 9268},
  722. {name: 1616025600000, value: 1083},
  723. ],
  724. seriesName: 'Total Project',
  725. z: 0,
  726. },
  727. ]);
  728. expect(
  729. healthData.getAdoption(
  730. '7a82c130be9143361f20bc77252df783cf91e4fc',
  731. projectId,
  732. DisplayOption.SESSIONS
  733. )
  734. ).toBe(26.29607698886915);
  735. expect(requestForAutoHealthStatsPeriodSessionHistogram).toHaveBeenCalledTimes(1);
  736. expect(requestForAutoTotalCountByProjectInPeriod).toHaveBeenCalledTimes(1);
  737. expect(requestForAutoTotalCountByReleaseInPeriod).toHaveBeenCalledTimes(1);
  738. });
  739. });