123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813 |
- import moment from 'moment-timezone';
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
- import {DataCategory} from 'sentry/types/core';
- import {BILLION, GIGABYTE, MILLION, UNLIMITED} from 'getsentry/constants';
- import type {ProductTrial} from 'getsentry/types';
- import {
- formatReservedWithUnits,
- formatUsageWithUnits,
- getActiveProductTrial,
- getProductTrial,
- getSlot,
- hasPerformance,
- isBizPlanFamily,
- isDeveloperPlan,
- isTeamPlanFamily,
- MILLISECONDS_IN_HOUR,
- trialPromptIsDismissed,
- } from 'getsentry/utils/billing';
- describe('formatReservedWithUnits', function () {
- it('returns correct string for Errors', function () {
- expect(formatReservedWithUnits(null, DataCategory.ERRORS)).toBe('0');
- expect(formatReservedWithUnits(0, DataCategory.ERRORS)).toBe('0');
- expect(formatReservedWithUnits(-1, DataCategory.ERRORS)).toBe(UNLIMITED);
- expect(formatReservedWithUnits(1, DataCategory.ERRORS)).toBe('1');
- expect(formatReservedWithUnits(1000, DataCategory.ERRORS)).toBe('1,000');
- expect(formatReservedWithUnits(MILLION, DataCategory.ERRORS)).toBe('1,000,000');
- expect(formatReservedWithUnits(BILLION, DataCategory.ERRORS)).toBe('1,000,000,000');
- expect(
- formatReservedWithUnits(1234, DataCategory.ERRORS, {
- isAbbreviated: true,
- })
- ).toBe('1K');
- expect(
- formatReservedWithUnits(MILLION, DataCategory.ERRORS, {
- isAbbreviated: true,
- })
- ).toBe('1M');
- expect(
- formatReservedWithUnits(1.234 * MILLION, DataCategory.ERRORS, {
- isAbbreviated: true,
- })
- ).toBe('1.2M');
- expect(
- formatReservedWithUnits(BILLION, DataCategory.ERRORS, {
- isAbbreviated: true,
- })
- ).toBe('1B');
- expect(
- formatReservedWithUnits(1.234 * BILLION, DataCategory.ERRORS, {
- isAbbreviated: true,
- })
- ).toBe('1.23B');
- });
- it('returns correct string for Transactions', function () {
- expect(formatReservedWithUnits(null, DataCategory.TRANSACTIONS)).toBe('0');
- expect(formatReservedWithUnits(0, DataCategory.TRANSACTIONS)).toBe('0');
- expect(formatReservedWithUnits(-1, DataCategory.TRANSACTIONS)).toBe(UNLIMITED);
- expect(formatReservedWithUnits(1, DataCategory.TRANSACTIONS)).toBe('1');
- expect(formatReservedWithUnits(1000, DataCategory.TRANSACTIONS)).toBe('1,000');
- expect(formatReservedWithUnits(MILLION, DataCategory.TRANSACTIONS)).toBe('1,000,000');
- expect(formatReservedWithUnits(BILLION, DataCategory.TRANSACTIONS)).toBe(
- '1,000,000,000'
- );
- expect(
- formatReservedWithUnits(1234, DataCategory.TRANSACTIONS, {
- isAbbreviated: true,
- })
- ).toBe('1K');
- expect(
- formatReservedWithUnits(MILLION, DataCategory.TRANSACTIONS, {
- isAbbreviated: true,
- })
- ).toBe('1M');
- expect(
- formatReservedWithUnits(1.234 * MILLION, DataCategory.TRANSACTIONS, {
- isAbbreviated: true,
- })
- ).toBe('1.2M');
- expect(
- formatReservedWithUnits(BILLION, DataCategory.TRANSACTIONS, {
- isAbbreviated: true,
- })
- ).toBe('1B');
- expect(
- formatReservedWithUnits(1.234 * BILLION, DataCategory.TRANSACTIONS, {
- isAbbreviated: true,
- })
- ).toBe('1.23B');
- });
- it('returns correct string for Attachments', function () {
- expect(formatReservedWithUnits(null, DataCategory.ATTACHMENTS)).toBe('0 GB');
- expect(formatReservedWithUnits(0, DataCategory.ATTACHMENTS)).toBe('0 GB');
- expect(formatReservedWithUnits(0.1, DataCategory.ATTACHMENTS)).toBe('0.1 GB');
- expect(formatReservedWithUnits(1, DataCategory.ATTACHMENTS)).toBe('1 GB');
- expect(formatReservedWithUnits(1000, DataCategory.ATTACHMENTS)).toBe('1,000 GB');
- expect(formatReservedWithUnits(MILLION, DataCategory.ATTACHMENTS)).toBe(
- '1,000,000 GB'
- );
- expect(formatReservedWithUnits(BILLION, DataCategory.ATTACHMENTS)).toBe(
- '1,000,000,000 GB'
- );
- expect(
- formatReservedWithUnits(0.1234, DataCategory.ATTACHMENTS, {
- isAbbreviated: true,
- })
- ).toBe('0 GB');
- expect(
- formatReservedWithUnits(1.234, DataCategory.ATTACHMENTS, {
- isAbbreviated: true,
- })
- ).toBe('1 GB');
- expect(
- formatReservedWithUnits(1234, DataCategory.ATTACHMENTS, {
- isAbbreviated: true,
- })
- ).toBe('1K GB');
- expect(
- formatReservedWithUnits(MILLION, DataCategory.ATTACHMENTS, {
- isAbbreviated: true,
- })
- ).toBe('1M GB');
- expect(
- formatReservedWithUnits(1.234 * MILLION, DataCategory.ATTACHMENTS, {
- isAbbreviated: true,
- })
- ).toBe('1.2M GB');
- expect(
- formatReservedWithUnits(BILLION, DataCategory.ATTACHMENTS, {
- isAbbreviated: true,
- })
- ).toBe('1B GB');
- expect(
- formatReservedWithUnits(1.234 * BILLION, DataCategory.ATTACHMENTS, {
- isAbbreviated: true,
- })
- ).toBe('1.23B GB');
- expect(
- formatReservedWithUnits(0.1, DataCategory.ATTACHMENTS, {
- useUnitScaling: true,
- })
- ).toBe('0.1 GB');
- expect(
- formatReservedWithUnits(1, DataCategory.ATTACHMENTS, {
- useUnitScaling: true,
- })
- ).toBe('1 GB');
- expect(
- formatReservedWithUnits(1000, DataCategory.ATTACHMENTS, {
- useUnitScaling: true,
- })
- ).toBe('1 TB');
- expect(
- formatReservedWithUnits(1234, DataCategory.ATTACHMENTS, {
- useUnitScaling: true,
- })
- ).toBe('1.23 TB');
- expect(
- formatReservedWithUnits(1234 * BILLION, DataCategory.ATTACHMENTS, {
- useUnitScaling: true,
- })
- ).toBe('1.23 ZB');
- expect(
- formatReservedWithUnits(-1 / GIGABYTE, DataCategory.ATTACHMENTS, {
- useUnitScaling: true,
- })
- ).toBe(UNLIMITED);
- });
- it('returns correct string for Profile Duration', function () {
- expect(formatReservedWithUnits(1000, DataCategory.PROFILE_DURATION)).toBe('1,000');
- expect(formatReservedWithUnits(0, DataCategory.PROFILE_DURATION)).toBe('0');
- expect(formatReservedWithUnits(-1, DataCategory.PROFILE_DURATION)).toBe(UNLIMITED);
- expect(formatReservedWithUnits(500, DataCategory.PROFILE_DURATION)).toBe('500');
- expect(
- formatReservedWithUnits(1000, DataCategory.PROFILE_DURATION, {
- isAbbreviated: true,
- })
- ).toBe('1K');
- });
- it('returns correct string for reserved budget', function () {
- expect(formatReservedWithUnits(1000, DataCategory.SPANS, {}, true)).toBe('$10.00');
- expect(formatReservedWithUnits(1500_00, DataCategory.SPANS, {}, true)).toBe(
- '$1,500.00'
- );
- expect(formatReservedWithUnits(0, DataCategory.SPANS, {}, true)).toBe('$0.00');
- });
- });
- describe('formatUsageWithUnits', function () {
- it('returns correct strings for Errors', function () {
- expect(formatUsageWithUnits(0, DataCategory.ERRORS)).toBe('0');
- expect(formatUsageWithUnits(1000, DataCategory.ERRORS)).toBe('1,000');
- expect(formatUsageWithUnits(MILLION, DataCategory.ERRORS)).toBe('1,000,000');
- expect(formatUsageWithUnits(BILLION, DataCategory.ERRORS)).toBe('1,000,000,000');
- expect(formatUsageWithUnits(0, DataCategory.ERRORS, {isAbbreviated: true})).toBe('0');
- expect(formatUsageWithUnits(1000, DataCategory.ERRORS, {isAbbreviated: true})).toBe(
- '1K'
- );
- expect(
- formatUsageWithUnits(MILLION, DataCategory.ERRORS, {isAbbreviated: true})
- ).toBe('1M');
- expect(
- formatUsageWithUnits(1.234 * MILLION, DataCategory.ERRORS, {
- isAbbreviated: true,
- })
- ).toBe('1.2M');
- expect(
- formatUsageWithUnits(1.234 * BILLION, DataCategory.ERRORS, {
- isAbbreviated: true,
- })
- ).toBe('1.23B');
- });
- it('returns correct strings for Transactions', function () {
- expect(formatUsageWithUnits(0, DataCategory.TRANSACTIONS)).toBe('0');
- expect(formatUsageWithUnits(1000, DataCategory.TRANSACTIONS)).toBe('1,000');
- expect(formatUsageWithUnits(MILLION, DataCategory.TRANSACTIONS)).toBe('1,000,000');
- expect(formatUsageWithUnits(BILLION, DataCategory.TRANSACTIONS)).toBe(
- '1,000,000,000'
- );
- expect(
- formatUsageWithUnits(0, DataCategory.TRANSACTIONS, {isAbbreviated: true})
- ).toBe('0');
- expect(
- formatUsageWithUnits(1000, DataCategory.TRANSACTIONS, {isAbbreviated: true})
- ).toBe('1K');
- expect(
- formatUsageWithUnits(MILLION, DataCategory.TRANSACTIONS, {isAbbreviated: true})
- ).toBe('1M');
- expect(
- formatUsageWithUnits(1.234 * MILLION, DataCategory.TRANSACTIONS, {
- isAbbreviated: true,
- })
- ).toBe('1.2M');
- expect(
- formatUsageWithUnits(1.234 * BILLION, DataCategory.TRANSACTIONS, {
- isAbbreviated: true,
- })
- ).toBe('1.23B');
- });
- it('returns correct strings for Attachments', function () {
- expect(formatUsageWithUnits(0, DataCategory.ATTACHMENTS)).toBe('0 GB');
- expect(formatUsageWithUnits(MILLION, DataCategory.ATTACHMENTS)).toBe('0 GB');
- expect(formatUsageWithUnits(BILLION, DataCategory.ATTACHMENTS)).toBe('1 GB');
- expect(formatUsageWithUnits(1.234 * BILLION, DataCategory.ATTACHMENTS)).toBe(
- '1.23 GB'
- );
- expect(formatUsageWithUnits(1234 * GIGABYTE, DataCategory.ATTACHMENTS)).toBe(
- '1,234 GB'
- );
- expect(formatUsageWithUnits(0, DataCategory.ATTACHMENTS, {isAbbreviated: true})).toBe(
- '0 GB'
- );
- expect(
- formatUsageWithUnits(MILLION, DataCategory.ATTACHMENTS, {isAbbreviated: true})
- ).toBe('0 GB');
- expect(
- formatUsageWithUnits(BILLION, DataCategory.ATTACHMENTS, {isAbbreviated: true})
- ).toBe('1 GB');
- expect(
- formatUsageWithUnits(1.234 * BILLION, DataCategory.ATTACHMENTS, {
- isAbbreviated: true,
- })
- ).toBe('1 GB');
- expect(
- formatUsageWithUnits(1234 * BILLION, DataCategory.ATTACHMENTS, {
- isAbbreviated: true,
- })
- ).toBe('1K GB');
- expect(
- formatUsageWithUnits(0, DataCategory.ATTACHMENTS, {
- useUnitScaling: true,
- })
- ).toBe('0 B');
- expect(
- formatUsageWithUnits(1000, DataCategory.ATTACHMENTS, {
- useUnitScaling: true,
- })
- ).toBe('1 KB');
- expect(
- formatUsageWithUnits(MILLION, DataCategory.ATTACHMENTS, {
- useUnitScaling: true,
- })
- ).toBe('1 MB');
- expect(
- formatUsageWithUnits(1.234 * MILLION, DataCategory.ATTACHMENTS, {
- useUnitScaling: true,
- })
- ).toBe('1.23 MB');
- expect(
- formatUsageWithUnits(1.234 * BILLION, DataCategory.ATTACHMENTS, {
- useUnitScaling: true,
- })
- ).toBe('1.23 GB');
- expect(
- formatUsageWithUnits(1234 * BILLION, DataCategory.ATTACHMENTS, {
- useUnitScaling: true,
- })
- ).toBe('1.23 TB');
- });
- it('returns correct string for Profile Duration', function () {
- expect(formatUsageWithUnits(0, DataCategory.PROFILE_DURATION)).toBe('0');
- expect(formatUsageWithUnits(1, DataCategory.PROFILE_DURATION)).toBe('0');
- expect(formatUsageWithUnits(360000, DataCategory.PROFILE_DURATION)).toBe('0.1');
- expect(
- formatUsageWithUnits(MILLISECONDS_IN_HOUR, DataCategory.PROFILE_DURATION)
- ).toBe('1');
- expect(
- formatUsageWithUnits(5.23 * MILLISECONDS_IN_HOUR, DataCategory.PROFILE_DURATION)
- ).toBe('5.2');
- expect(
- formatUsageWithUnits(1000 * MILLISECONDS_IN_HOUR, DataCategory.PROFILE_DURATION)
- ).toBe('1,000');
- expect(
- formatUsageWithUnits(1000 * MILLISECONDS_IN_HOUR, DataCategory.PROFILE_DURATION, {
- isAbbreviated: true,
- })
- ).toBe('1K');
- });
- });
- describe('getSlot', () => {
- function makeBucket(props: {events?: number; price?: number}) {
- return {
- events: 0,
- min: 0,
- onDemandPrice: 0,
- price: 0,
- unitPrice: 0,
- ...props,
- };
- }
- it('should return slot zero when no slots are passed', () => {
- const reservedEvents = 0;
- const currentPrice = 0;
- const slot = getSlot(reservedEvents, currentPrice, []);
- expect(slot).toBe(0);
- });
- it('should return slot zero when no price is passed', () => {
- const reservedEvents = undefined;
- const currentPrice = 0;
- const slot = getSlot(reservedEvents, currentPrice, []);
- expect(slot).toBe(0);
- });
- it('should return slot zero when no events is passed', () => {
- const reservedEvents = 0;
- const currentPrice = undefined;
- const slot = getSlot(reservedEvents, currentPrice, []);
- expect(slot).toBe(0);
- });
- it('should return the slot index which matches the current reserved events', () => {
- const reservedEvents = 100_000;
- const currentPrice = undefined;
- const buckets = [
- makeBucket({events: 50_000}),
- makeBucket({events: 100_000}), // matches the current reservation
- makeBucket({events: 200_000}),
- ];
- const slot = getSlot(reservedEvents, currentPrice, buckets);
- expect(slot).toBe(1);
- const slotWithMinimize = getSlot(reservedEvents, currentPrice, buckets, true);
- expect(slotWithMinimize).toBe(1);
- });
- it('should return the slot index which matches the current price', () => {
- const reservedEvents = undefined;
- const currentPrice = 29.0;
- const buckets = [
- makeBucket({price: 29}), // matches the current price
- makeBucket({price: 39}),
- makeBucket({price: 49}),
- ];
- const slot = getSlot(reservedEvents, currentPrice, buckets);
- expect(slot).toBe(0);
- const slotWithMinimize = getSlot(reservedEvents, currentPrice, buckets, true);
- expect(slotWithMinimize).toBe(0);
- });
- it('should return the slot index that is above the current reserved events', () => {
- const reservedEvents = 110_000;
- const currentPrice = undefined;
- const buckets = [
- makeBucket({events: 50_000}),
- makeBucket({events: 100_000}),
- makeBucket({events: 200_000}), // next highest
- ];
- const slot = getSlot(reservedEvents, currentPrice, buckets);
- expect(slot).toBe(2);
- });
- it('should return the slot index that is below the current reserved events with minimize strategy', () => {
- const reservedEvents = 110_000;
- const currentPrice = undefined;
- const buckets = [
- makeBucket({events: 50_000}),
- makeBucket({events: 100_000}), // next lowest
- makeBucket({events: 200_000}),
- ];
- const slot = getSlot(reservedEvents, currentPrice, buckets, true);
- expect(slot).toBe(1);
- });
- it('should return the slot index that is above the current price', () => {
- const reservedEvents = undefined;
- const currentPrice = 33.0;
- const buckets = [
- makeBucket({price: 29}),
- makeBucket({price: 39}), // next highest
- makeBucket({price: 49}),
- ];
- const slot = getSlot(reservedEvents, currentPrice, buckets);
- expect(slot).toBe(1);
- });
- it('should return the slot index that is below the current price with minimize strategy', () => {
- const reservedEvents = undefined;
- const currentPrice = 33.0;
- const buckets = [
- makeBucket({price: 29}), // next lowest
- makeBucket({price: 39}),
- makeBucket({price: 49}),
- ];
- const slot = getSlot(reservedEvents, currentPrice, buckets, true);
- expect(slot).toBe(0);
- });
- it('should not overflow the known slot indexes', () => {
- const reservedEvents = 110_000;
- const currentPrice = undefined;
- const buckets = [
- makeBucket({events: 50_000}),
- makeBucket({events: 100_000}), // highest available plan, lower than our reservation
- ];
- const slot = getSlot(reservedEvents, currentPrice, buckets);
- const expectedSlot = 1;
- expect(slot).toBe(expectedSlot);
- expect(buckets.length).toBeGreaterThan(expectedSlot);
- });
- it('should not overflow the known slot indexes when the best option is less than our reservation', () => {
- const reservedEvents = 110_000;
- const currentPrice = undefined;
- const buckets = [
- makeBucket({events: 50_000}), // highest available plan, lower than our reservation
- ];
- const slot = getSlot(reservedEvents, currentPrice, buckets);
- const expectedSlot = 0;
- expect(slot).toBe(expectedSlot);
- expect(buckets.length).toBeGreaterThan(expectedSlot);
- });
- it('should not overflow the known slot indexes when the best option is more than current reservation', () => {
- const reservedEvents = 30_000;
- const currentPrice = undefined;
- const buckets = [
- makeBucket({events: 50_000}), // highest available plan, higher than our reservation
- ];
- const slot = getSlot(reservedEvents, currentPrice, buckets);
- const expectedSlot = 0;
- expect(slot).toBe(expectedSlot);
- expect(buckets.length).toBeGreaterThan(expectedSlot);
- });
- it('should not return a negative index with minimize strategy', () => {
- const reservedEvents = 40_000;
- const currentPrice = undefined;
- const buckets = [
- makeBucket({events: 50_000}),
- makeBucket({events: 100_000}), // highest available plan, lower than our reservation
- ];
- const slot = getSlot(reservedEvents, currentPrice, buckets, true);
- const expectedSlot = 0;
- expect(slot).toBe(expectedSlot);
- expect(buckets.length).toBeGreaterThan(expectedSlot);
- });
- });
- describe('Pricing plan functions', function () {
- const organization = OrganizationFixture();
- const am1Team = SubscriptionFixture({organization, plan: 'am1_team'});
- const mm2Team = SubscriptionFixture({organization, plan: 'mm2_b_100k'});
- const am1Biz = SubscriptionFixture({organization, plan: 'am1_business'});
- const am2Biz = SubscriptionFixture({organization, plan: 'am2_business'});
- const mm2Biz = SubscriptionFixture({organization, plan: 'mm2_a_100k'});
- const am2Dev = SubscriptionFixture({organization, plan: 'am2_f'});
- const am3Dev = SubscriptionFixture({organization, plan: 'am3_f'});
- const am3Biz = SubscriptionFixture({organization, plan: 'am3_business'});
- it('returns if a plan has performance', function () {
- expect(hasPerformance(mm2Biz.planDetails)).toBe(false);
- expect(hasPerformance(mm2Team.planDetails)).toBe(false);
- expect(hasPerformance(am1Biz.planDetails)).toBe(true);
- expect(hasPerformance(am1Team.planDetails)).toBe(true);
- expect(hasPerformance(am3Dev.planDetails)).toBe(true);
- expect(hasPerformance(am3Biz.planDetails)).toBe(true);
- });
- it('returns correct plan family', function () {
- expect(isTeamPlanFamily(am1Team.planDetails)).toBe(true);
- expect(isTeamPlanFamily(mm2Team.planDetails)).toBe(true);
- expect(isTeamPlanFamily(am1Biz.planDetails)).toBe(false);
- expect(isTeamPlanFamily(mm2Biz.planDetails)).toBe(false);
- expect(isBizPlanFamily(am1Team.planDetails)).toBe(false);
- expect(isBizPlanFamily(mm2Team.planDetails)).toBe(false);
- expect(isBizPlanFamily(am1Biz.planDetails)).toBe(true);
- expect(isBizPlanFamily(mm2Biz.planDetails)).toBe(true);
- expect(isDeveloperPlan(am2Dev.planDetails)).toBe(true);
- expect(isDeveloperPlan(am2Biz.planDetails)).toBe(false);
- expect(isDeveloperPlan(am1Biz.planDetails)).toBe(false);
- expect(isDeveloperPlan(am1Team.planDetails)).toBe(false);
- expect(isDeveloperPlan(mm2Biz.planDetails)).toBe(false);
- });
- });
- describe('getProductTrial', function () {
- const TEST_TRIALS: ProductTrial[] = [
- // errors - with active trials
- {
- category: DataCategory.ERRORS,
- isStarted: true,
- reasonCode: 1001,
- startDate: moment().utc().subtract(10, 'days').format(),
- endDate: moment().utc().add(20, 'days').format(),
- },
- {
- category: DataCategory.ERRORS,
- isStarted: true,
- reasonCode: 1002,
- startDate: moment().utc().subtract(10, 'days').format(),
- endDate: moment().utc().add(5, 'days').format(),
- },
- {
- category: DataCategory.ERRORS,
- isStarted: true,
- reasonCode: 1003,
- startDate: moment().utc().subtract(20, 'days').format(),
- endDate: moment().utc().subtract(5, 'days').format(),
- },
- {
- category: DataCategory.ERRORS,
- isStarted: false,
- reasonCode: 1004,
- endDate: moment().utc().add(90, 'days').format(),
- lengthDays: 14,
- },
- // transactions - with available trials not started
- {
- category: DataCategory.TRANSACTIONS,
- isStarted: false,
- reasonCode: 2001,
- endDate: moment().utc().add(20, 'days').format(),
- lengthDays: 7,
- },
- {
- category: DataCategory.TRANSACTIONS,
- isStarted: false,
- reasonCode: 2002,
- endDate: moment().utc().add(5, 'days').format(),
- lengthDays: 14,
- },
- {
- category: DataCategory.TRANSACTIONS,
- isStarted: false,
- reasonCode: 2003,
- startDate: moment().utc().subtract(20, 'days').format(),
- endDate: moment().utc().subtract(5, 'days').format(),
- },
- {
- category: DataCategory.TRANSACTIONS,
- isStarted: true,
- reasonCode: 2004,
- startDate: moment().utc().subtract(21, 'days').format(),
- endDate: moment().utc().subtract(7, 'days').format(),
- lengthDays: 14,
- },
- // replays - only expired trials
- {
- category: DataCategory.REPLAYS,
- isStarted: false,
- reasonCode: 3001,
- startDate: moment().utc().subtract(42, 'days').format(),
- endDate: moment().utc().subtract(27, 'days').format(),
- },
- {
- category: DataCategory.REPLAYS,
- isStarted: false,
- reasonCode: 3002,
- startDate: moment().utc().subtract(15, 'days').format(),
- endDate: moment().utc().subtract(1, 'days').format(),
- },
- {
- category: DataCategory.REPLAYS,
- isStarted: false,
- reasonCode: 3003,
- startDate: moment().utc().subtract(70, 'days').format(),
- endDate: moment().utc().subtract(56, 'days').format(),
- },
- ];
- it('returns current trial with latest end date', function () {
- const pt = getProductTrial(TEST_TRIALS, DataCategory.ERRORS);
- expect(pt?.reasonCode).toBe(1001);
- });
- it('returns available trial with longest days', function () {
- const pt = getProductTrial(TEST_TRIALS, DataCategory.TRANSACTIONS);
- expect(pt?.reasonCode).toBe(2002);
- });
- it('returns most recent ended trial', function () {
- const pt = getProductTrial(TEST_TRIALS, DataCategory.REPLAYS);
- expect(pt?.reasonCode).toBe(3002);
- });
- it('returns null trial when not available', function () {
- const pt = getProductTrial(TEST_TRIALS, DataCategory.ATTACHMENTS);
- expect(pt).toBeNull();
- });
- it('returns null trial when empty', function () {
- const pt = getProductTrial([], DataCategory.ATTACHMENTS);
- expect(pt).toBeNull();
- });
- it('returns null trial for null trials', function () {
- const pt = getProductTrial(null, DataCategory.ATTACHMENTS);
- expect(pt).toBeNull();
- });
- it('tests for trialPromptIsDismissed', function () {
- const organization = OrganizationFixture();
- const jan01 = '2023-01-01';
- const feb01 = '2023-02-01';
- const mar01 = '2023-03-01';
- const dateDismissed = '2023-01-15';
- const isDismissedNoDate = trialPromptIsDismissed(
- {},
- SubscriptionFixture({organization, plan: 'am1_team', onDemandPeriodStart: jan01})
- );
- expect(isDismissedNoDate).toBe(false);
- const isDismissedInJan = trialPromptIsDismissed(
- {snoozedTime: new Date(dateDismissed).getTime() / 1000},
- SubscriptionFixture({organization, plan: 'am1_team', onDemandPeriodStart: jan01})
- );
- expect(isDismissedInJan).toBe(true);
- const isDismissedInFeb = trialPromptIsDismissed(
- {snoozedTime: new Date(dateDismissed).getTime() / 1000},
- SubscriptionFixture({organization, plan: 'am1_team', onDemandPeriodStart: feb01})
- );
- expect(isDismissedInFeb).toBe(false);
- const isDismissedInMar = trialPromptIsDismissed(
- {dismissedTime: new Date(dateDismissed).getTime() / 1000},
- SubscriptionFixture({organization, plan: 'am1_team', onDemandPeriodStart: mar01})
- );
- expect(isDismissedInMar).toBe(false);
- });
- });
- describe('getActiveProductTrial', function () {
- const TEST_TRIALS: ProductTrial[] = [
- // errors - with active trials
- {
- category: DataCategory.ERRORS,
- isStarted: true,
- reasonCode: 1001,
- startDate: moment().utc().subtract(10, 'days').format(),
- endDate: moment().utc().add(20, 'days').format(),
- },
- {
- category: DataCategory.ERRORS,
- isStarted: true,
- reasonCode: 1002,
- startDate: moment().utc().subtract(10, 'days').format(),
- endDate: moment().utc().add(5, 'days').format(),
- },
- {
- category: DataCategory.ERRORS,
- isStarted: true,
- reasonCode: 1003,
- startDate: moment().utc().subtract(20, 'days').format(),
- endDate: moment().utc().subtract(5, 'days').format(),
- },
- {
- category: DataCategory.ERRORS,
- isStarted: false,
- reasonCode: 1004,
- endDate: moment().utc().add(90, 'days').format(),
- lengthDays: 14,
- },
- // transactions - with available trials not started
- {
- category: DataCategory.TRANSACTIONS,
- isStarted: false,
- reasonCode: 2001,
- endDate: moment().utc().add(20, 'days').format(),
- lengthDays: 7,
- },
- {
- category: DataCategory.TRANSACTIONS,
- isStarted: false,
- reasonCode: 2002,
- endDate: moment().utc().add(5, 'days').format(),
- lengthDays: 14,
- },
- {
- category: DataCategory.TRANSACTIONS,
- isStarted: false,
- reasonCode: 2003,
- startDate: moment().utc().subtract(20, 'days').format(),
- endDate: moment().utc().subtract(5, 'days').format(),
- },
- {
- category: DataCategory.TRANSACTIONS,
- isStarted: true,
- reasonCode: 2004,
- startDate: moment().utc().subtract(21, 'days').format(),
- endDate: moment().utc().subtract(7, 'days').format(),
- lengthDays: 14,
- },
- // replays - only expired trials
- {
- category: DataCategory.REPLAYS,
- isStarted: false,
- reasonCode: 3001,
- startDate: moment().utc().subtract(42, 'days').format(),
- endDate: moment().utc().subtract(27, 'days').format(),
- },
- {
- category: DataCategory.REPLAYS,
- isStarted: false,
- reasonCode: 3002,
- startDate: moment().utc().subtract(15, 'days').format(),
- endDate: moment().utc().subtract(1, 'days').format(),
- },
- {
- category: DataCategory.REPLAYS,
- isStarted: false,
- reasonCode: 3003,
- startDate: moment().utc().subtract(70, 'days').format(),
- endDate: moment().utc().subtract(56, 'days').format(),
- },
- ];
- it('returns current trial with latest end date for category', function () {
- const pt = getActiveProductTrial(TEST_TRIALS, DataCategory.ERRORS);
- expect(pt?.reasonCode).toBe(1001);
- });
- it('returns null when no active trial for the category', function () {
- // none started
- const transaction_pt = getActiveProductTrial(TEST_TRIALS, DataCategory.TRANSACTIONS);
- expect(transaction_pt).toBeNull();
- // all expired
- const replay_pt = getActiveProductTrial(TEST_TRIALS, DataCategory.REPLAYS);
- expect(replay_pt).toBeNull();
- });
- it('returns null trial when no trials for category', function () {
- const pt = getProductTrial(TEST_TRIALS, DataCategory.ATTACHMENTS);
- expect(pt).toBeNull();
- });
- it('returns null trial when empty', function () {
- const pt = getProductTrial([], DataCategory.ERRORS);
- expect(pt).toBeNull();
- });
- it('returns null trial for null trials', function () {
- const pt = getProductTrial(null, DataCategory.ERRORS);
- expect(pt).toBeNull();
- });
- });
|