billing.spec.tsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. import moment from 'moment-timezone';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
  4. import {DataCategory} from 'sentry/types/core';
  5. import {BILLION, GIGABYTE, MILLION, UNLIMITED} from 'getsentry/constants';
  6. import type {ProductTrial} from 'getsentry/types';
  7. import {
  8. formatReservedWithUnits,
  9. formatUsageWithUnits,
  10. getActiveProductTrial,
  11. getProductTrial,
  12. getSlot,
  13. hasPerformance,
  14. isBizPlanFamily,
  15. isDeveloperPlan,
  16. isTeamPlanFamily,
  17. MILLISECONDS_IN_HOUR,
  18. trialPromptIsDismissed,
  19. } from 'getsentry/utils/billing';
  20. describe('formatReservedWithUnits', function () {
  21. it('returns correct string for Errors', function () {
  22. expect(formatReservedWithUnits(null, DataCategory.ERRORS)).toBe('0');
  23. expect(formatReservedWithUnits(0, DataCategory.ERRORS)).toBe('0');
  24. expect(formatReservedWithUnits(-1, DataCategory.ERRORS)).toBe(UNLIMITED);
  25. expect(formatReservedWithUnits(1, DataCategory.ERRORS)).toBe('1');
  26. expect(formatReservedWithUnits(1000, DataCategory.ERRORS)).toBe('1,000');
  27. expect(formatReservedWithUnits(MILLION, DataCategory.ERRORS)).toBe('1,000,000');
  28. expect(formatReservedWithUnits(BILLION, DataCategory.ERRORS)).toBe('1,000,000,000');
  29. expect(
  30. formatReservedWithUnits(1234, DataCategory.ERRORS, {
  31. isAbbreviated: true,
  32. })
  33. ).toBe('1K');
  34. expect(
  35. formatReservedWithUnits(MILLION, DataCategory.ERRORS, {
  36. isAbbreviated: true,
  37. })
  38. ).toBe('1M');
  39. expect(
  40. formatReservedWithUnits(1.234 * MILLION, DataCategory.ERRORS, {
  41. isAbbreviated: true,
  42. })
  43. ).toBe('1.2M');
  44. expect(
  45. formatReservedWithUnits(BILLION, DataCategory.ERRORS, {
  46. isAbbreviated: true,
  47. })
  48. ).toBe('1B');
  49. expect(
  50. formatReservedWithUnits(1.234 * BILLION, DataCategory.ERRORS, {
  51. isAbbreviated: true,
  52. })
  53. ).toBe('1.23B');
  54. });
  55. it('returns correct string for Transactions', function () {
  56. expect(formatReservedWithUnits(null, DataCategory.TRANSACTIONS)).toBe('0');
  57. expect(formatReservedWithUnits(0, DataCategory.TRANSACTIONS)).toBe('0');
  58. expect(formatReservedWithUnits(-1, DataCategory.TRANSACTIONS)).toBe(UNLIMITED);
  59. expect(formatReservedWithUnits(1, DataCategory.TRANSACTIONS)).toBe('1');
  60. expect(formatReservedWithUnits(1000, DataCategory.TRANSACTIONS)).toBe('1,000');
  61. expect(formatReservedWithUnits(MILLION, DataCategory.TRANSACTIONS)).toBe('1,000,000');
  62. expect(formatReservedWithUnits(BILLION, DataCategory.TRANSACTIONS)).toBe(
  63. '1,000,000,000'
  64. );
  65. expect(
  66. formatReservedWithUnits(1234, DataCategory.TRANSACTIONS, {
  67. isAbbreviated: true,
  68. })
  69. ).toBe('1K');
  70. expect(
  71. formatReservedWithUnits(MILLION, DataCategory.TRANSACTIONS, {
  72. isAbbreviated: true,
  73. })
  74. ).toBe('1M');
  75. expect(
  76. formatReservedWithUnits(1.234 * MILLION, DataCategory.TRANSACTIONS, {
  77. isAbbreviated: true,
  78. })
  79. ).toBe('1.2M');
  80. expect(
  81. formatReservedWithUnits(BILLION, DataCategory.TRANSACTIONS, {
  82. isAbbreviated: true,
  83. })
  84. ).toBe('1B');
  85. expect(
  86. formatReservedWithUnits(1.234 * BILLION, DataCategory.TRANSACTIONS, {
  87. isAbbreviated: true,
  88. })
  89. ).toBe('1.23B');
  90. });
  91. it('returns correct string for Attachments', function () {
  92. expect(formatReservedWithUnits(null, DataCategory.ATTACHMENTS)).toBe('0 GB');
  93. expect(formatReservedWithUnits(0, DataCategory.ATTACHMENTS)).toBe('0 GB');
  94. expect(formatReservedWithUnits(0.1, DataCategory.ATTACHMENTS)).toBe('0.1 GB');
  95. expect(formatReservedWithUnits(1, DataCategory.ATTACHMENTS)).toBe('1 GB');
  96. expect(formatReservedWithUnits(1000, DataCategory.ATTACHMENTS)).toBe('1,000 GB');
  97. expect(formatReservedWithUnits(MILLION, DataCategory.ATTACHMENTS)).toBe(
  98. '1,000,000 GB'
  99. );
  100. expect(formatReservedWithUnits(BILLION, DataCategory.ATTACHMENTS)).toBe(
  101. '1,000,000,000 GB'
  102. );
  103. expect(
  104. formatReservedWithUnits(0.1234, DataCategory.ATTACHMENTS, {
  105. isAbbreviated: true,
  106. })
  107. ).toBe('0 GB');
  108. expect(
  109. formatReservedWithUnits(1.234, DataCategory.ATTACHMENTS, {
  110. isAbbreviated: true,
  111. })
  112. ).toBe('1 GB');
  113. expect(
  114. formatReservedWithUnits(1234, DataCategory.ATTACHMENTS, {
  115. isAbbreviated: true,
  116. })
  117. ).toBe('1K GB');
  118. expect(
  119. formatReservedWithUnits(MILLION, DataCategory.ATTACHMENTS, {
  120. isAbbreviated: true,
  121. })
  122. ).toBe('1M GB');
  123. expect(
  124. formatReservedWithUnits(1.234 * MILLION, DataCategory.ATTACHMENTS, {
  125. isAbbreviated: true,
  126. })
  127. ).toBe('1.2M GB');
  128. expect(
  129. formatReservedWithUnits(BILLION, DataCategory.ATTACHMENTS, {
  130. isAbbreviated: true,
  131. })
  132. ).toBe('1B GB');
  133. expect(
  134. formatReservedWithUnits(1.234 * BILLION, DataCategory.ATTACHMENTS, {
  135. isAbbreviated: true,
  136. })
  137. ).toBe('1.23B GB');
  138. expect(
  139. formatReservedWithUnits(0.1, DataCategory.ATTACHMENTS, {
  140. useUnitScaling: true,
  141. })
  142. ).toBe('0.1 GB');
  143. expect(
  144. formatReservedWithUnits(1, DataCategory.ATTACHMENTS, {
  145. useUnitScaling: true,
  146. })
  147. ).toBe('1 GB');
  148. expect(
  149. formatReservedWithUnits(1000, DataCategory.ATTACHMENTS, {
  150. useUnitScaling: true,
  151. })
  152. ).toBe('1 TB');
  153. expect(
  154. formatReservedWithUnits(1234, DataCategory.ATTACHMENTS, {
  155. useUnitScaling: true,
  156. })
  157. ).toBe('1.23 TB');
  158. expect(
  159. formatReservedWithUnits(1234 * BILLION, DataCategory.ATTACHMENTS, {
  160. useUnitScaling: true,
  161. })
  162. ).toBe('1.23 ZB');
  163. expect(
  164. formatReservedWithUnits(-1 / GIGABYTE, DataCategory.ATTACHMENTS, {
  165. useUnitScaling: true,
  166. })
  167. ).toBe(UNLIMITED);
  168. });
  169. it('returns correct string for Profile Duration', function () {
  170. expect(formatReservedWithUnits(1000, DataCategory.PROFILE_DURATION)).toBe('1,000');
  171. expect(formatReservedWithUnits(0, DataCategory.PROFILE_DURATION)).toBe('0');
  172. expect(formatReservedWithUnits(-1, DataCategory.PROFILE_DURATION)).toBe(UNLIMITED);
  173. expect(formatReservedWithUnits(500, DataCategory.PROFILE_DURATION)).toBe('500');
  174. expect(
  175. formatReservedWithUnits(1000, DataCategory.PROFILE_DURATION, {
  176. isAbbreviated: true,
  177. })
  178. ).toBe('1K');
  179. });
  180. it('returns correct string for reserved budget', function () {
  181. expect(formatReservedWithUnits(1000, DataCategory.SPANS, {}, true)).toBe('$10.00');
  182. expect(formatReservedWithUnits(1500_00, DataCategory.SPANS, {}, true)).toBe(
  183. '$1,500.00'
  184. );
  185. expect(formatReservedWithUnits(0, DataCategory.SPANS, {}, true)).toBe('$0.00');
  186. });
  187. });
  188. describe('formatUsageWithUnits', function () {
  189. it('returns correct strings for Errors', function () {
  190. expect(formatUsageWithUnits(0, DataCategory.ERRORS)).toBe('0');
  191. expect(formatUsageWithUnits(1000, DataCategory.ERRORS)).toBe('1,000');
  192. expect(formatUsageWithUnits(MILLION, DataCategory.ERRORS)).toBe('1,000,000');
  193. expect(formatUsageWithUnits(BILLION, DataCategory.ERRORS)).toBe('1,000,000,000');
  194. expect(formatUsageWithUnits(0, DataCategory.ERRORS, {isAbbreviated: true})).toBe('0');
  195. expect(formatUsageWithUnits(1000, DataCategory.ERRORS, {isAbbreviated: true})).toBe(
  196. '1K'
  197. );
  198. expect(
  199. formatUsageWithUnits(MILLION, DataCategory.ERRORS, {isAbbreviated: true})
  200. ).toBe('1M');
  201. expect(
  202. formatUsageWithUnits(1.234 * MILLION, DataCategory.ERRORS, {
  203. isAbbreviated: true,
  204. })
  205. ).toBe('1.2M');
  206. expect(
  207. formatUsageWithUnits(1.234 * BILLION, DataCategory.ERRORS, {
  208. isAbbreviated: true,
  209. })
  210. ).toBe('1.23B');
  211. });
  212. it('returns correct strings for Transactions', function () {
  213. expect(formatUsageWithUnits(0, DataCategory.TRANSACTIONS)).toBe('0');
  214. expect(formatUsageWithUnits(1000, DataCategory.TRANSACTIONS)).toBe('1,000');
  215. expect(formatUsageWithUnits(MILLION, DataCategory.TRANSACTIONS)).toBe('1,000,000');
  216. expect(formatUsageWithUnits(BILLION, DataCategory.TRANSACTIONS)).toBe(
  217. '1,000,000,000'
  218. );
  219. expect(
  220. formatUsageWithUnits(0, DataCategory.TRANSACTIONS, {isAbbreviated: true})
  221. ).toBe('0');
  222. expect(
  223. formatUsageWithUnits(1000, DataCategory.TRANSACTIONS, {isAbbreviated: true})
  224. ).toBe('1K');
  225. expect(
  226. formatUsageWithUnits(MILLION, DataCategory.TRANSACTIONS, {isAbbreviated: true})
  227. ).toBe('1M');
  228. expect(
  229. formatUsageWithUnits(1.234 * MILLION, DataCategory.TRANSACTIONS, {
  230. isAbbreviated: true,
  231. })
  232. ).toBe('1.2M');
  233. expect(
  234. formatUsageWithUnits(1.234 * BILLION, DataCategory.TRANSACTIONS, {
  235. isAbbreviated: true,
  236. })
  237. ).toBe('1.23B');
  238. });
  239. it('returns correct strings for Attachments', function () {
  240. expect(formatUsageWithUnits(0, DataCategory.ATTACHMENTS)).toBe('0 GB');
  241. expect(formatUsageWithUnits(MILLION, DataCategory.ATTACHMENTS)).toBe('0 GB');
  242. expect(formatUsageWithUnits(BILLION, DataCategory.ATTACHMENTS)).toBe('1 GB');
  243. expect(formatUsageWithUnits(1.234 * BILLION, DataCategory.ATTACHMENTS)).toBe(
  244. '1.23 GB'
  245. );
  246. expect(formatUsageWithUnits(1234 * GIGABYTE, DataCategory.ATTACHMENTS)).toBe(
  247. '1,234 GB'
  248. );
  249. expect(formatUsageWithUnits(0, DataCategory.ATTACHMENTS, {isAbbreviated: true})).toBe(
  250. '0 GB'
  251. );
  252. expect(
  253. formatUsageWithUnits(MILLION, DataCategory.ATTACHMENTS, {isAbbreviated: true})
  254. ).toBe('0 GB');
  255. expect(
  256. formatUsageWithUnits(BILLION, DataCategory.ATTACHMENTS, {isAbbreviated: true})
  257. ).toBe('1 GB');
  258. expect(
  259. formatUsageWithUnits(1.234 * BILLION, DataCategory.ATTACHMENTS, {
  260. isAbbreviated: true,
  261. })
  262. ).toBe('1 GB');
  263. expect(
  264. formatUsageWithUnits(1234 * BILLION, DataCategory.ATTACHMENTS, {
  265. isAbbreviated: true,
  266. })
  267. ).toBe('1K GB');
  268. expect(
  269. formatUsageWithUnits(0, DataCategory.ATTACHMENTS, {
  270. useUnitScaling: true,
  271. })
  272. ).toBe('0 B');
  273. expect(
  274. formatUsageWithUnits(1000, DataCategory.ATTACHMENTS, {
  275. useUnitScaling: true,
  276. })
  277. ).toBe('1 KB');
  278. expect(
  279. formatUsageWithUnits(MILLION, DataCategory.ATTACHMENTS, {
  280. useUnitScaling: true,
  281. })
  282. ).toBe('1 MB');
  283. expect(
  284. formatUsageWithUnits(1.234 * MILLION, DataCategory.ATTACHMENTS, {
  285. useUnitScaling: true,
  286. })
  287. ).toBe('1.23 MB');
  288. expect(
  289. formatUsageWithUnits(1.234 * BILLION, DataCategory.ATTACHMENTS, {
  290. useUnitScaling: true,
  291. })
  292. ).toBe('1.23 GB');
  293. expect(
  294. formatUsageWithUnits(1234 * BILLION, DataCategory.ATTACHMENTS, {
  295. useUnitScaling: true,
  296. })
  297. ).toBe('1.23 TB');
  298. });
  299. it('returns correct string for Profile Duration', function () {
  300. expect(formatUsageWithUnits(0, DataCategory.PROFILE_DURATION)).toBe('0');
  301. expect(formatUsageWithUnits(1, DataCategory.PROFILE_DURATION)).toBe('0');
  302. expect(formatUsageWithUnits(360000, DataCategory.PROFILE_DURATION)).toBe('0.1');
  303. expect(
  304. formatUsageWithUnits(MILLISECONDS_IN_HOUR, DataCategory.PROFILE_DURATION)
  305. ).toBe('1');
  306. expect(
  307. formatUsageWithUnits(5.23 * MILLISECONDS_IN_HOUR, DataCategory.PROFILE_DURATION)
  308. ).toBe('5.2');
  309. expect(
  310. formatUsageWithUnits(1000 * MILLISECONDS_IN_HOUR, DataCategory.PROFILE_DURATION)
  311. ).toBe('1,000');
  312. expect(
  313. formatUsageWithUnits(1000 * MILLISECONDS_IN_HOUR, DataCategory.PROFILE_DURATION, {
  314. isAbbreviated: true,
  315. })
  316. ).toBe('1K');
  317. });
  318. });
  319. describe('getSlot', () => {
  320. function makeBucket(props: {events?: number; price?: number}) {
  321. return {
  322. events: 0,
  323. min: 0,
  324. onDemandPrice: 0,
  325. price: 0,
  326. unitPrice: 0,
  327. ...props,
  328. };
  329. }
  330. it('should return slot zero when no slots are passed', () => {
  331. const reservedEvents = 0;
  332. const currentPrice = 0;
  333. const slot = getSlot(reservedEvents, currentPrice, []);
  334. expect(slot).toBe(0);
  335. });
  336. it('should return slot zero when no price is passed', () => {
  337. const reservedEvents = undefined;
  338. const currentPrice = 0;
  339. const slot = getSlot(reservedEvents, currentPrice, []);
  340. expect(slot).toBe(0);
  341. });
  342. it('should return slot zero when no events is passed', () => {
  343. const reservedEvents = 0;
  344. const currentPrice = undefined;
  345. const slot = getSlot(reservedEvents, currentPrice, []);
  346. expect(slot).toBe(0);
  347. });
  348. it('should return the slot index which matches the current reserved events', () => {
  349. const reservedEvents = 100_000;
  350. const currentPrice = undefined;
  351. const buckets = [
  352. makeBucket({events: 50_000}),
  353. makeBucket({events: 100_000}), // matches the current reservation
  354. makeBucket({events: 200_000}),
  355. ];
  356. const slot = getSlot(reservedEvents, currentPrice, buckets);
  357. expect(slot).toBe(1);
  358. const slotWithMinimize = getSlot(reservedEvents, currentPrice, buckets, true);
  359. expect(slotWithMinimize).toBe(1);
  360. });
  361. it('should return the slot index which matches the current price', () => {
  362. const reservedEvents = undefined;
  363. const currentPrice = 29.0;
  364. const buckets = [
  365. makeBucket({price: 29}), // matches the current price
  366. makeBucket({price: 39}),
  367. makeBucket({price: 49}),
  368. ];
  369. const slot = getSlot(reservedEvents, currentPrice, buckets);
  370. expect(slot).toBe(0);
  371. const slotWithMinimize = getSlot(reservedEvents, currentPrice, buckets, true);
  372. expect(slotWithMinimize).toBe(0);
  373. });
  374. it('should return the slot index that is above the current reserved events', () => {
  375. const reservedEvents = 110_000;
  376. const currentPrice = undefined;
  377. const buckets = [
  378. makeBucket({events: 50_000}),
  379. makeBucket({events: 100_000}),
  380. makeBucket({events: 200_000}), // next highest
  381. ];
  382. const slot = getSlot(reservedEvents, currentPrice, buckets);
  383. expect(slot).toBe(2);
  384. });
  385. it('should return the slot index that is below the current reserved events with minimize strategy', () => {
  386. const reservedEvents = 110_000;
  387. const currentPrice = undefined;
  388. const buckets = [
  389. makeBucket({events: 50_000}),
  390. makeBucket({events: 100_000}), // next lowest
  391. makeBucket({events: 200_000}),
  392. ];
  393. const slot = getSlot(reservedEvents, currentPrice, buckets, true);
  394. expect(slot).toBe(1);
  395. });
  396. it('should return the slot index that is above the current price', () => {
  397. const reservedEvents = undefined;
  398. const currentPrice = 33.0;
  399. const buckets = [
  400. makeBucket({price: 29}),
  401. makeBucket({price: 39}), // next highest
  402. makeBucket({price: 49}),
  403. ];
  404. const slot = getSlot(reservedEvents, currentPrice, buckets);
  405. expect(slot).toBe(1);
  406. });
  407. it('should return the slot index that is below the current price with minimize strategy', () => {
  408. const reservedEvents = undefined;
  409. const currentPrice = 33.0;
  410. const buckets = [
  411. makeBucket({price: 29}), // next lowest
  412. makeBucket({price: 39}),
  413. makeBucket({price: 49}),
  414. ];
  415. const slot = getSlot(reservedEvents, currentPrice, buckets, true);
  416. expect(slot).toBe(0);
  417. });
  418. it('should not overflow the known slot indexes', () => {
  419. const reservedEvents = 110_000;
  420. const currentPrice = undefined;
  421. const buckets = [
  422. makeBucket({events: 50_000}),
  423. makeBucket({events: 100_000}), // highest available plan, lower than our reservation
  424. ];
  425. const slot = getSlot(reservedEvents, currentPrice, buckets);
  426. const expectedSlot = 1;
  427. expect(slot).toBe(expectedSlot);
  428. expect(buckets.length).toBeGreaterThan(expectedSlot);
  429. });
  430. it('should not overflow the known slot indexes when the best option is less than our reservation', () => {
  431. const reservedEvents = 110_000;
  432. const currentPrice = undefined;
  433. const buckets = [
  434. makeBucket({events: 50_000}), // highest available plan, lower than our reservation
  435. ];
  436. const slot = getSlot(reservedEvents, currentPrice, buckets);
  437. const expectedSlot = 0;
  438. expect(slot).toBe(expectedSlot);
  439. expect(buckets.length).toBeGreaterThan(expectedSlot);
  440. });
  441. it('should not overflow the known slot indexes when the best option is more than current reservation', () => {
  442. const reservedEvents = 30_000;
  443. const currentPrice = undefined;
  444. const buckets = [
  445. makeBucket({events: 50_000}), // highest available plan, higher than our reservation
  446. ];
  447. const slot = getSlot(reservedEvents, currentPrice, buckets);
  448. const expectedSlot = 0;
  449. expect(slot).toBe(expectedSlot);
  450. expect(buckets.length).toBeGreaterThan(expectedSlot);
  451. });
  452. it('should not return a negative index with minimize strategy', () => {
  453. const reservedEvents = 40_000;
  454. const currentPrice = undefined;
  455. const buckets = [
  456. makeBucket({events: 50_000}),
  457. makeBucket({events: 100_000}), // highest available plan, lower than our reservation
  458. ];
  459. const slot = getSlot(reservedEvents, currentPrice, buckets, true);
  460. const expectedSlot = 0;
  461. expect(slot).toBe(expectedSlot);
  462. expect(buckets.length).toBeGreaterThan(expectedSlot);
  463. });
  464. });
  465. describe('Pricing plan functions', function () {
  466. const organization = OrganizationFixture();
  467. const am1Team = SubscriptionFixture({organization, plan: 'am1_team'});
  468. const mm2Team = SubscriptionFixture({organization, plan: 'mm2_b_100k'});
  469. const am1Biz = SubscriptionFixture({organization, plan: 'am1_business'});
  470. const am2Biz = SubscriptionFixture({organization, plan: 'am2_business'});
  471. const mm2Biz = SubscriptionFixture({organization, plan: 'mm2_a_100k'});
  472. const am2Dev = SubscriptionFixture({organization, plan: 'am2_f'});
  473. const am3Dev = SubscriptionFixture({organization, plan: 'am3_f'});
  474. const am3Biz = SubscriptionFixture({organization, plan: 'am3_business'});
  475. it('returns if a plan has performance', function () {
  476. expect(hasPerformance(mm2Biz.planDetails)).toBe(false);
  477. expect(hasPerformance(mm2Team.planDetails)).toBe(false);
  478. expect(hasPerformance(am1Biz.planDetails)).toBe(true);
  479. expect(hasPerformance(am1Team.planDetails)).toBe(true);
  480. expect(hasPerformance(am3Dev.planDetails)).toBe(true);
  481. expect(hasPerformance(am3Biz.planDetails)).toBe(true);
  482. });
  483. it('returns correct plan family', function () {
  484. expect(isTeamPlanFamily(am1Team.planDetails)).toBe(true);
  485. expect(isTeamPlanFamily(mm2Team.planDetails)).toBe(true);
  486. expect(isTeamPlanFamily(am1Biz.planDetails)).toBe(false);
  487. expect(isTeamPlanFamily(mm2Biz.planDetails)).toBe(false);
  488. expect(isBizPlanFamily(am1Team.planDetails)).toBe(false);
  489. expect(isBizPlanFamily(mm2Team.planDetails)).toBe(false);
  490. expect(isBizPlanFamily(am1Biz.planDetails)).toBe(true);
  491. expect(isBizPlanFamily(mm2Biz.planDetails)).toBe(true);
  492. expect(isDeveloperPlan(am2Dev.planDetails)).toBe(true);
  493. expect(isDeveloperPlan(am2Biz.planDetails)).toBe(false);
  494. expect(isDeveloperPlan(am1Biz.planDetails)).toBe(false);
  495. expect(isDeveloperPlan(am1Team.planDetails)).toBe(false);
  496. expect(isDeveloperPlan(mm2Biz.planDetails)).toBe(false);
  497. });
  498. });
  499. describe('getProductTrial', function () {
  500. const TEST_TRIALS: ProductTrial[] = [
  501. // errors - with active trials
  502. {
  503. category: DataCategory.ERRORS,
  504. isStarted: true,
  505. reasonCode: 1001,
  506. startDate: moment().utc().subtract(10, 'days').format(),
  507. endDate: moment().utc().add(20, 'days').format(),
  508. },
  509. {
  510. category: DataCategory.ERRORS,
  511. isStarted: true,
  512. reasonCode: 1002,
  513. startDate: moment().utc().subtract(10, 'days').format(),
  514. endDate: moment().utc().add(5, 'days').format(),
  515. },
  516. {
  517. category: DataCategory.ERRORS,
  518. isStarted: true,
  519. reasonCode: 1003,
  520. startDate: moment().utc().subtract(20, 'days').format(),
  521. endDate: moment().utc().subtract(5, 'days').format(),
  522. },
  523. {
  524. category: DataCategory.ERRORS,
  525. isStarted: false,
  526. reasonCode: 1004,
  527. endDate: moment().utc().add(90, 'days').format(),
  528. lengthDays: 14,
  529. },
  530. // transactions - with available trials not started
  531. {
  532. category: DataCategory.TRANSACTIONS,
  533. isStarted: false,
  534. reasonCode: 2001,
  535. endDate: moment().utc().add(20, 'days').format(),
  536. lengthDays: 7,
  537. },
  538. {
  539. category: DataCategory.TRANSACTIONS,
  540. isStarted: false,
  541. reasonCode: 2002,
  542. endDate: moment().utc().add(5, 'days').format(),
  543. lengthDays: 14,
  544. },
  545. {
  546. category: DataCategory.TRANSACTIONS,
  547. isStarted: false,
  548. reasonCode: 2003,
  549. startDate: moment().utc().subtract(20, 'days').format(),
  550. endDate: moment().utc().subtract(5, 'days').format(),
  551. },
  552. {
  553. category: DataCategory.TRANSACTIONS,
  554. isStarted: true,
  555. reasonCode: 2004,
  556. startDate: moment().utc().subtract(21, 'days').format(),
  557. endDate: moment().utc().subtract(7, 'days').format(),
  558. lengthDays: 14,
  559. },
  560. // replays - only expired trials
  561. {
  562. category: DataCategory.REPLAYS,
  563. isStarted: false,
  564. reasonCode: 3001,
  565. startDate: moment().utc().subtract(42, 'days').format(),
  566. endDate: moment().utc().subtract(27, 'days').format(),
  567. },
  568. {
  569. category: DataCategory.REPLAYS,
  570. isStarted: false,
  571. reasonCode: 3002,
  572. startDate: moment().utc().subtract(15, 'days').format(),
  573. endDate: moment().utc().subtract(1, 'days').format(),
  574. },
  575. {
  576. category: DataCategory.REPLAYS,
  577. isStarted: false,
  578. reasonCode: 3003,
  579. startDate: moment().utc().subtract(70, 'days').format(),
  580. endDate: moment().utc().subtract(56, 'days').format(),
  581. },
  582. ];
  583. it('returns current trial with latest end date', function () {
  584. const pt = getProductTrial(TEST_TRIALS, DataCategory.ERRORS);
  585. expect(pt?.reasonCode).toBe(1001);
  586. });
  587. it('returns available trial with longest days', function () {
  588. const pt = getProductTrial(TEST_TRIALS, DataCategory.TRANSACTIONS);
  589. expect(pt?.reasonCode).toBe(2002);
  590. });
  591. it('returns most recent ended trial', function () {
  592. const pt = getProductTrial(TEST_TRIALS, DataCategory.REPLAYS);
  593. expect(pt?.reasonCode).toBe(3002);
  594. });
  595. it('returns null trial when not available', function () {
  596. const pt = getProductTrial(TEST_TRIALS, DataCategory.ATTACHMENTS);
  597. expect(pt).toBeNull();
  598. });
  599. it('returns null trial when empty', function () {
  600. const pt = getProductTrial([], DataCategory.ATTACHMENTS);
  601. expect(pt).toBeNull();
  602. });
  603. it('returns null trial for null trials', function () {
  604. const pt = getProductTrial(null, DataCategory.ATTACHMENTS);
  605. expect(pt).toBeNull();
  606. });
  607. it('tests for trialPromptIsDismissed', function () {
  608. const organization = OrganizationFixture();
  609. const jan01 = '2023-01-01';
  610. const feb01 = '2023-02-01';
  611. const mar01 = '2023-03-01';
  612. const dateDismissed = '2023-01-15';
  613. const isDismissedNoDate = trialPromptIsDismissed(
  614. {},
  615. SubscriptionFixture({organization, plan: 'am1_team', onDemandPeriodStart: jan01})
  616. );
  617. expect(isDismissedNoDate).toBe(false);
  618. const isDismissedInJan = trialPromptIsDismissed(
  619. {snoozedTime: new Date(dateDismissed).getTime() / 1000},
  620. SubscriptionFixture({organization, plan: 'am1_team', onDemandPeriodStart: jan01})
  621. );
  622. expect(isDismissedInJan).toBe(true);
  623. const isDismissedInFeb = trialPromptIsDismissed(
  624. {snoozedTime: new Date(dateDismissed).getTime() / 1000},
  625. SubscriptionFixture({organization, plan: 'am1_team', onDemandPeriodStart: feb01})
  626. );
  627. expect(isDismissedInFeb).toBe(false);
  628. const isDismissedInMar = trialPromptIsDismissed(
  629. {dismissedTime: new Date(dateDismissed).getTime() / 1000},
  630. SubscriptionFixture({organization, plan: 'am1_team', onDemandPeriodStart: mar01})
  631. );
  632. expect(isDismissedInMar).toBe(false);
  633. });
  634. });
  635. describe('getActiveProductTrial', function () {
  636. const TEST_TRIALS: ProductTrial[] = [
  637. // errors - with active trials
  638. {
  639. category: DataCategory.ERRORS,
  640. isStarted: true,
  641. reasonCode: 1001,
  642. startDate: moment().utc().subtract(10, 'days').format(),
  643. endDate: moment().utc().add(20, 'days').format(),
  644. },
  645. {
  646. category: DataCategory.ERRORS,
  647. isStarted: true,
  648. reasonCode: 1002,
  649. startDate: moment().utc().subtract(10, 'days').format(),
  650. endDate: moment().utc().add(5, 'days').format(),
  651. },
  652. {
  653. category: DataCategory.ERRORS,
  654. isStarted: true,
  655. reasonCode: 1003,
  656. startDate: moment().utc().subtract(20, 'days').format(),
  657. endDate: moment().utc().subtract(5, 'days').format(),
  658. },
  659. {
  660. category: DataCategory.ERRORS,
  661. isStarted: false,
  662. reasonCode: 1004,
  663. endDate: moment().utc().add(90, 'days').format(),
  664. lengthDays: 14,
  665. },
  666. // transactions - with available trials not started
  667. {
  668. category: DataCategory.TRANSACTIONS,
  669. isStarted: false,
  670. reasonCode: 2001,
  671. endDate: moment().utc().add(20, 'days').format(),
  672. lengthDays: 7,
  673. },
  674. {
  675. category: DataCategory.TRANSACTIONS,
  676. isStarted: false,
  677. reasonCode: 2002,
  678. endDate: moment().utc().add(5, 'days').format(),
  679. lengthDays: 14,
  680. },
  681. {
  682. category: DataCategory.TRANSACTIONS,
  683. isStarted: false,
  684. reasonCode: 2003,
  685. startDate: moment().utc().subtract(20, 'days').format(),
  686. endDate: moment().utc().subtract(5, 'days').format(),
  687. },
  688. {
  689. category: DataCategory.TRANSACTIONS,
  690. isStarted: true,
  691. reasonCode: 2004,
  692. startDate: moment().utc().subtract(21, 'days').format(),
  693. endDate: moment().utc().subtract(7, 'days').format(),
  694. lengthDays: 14,
  695. },
  696. // replays - only expired trials
  697. {
  698. category: DataCategory.REPLAYS,
  699. isStarted: false,
  700. reasonCode: 3001,
  701. startDate: moment().utc().subtract(42, 'days').format(),
  702. endDate: moment().utc().subtract(27, 'days').format(),
  703. },
  704. {
  705. category: DataCategory.REPLAYS,
  706. isStarted: false,
  707. reasonCode: 3002,
  708. startDate: moment().utc().subtract(15, 'days').format(),
  709. endDate: moment().utc().subtract(1, 'days').format(),
  710. },
  711. {
  712. category: DataCategory.REPLAYS,
  713. isStarted: false,
  714. reasonCode: 3003,
  715. startDate: moment().utc().subtract(70, 'days').format(),
  716. endDate: moment().utc().subtract(56, 'days').format(),
  717. },
  718. ];
  719. it('returns current trial with latest end date for category', function () {
  720. const pt = getActiveProductTrial(TEST_TRIALS, DataCategory.ERRORS);
  721. expect(pt?.reasonCode).toBe(1001);
  722. });
  723. it('returns null when no active trial for the category', function () {
  724. // none started
  725. const transaction_pt = getActiveProductTrial(TEST_TRIALS, DataCategory.TRANSACTIONS);
  726. expect(transaction_pt).toBeNull();
  727. // all expired
  728. const replay_pt = getActiveProductTrial(TEST_TRIALS, DataCategory.REPLAYS);
  729. expect(replay_pt).toBeNull();
  730. });
  731. it('returns null trial when no trials for category', function () {
  732. const pt = getProductTrial(TEST_TRIALS, DataCategory.ATTACHMENTS);
  733. expect(pt).toBeNull();
  734. });
  735. it('returns null trial when empty', function () {
  736. const pt = getProductTrial([], DataCategory.ERRORS);
  737. expect(pt).toBeNull();
  738. });
  739. it('returns null trial for null trials', function () {
  740. const pt = getProductTrial(null, DataCategory.ERRORS);
  741. expect(pt).toBeNull();
  742. });
  743. });