1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134 |
- import moment from 'moment-timezone';
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {MetricHistoryFixture} from 'getsentry-test/fixtures/metricHistory';
- import {
- InvoicedSubscriptionFixture,
- SubscriptionFixture,
- } from 'getsentry-test/fixtures/subscription';
- import {
- act,
- render,
- renderGlobalModal,
- screen,
- userEvent,
- waitFor,
- } from 'sentry-test/reactTestingLibrary';
- import {textWithMarkupMatcher} from 'sentry-test/utils';
- import ConfigStore from 'sentry/stores/configStore';
- import ModalStore from 'sentry/stores/modalStore';
- import {DataCategory} from 'sentry/types/core';
- import {browserHistory} from 'sentry/utils/browserHistory';
- import {PendingChangesFixture} from 'getsentry/__fixtures__/pendingChanges';
- import {PlanFixture} from 'getsentry/__fixtures__/plan';
- import {
- openForcedTrialModal,
- openPartnerPlanEndingModal,
- openTrialEndingModal,
- } from 'getsentry/actionCreators/modal';
- import GSBanner from 'getsentry/components/gsBanner';
- import SubscriptionStore from 'getsentry/stores/subscriptionStore';
- jest.mock('getsentry/actionCreators/modal');
- const guideMock = jest.requireMock('sentry/stores/guideStore');
- jest.mock('sentry/stores/guideStore', () => ({
- state: {},
- }));
- describe('GSBanner', function () {
- beforeEach(() => {
- ModalStore.reset();
- jest.clearAllMocks();
- delete window.pendo;
- MockApiClient.clearMockResponses();
- MockApiClient.addMockResponse({
- method: 'POST',
- url: '/_experiment/log_exposure/',
- body: {},
- });
- MockApiClient.addMockResponse({
- url: `/organizations/org-slug/projects/`,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/org-slug/teams/`,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/subscriptions/org-slug/`,
- body: {},
- });
- MockApiClient.addMockResponse({
- url: `/organizations/org-slug/`,
- body: {},
- });
- [
- 'another-slug-1',
- 'another-slug-2',
- 'another-slug-3',
- 'another-slug-4',
- 'org-slug',
- 'promotion-platform',
- 'forced-trial',
- 'soft-cap',
- 'grace-period',
- 'trial-ending',
- 'partner-plan-ending',
- 'suspended',
- 'exceeded',
- 'past-due',
- 'past-due-2',
- 'past-due-3',
- 'past-due-4',
- ].forEach(slug => {
- SubscriptionStore.set(slug, {});
- MockApiClient.addMockResponse({
- url: `/organizations/${slug}/promotions/trigger-check/`,
- method: 'POST',
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/${slug}/prompts-activity/`,
- body: {},
- });
- });
- });
- it('renders empty', async function () {
- const organization = OrganizationFixture();
- SubscriptionStore.set(organization.slug, {});
- const {container} = render(<GSBanner organization={organization} />, {organization});
- // wait for requests to finish
- await act(tick);
- expect(container).toBeEmptyDOMElement();
- });
- it('shows overage notification banner and request more events btn for members', async function () {
- const organization = OrganizationFixture();
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am2_team',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: false}),
- transactions: MetricHistoryFixture({usageExceeded: true}),
- replays: MetricHistoryFixture({usageExceeded: false}),
- attachments: MetricHistoryFixture({usageExceeded: true}),
- monitorSeats: MetricHistoryFixture({usageExceeded: false}),
- },
- canSelfServe: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByTestId('overage-banner-transaction-attachment')
- ).toBeInTheDocument();
- expect(screen.getByText('performance unit')).toBeInTheDocument();
- expect(screen.queryByText('transaction')).not.toBeInTheDocument();
- expect(screen.getByTestId('btn-request_add_events')).toBeInTheDocument();
- });
- it('shows overage notification banner for multiple categories', async function () {
- const organization = OrganizationFixture();
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_t',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: true}),
- transactions: MetricHistoryFixture({usageExceeded: true}),
- replays: MetricHistoryFixture({usageExceeded: false}),
- attachments: MetricHistoryFixture({usageExceeded: true}),
- monitorSeats: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByTestId('overage-banner-error-transaction-attachment-monitorSeat')
- ).toBeInTheDocument();
- expect(screen.getByText('transaction')).toBeInTheDocument();
- expect(screen.getByText('cron monitor')).toBeInTheDocument();
- expect(screen.queryByText('performance unit')).not.toBeInTheDocument();
- });
- it('does not show overage notification banner if is not self served', async function () {
- const organization = OrganizationFixture();
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_t',
- categories: {attachments: MetricHistoryFixture({usageExceeded: true})},
- canSelfServe: false,
- });
- SubscriptionStore.set(organization.slug, subscription);
- const {container} = render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(container).toBeEmptyDOMElement();
- });
- it('does not show overage notification banner if active product trial', async function () {
- const organization = OrganizationFixture();
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am2_team',
- categories: {replays: MetricHistoryFixture({usageExceeded: true})},
- canSelfServe: true,
- productTrials: [
- {
- category: DataCategory.REPLAYS,
- isStarted: true,
- reasonCode: 1001,
- startDate: moment().utc().subtract(10, 'days').format(),
- endDate: moment().utc().add(20, 'days').format(),
- },
- ],
- });
- SubscriptionStore.set(organization.slug, subscription);
- const {container} = render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(container).toBeEmptyDOMElement();
- });
- it('shows overage notification banner even if other category is on active trial', async function () {
- const organization = OrganizationFixture();
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am2_team',
- categories: {
- attachments: MetricHistoryFixture({usageExceeded: true}),
- replays: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- productTrials: [
- {
- category: DataCategory.REPLAYS,
- isStarted: true,
- reasonCode: 1001,
- startDate: moment().utc().subtract(10, 'days').format(),
- endDate: moment().utc().add(20, 'days').format(),
- },
- ],
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(await screen.findByTestId('overage-banner-attachment')).toBeInTheDocument();
- expect(screen.queryByTestId('overage-banner-replay')).not.toBeInTheDocument();
- });
- it('shows start trial btn for billing admins if can trial', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_f',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: false}),
- transactions: MetricHistoryFixture({usageExceeded: true}),
- attachments: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- canTrial: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByTestId('overage-banner-transaction-attachment')
- ).toBeInTheDocument();
- expect(screen.getByTestId('btn-start_trial')).toBeInTheDocument();
- });
- it('shows upgrade plan btn for free plans for admins', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_f',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: true}),
- transactions: MetricHistoryFixture({usageExceeded: false}),
- attachments: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- canTrial: false,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByTestId('overage-banner-error-attachment')
- ).toBeInTheDocument();
- expect(screen.getByRole('button', {name: /upgrade plan/i})).toBeInTheDocument();
- });
- it('shows add quota btn for paid plans for admins', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: true}),
- transactions: MetricHistoryFixture({usageExceeded: true}),
- replays: MetricHistoryFixture({usageExceeded: true}),
- attachments: MetricHistoryFixture({usageExceeded: true}),
- monitorSeats: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- canTrial: false,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByTestId(
- 'overage-banner-error-transaction-replay-attachment-monitorSeat'
- )
- ).toBeInTheDocument();
- expect(
- screen.getByRole('button', {name: /increase reserved limits/i})
- ).toBeInTheDocument();
- });
- it('shows add quota button for paid plans without active product trial', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am3_team',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: false}),
- spans: MetricHistoryFixture({usageExceeded: true}),
- replays: MetricHistoryFixture({usageExceeded: false}),
- attachments: MetricHistoryFixture({usageExceeded: false}),
- monitorSeats: MetricHistoryFixture({usageExceeded: false}),
- profileDuration: MetricHistoryFixture({usageExceeded: false}),
- },
- canSelfServe: true,
- productTrials: [
- {
- category: 'spans',
- reasonCode: 1001,
- isStarted: false,
- lengthDays: undefined,
- startDate: undefined,
- endDate: undefined,
- },
- ],
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByRole('button', {name: /increase reserved limits/i})
- ).toBeInTheDocument();
- });
- it('does not show add quota button for paid plans with active product trial', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am3_team',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: false}),
- spans: MetricHistoryFixture({usageExceeded: true}),
- replays: MetricHistoryFixture({usageExceeded: false}),
- attachments: MetricHistoryFixture({usageExceeded: false}),
- monitorSeats: MetricHistoryFixture({usageExceeded: false}),
- profileDuration: MetricHistoryFixture({usageExceeded: false}),
- },
- canSelfServe: true,
- productTrials: [
- {
- category: 'spans',
- reasonCode: 1001,
- isStarted: true,
- lengthDays: 20,
- startDate: moment().utc().subtract(10, 'days').format(),
- endDate: moment().utc().add(10, 'days').format(),
- },
- ],
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(
- screen.queryByRole('button', {name: /increase reserved limits/i})
- ).not.toBeInTheDocument();
- });
- it('user can dismiss notification', async function () {
- const organization = OrganizationFixture();
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_t',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: true}),
- transactions: MetricHistoryFixture({usageExceeded: true}),
- replays: MetricHistoryFixture({usageExceeded: true}),
- attachments: MetricHistoryFixture({usageExceeded: true}),
- monitorSeats: MetricHistoryFixture({usageExceeded: true}),
- spans: MetricHistoryFixture({usageExceeded: true}),
- profileDuration: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- const snoozeEndpoint = MockApiClient.addMockResponse({
- method: 'PUT',
- url: `/organizations/${organization.slug}/prompts-activity/`,
- body: {},
- });
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByTestId(
- 'overage-banner-error-transaction-replay-attachment-monitorSeat-span-profileDuration'
- )
- ).toBeInTheDocument();
- expect(screen.getByTestId('btn-overage-notification-snooze')).toBeInTheDocument();
- await userEvent.click(screen.getByTestId('btn-overage-notification-snooze'));
- for (const feature of [
- 'errors_overage_alert',
- 'transactions_overage_alert',
- 'replays_overage_alert',
- 'attachments_overage_alert',
- 'spans_overage_alert',
- 'profile_duration_overage_alert',
- ]) {
- expect(snoozeEndpoint).toHaveBeenCalledWith(
- `/organizations/${organization.slug}/prompts-activity/`,
- expect.objectContaining({
- data: {
- feature,
- organization_id: organization.id,
- status: 'snoozed',
- },
- })
- );
- }
- expect(screen.queryByTestId(/overage-banner/)).not.toBeInTheDocument();
- });
- it('do not show banner when dismissed', async function () {
- const organization = OrganizationFixture();
- const snoozeTime = new Date('2020-02-02');
- snoozeTime.setHours(23, 59, 59);
- MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/${organization.slug}/prompts-activity/`,
- body: {
- features: {
- transactions_overage_alert: {
- snoozed_ts: snoozeTime.getTime() / 1000,
- },
- replays_overage_alert: {
- snoozed_ts: snoozeTime.getTime() / 1000,
- },
- },
- },
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_t',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: false}),
- transactions: MetricHistoryFixture({usageExceeded: true}),
- replays: MetricHistoryFixture({usageExceeded: true}),
- attachments: MetricHistoryFixture({usageExceeded: false}),
- monitorSeats: MetricHistoryFixture({usageExceeded: false}),
- },
- canSelfServe: true,
- onDemandPeriodEnd: '2020-02-02',
- });
- SubscriptionStore.set(organization.slug, subscription);
- const {container} = render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(container).toBeEmptyDOMElement();
- });
- it('shows add quota btn for paid plans for admins for warnings', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-1',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- categories: {
- errors: MetricHistoryFixture({sentUsageWarning: true}),
- transactions: MetricHistoryFixture({sentUsageWarning: false}),
- replays: MetricHistoryFixture({usageExceeded: false}),
- attachments: MetricHistoryFixture({sentUsageWarning: false}),
- monitorSeats: MetricHistoryFixture({sentUsageWarning: false}),
- },
- canSelfServe: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByRole('button', {name: /increase reserved limits/i})
- ).toBeInTheDocument();
- });
- it('shows add quota button for paid plans warnings with no active product trial', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-1',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am3_team',
- categories: {
- errors: MetricHistoryFixture({sentUsageWarning: false}),
- spans: MetricHistoryFixture({sentUsageWarning: false}),
- replays: MetricHistoryFixture({usageExceeded: true}),
- attachments: MetricHistoryFixture({sentUsageWarning: false}),
- monitorSeats: MetricHistoryFixture({sentUsageWarning: false}),
- profileDuration: MetricHistoryFixture({sentUsageWarning: false}),
- },
- canSelfServe: true,
- productTrials: [
- {
- category: 'replays',
- reasonCode: 1001,
- isStarted: false,
- lengthDays: undefined,
- startDate: undefined,
- endDate: undefined,
- },
- ],
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByRole('button', {name: /increase reserved limits/i})
- ).toBeInTheDocument();
- });
- it('does not show add quota btn for paid plans warnings with active product trial', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-1',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am3_team',
- categories: {
- errors: MetricHistoryFixture({sentUsageWarning: false}),
- spans: MetricHistoryFixture({sentUsageWarning: false}),
- replays: MetricHistoryFixture({usageExceeded: true}),
- attachments: MetricHistoryFixture({sentUsageWarning: false}),
- monitorSeats: MetricHistoryFixture({sentUsageWarning: false}),
- },
- canSelfServe: true,
- productTrials: [
- {
- category: 'replays',
- reasonCode: 1001,
- isStarted: true,
- lengthDays: 20,
- startDate: moment().utc().subtract(10, 'days').format(),
- endDate: moment().utc().add(10, 'days').format(),
- },
- ],
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(
- screen.queryByRole('button', {name: /increase reserved limits/i})
- ).not.toBeInTheDocument();
- });
- it('does not show warning if on-demand is set', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-1',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- categories: {errors: MetricHistoryFixture({sentUsageWarning: true})},
- canSelfServe: true,
- onDemandMaxSpend: 10,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(
- screen.queryByRole('button', {name: /increase reserved limits/i})
- ).not.toBeInTheDocument();
- });
- it('does not show warning if active product trial', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-1',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- categories: {monitorSeats: MetricHistoryFixture({sentUsageWarning: true})},
- canSelfServe: true,
- productTrials: [
- {
- category: DataCategory.MONITOR_SEATS,
- isStarted: true,
- reasonCode: 1001,
- startDate: moment().utc().subtract(10, 'days').format(),
- endDate: moment().utc().add(20, 'days').format(),
- },
- ],
- });
- SubscriptionStore.set(organization.slug, subscription);
- const {container} = render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(container).toBeEmptyDOMElement();
- });
- it('shows warning even if other category is on active trial', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-1',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- categories: {
- errors: MetricHistoryFixture({sentUsageWarning: true}),
- monitorSeats: MetricHistoryFixture({sentUsageWarning: true}),
- },
- canSelfServe: true,
- productTrials: [
- {
- category: DataCategory.MONITOR_SEATS,
- isStarted: true,
- reasonCode: 1001,
- startDate: moment().utc().subtract(10, 'days').format(),
- endDate: moment().utc().add(20, 'days').format(),
- },
- ],
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(await screen.findByTestId('overage-banner-error')).toBeInTheDocument();
- expect(screen.queryByTestId('overage-banner-monitorSeat')).not.toBeInTheDocument();
- });
- it('does not show alert if hasOverageNotificationsDisabled is set', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-2',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: true}),
- transactions: MetricHistoryFixture({usageExceeded: true}),
- replays: MetricHistoryFixture({usageExceeded: true}),
- attachments: MetricHistoryFixture({usageExceeded: true}),
- monitorSeats: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- hasOverageNotificationsDisabled: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(
- screen.queryByRole('button', {name: /increase reserved limits/i})
- ).not.toBeInTheDocument();
- });
- it('does not show notification if hasOverageNotificationsDisabled is set', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-3',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: true}),
- transactions: MetricHistoryFixture({usageExceeded: true}),
- replays: MetricHistoryFixture({usageExceeded: true}),
- attachments: MetricHistoryFixture({usageExceeded: true}),
- monitorSeats: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- hasOverageNotificationsDisabled: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(
- screen.queryByRole('button', {name: /increase reserved limits/i})
- ).not.toBeInTheDocument();
- });
- it('does not show warning if hasOverageNotificationsDisabled is set', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-4',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- categories: {
- errors: MetricHistoryFixture({
- category: DataCategory.ERRORS,
- sentUsageWarning: true,
- }),
- transactions: MetricHistoryFixture({
- category: DataCategory.TRANSACTIONS,
- sentUsageWarning: true,
- }),
- replays: MetricHistoryFixture({
- category: DataCategory.REPLAYS,
- sentUsageWarning: true,
- }),
- attachments: MetricHistoryFixture({
- category: DataCategory.ATTACHMENTS,
- sentUsageWarning: true,
- }),
- monitorSeats: MetricHistoryFixture({
- category: DataCategory.MONITOR_SEATS,
- sentUsageWarning: true,
- }),
- },
- canSelfServe: true,
- hasOverageNotificationsDisabled: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {
- organization,
- });
- await act(tick);
- expect(screen.queryByTestId('overage-banner-error')).not.toBeInTheDocument();
- expect(screen.queryByTestId('overage-banner-transaction')).not.toBeInTheDocument();
- expect(screen.queryByTestId('overage-banner-replay')).not.toBeInTheDocument();
- expect(screen.queryByTestId('overage-banner-attachment')).not.toBeInTheDocument();
- expect(screen.queryByTestId('overage-banner-monitorSeat')).not.toBeInTheDocument();
- });
- it('renders suspension modal', async function () {
- const organization = OrganizationFixture({slug: 'suspended'});
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({organization, isSuspended: true})
- );
- render(<GSBanner organization={organization} />, {organization});
- renderGlobalModal();
- expect(await screen.findByRole('dialog')).toBeInTheDocument();
- });
- it('renders usage exceeded modal', async function () {
- const organization = OrganizationFixture({slug: 'exceeded'});
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({organization, usageExceeded: true})
- );
- render(<GSBanner organization={organization} />, {organization});
- renderGlobalModal();
- expect(await screen.findByTestId('modal-usage-exceeded')).toBeInTheDocument();
- });
- it('renders grace period modal with billing access', async function () {
- const organization = OrganizationFixture({
- slug: 'grace-period',
- access: ['org:billing'],
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({organization, isGracePeriod: true})
- );
- render(<GSBanner organization={organization} />, {organization});
- renderGlobalModal();
- expect(await screen.findByTestId('modal-grace-period')).toBeInTheDocument();
- });
- it('does not render overage banner without grace period and usage exceeded', async function () {
- const organization = OrganizationFixture({
- slug: 'soft-cap',
- access: ['org:billing'],
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- isGracePeriod: false,
- usageExceeded: false,
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(screen.queryByTestId('grace-period-banner')).not.toBeInTheDocument();
- expect(screen.queryByTestId('usage-exceeded-banner')).not.toBeInTheDocument();
- expect(screen.queryByTestId('modal-usage-exceeded')).not.toBeInTheDocument();
- expect(screen.queryByTestId('modal-grace-period')).not.toBeInTheDocument();
- });
- it('opens the trialEndingModal within 3 days of ending', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'trial-ending',
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- isTrial: true,
- hasDismissedTrialEndingNotice: false,
- plan: 'am1_t',
- trialEnd: now.add(2, 'day').toString(),
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openTrialEndingModal).toHaveBeenCalled());
- });
- it('does not display trial ending modal more than 3 days', async function () {
- const now = moment();
- const organization = OrganizationFixture({});
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- hasDismissedTrialEndingNotice: false,
- plan: 'am1_t',
- trialEnd: now.add(5, 'day').toString(),
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(openTrialEndingModal).not.toHaveBeenCalled();
- });
- it('does not display trial ending modal to free plan', async function () {
- const organization = OrganizationFixture({});
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- hasDismissedTrialEndingNotice: false,
- plan: 'am1_f',
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(openTrialEndingModal).not.toHaveBeenCalled();
- });
- it('does not display trial ending modal to plan trial', async function () {
- const now = moment();
- const organization = OrganizationFixture({});
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- hasDismissedTrialEndingNotice: false,
- plan: 'am1_team',
- trialEnd: now.add(2, 'day').toString(),
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(openTrialEndingModal).not.toHaveBeenCalled();
- });
- it('does not display trial ending modal to enterprise trial', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'trial-ending',
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- isTrial: true,
- hasDismissedTrialEndingNotice: false,
- plan: 'am1_business',
- trialEnd: now.add(2, 'day').toString(),
- isEnterpriseTrial: true,
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(openTrialEndingModal).not.toHaveBeenCalled();
- });
- it('opens the partnerPlanEndingModal within 30 days of ending', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'partner-plan-ending',
- features: ['partner-billing-migration'],
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- contractPeriodEnd: now.add(30, 'day').toString(),
- isTrial: true,
- plan: 'am2_sponsored_team_auf',
- partner: {
- externalId: '123',
- name: 'FOO',
- partnership: {
- id: 'FOO',
- displayName: 'FOO',
- supportNote: '',
- },
- isActive: true,
- },
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openPartnerPlanEndingModal).toHaveBeenCalled());
- });
- it('opens the partnerPlanEndingModal within 7 days of ending', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'partner-plan-ending',
- features: ['partner-billing-migration'],
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- contractPeriodEnd: now.add(7, 'day').toString(),
- isTrial: true,
- plan: 'am2_sponsored_team_auf',
- partner: {
- externalId: '123',
- name: 'FOO',
- partnership: {
- id: 'FOO',
- displayName: 'FOO',
- supportNote: '',
- },
- isActive: true,
- },
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openPartnerPlanEndingModal).toHaveBeenCalled());
- });
- it('opens the partnerPlanEndingModal with 2 days left', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'partner-plan-ending',
- features: ['partner-billing-migration'],
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- contractPeriodEnd: now.add(2, 'days').toString(),
- isTrial: true,
- plan: 'am2_sponsored_team_auf',
- partner: {
- externalId: '123',
- name: 'FOO',
- partnership: {
- id: 'FOO',
- displayName: 'FOO',
- supportNote: '',
- },
- isActive: true,
- },
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openPartnerPlanEndingModal).toHaveBeenCalled());
- });
- it('opens the partnerPlanEndingModal on day that plan ends', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'partner-plan-ending',
- features: ['partner-billing-migration'],
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- contractPeriodEnd: now.toString(),
- isTrial: true,
- plan: 'am2_sponsored_team_auf',
- partner: {
- externalId: '123',
- name: 'FOO',
- partnership: {
- id: 'FOO',
- displayName: 'FOO',
- supportNote: '',
- },
- isActive: true,
- },
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openPartnerPlanEndingModal).toHaveBeenCalled());
- });
- it('does not open the partnerPlanEndingModal without feature flag', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'partner-plan-ending',
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- contractPeriodEnd: now.add(7, 'day').toString(),
- isTrial: true,
- plan: 'am2_sponsored_team_auf',
- partner: {
- externalId: '123',
- name: 'FOO',
- partnership: {
- id: 'FOO',
- displayName: 'FOO',
- supportNote: '',
- },
- isActive: true,
- },
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openPartnerPlanEndingModal).not.toHaveBeenCalled());
- });
- it('does not open the partnerPlanEndingModal with pending upgrade', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'partner-plan-ending',
- features: ['partner-billing-migration'],
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- contractPeriodEnd: now.add(7, 'day').toString(),
- isTrial: true,
- plan: 'am2_sponsored_team_auf',
- partner: {
- externalId: '123',
- name: 'FOO',
- partnership: {
- id: 'FOO',
- displayName: 'FOO',
- supportNote: '',
- },
- isActive: true,
- },
- pendingChanges: PendingChangesFixture({
- plan: 'am3_business',
- planDetails: PlanFixture({
- name: 'Business',
- price: 100,
- }),
- }),
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openPartnerPlanEndingModal).not.toHaveBeenCalled());
- });
- it('opens the partnerPlanEndingModal with pending downgrade', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'partner-plan-ending',
- features: ['partner-billing-migration'],
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- contractPeriodEnd: now.add(7, 'day').toString(),
- isTrial: true,
- plan: 'am2_sponsored_team_auf',
- partner: {
- externalId: '123',
- name: 'FOO',
- partnership: {
- id: 'FOO',
- displayName: 'FOO',
- supportNote: '',
- },
- isActive: true,
- },
- pendingChanges: PendingChangesFixture({
- plan: 'am3_f',
- planDetails: PlanFixture({
- name: 'Developer',
- price: 0,
- }),
- }),
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openPartnerPlanEndingModal).toHaveBeenCalled());
- });
- it('does not open the partnerPlanEndingModal with more than 30 days before ending', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'partner-plan-ending',
- features: ['partner-billing-migration'],
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- contractPeriodEnd: now.add(31, 'day').toString(),
- isTrial: true,
- plan: 'am2_sponsored_team_auf',
- partner: {
- externalId: '123',
- name: 'FOO',
- partnership: {
- id: 'FOO',
- displayName: 'FOO',
- supportNote: '',
- },
- isActive: true,
- },
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openPartnerPlanEndingModal).not.toHaveBeenCalled());
- });
- it('does not open the partnerPlanEndingModal if dismissed', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'partner-plan-ending',
- features: ['partner-billing-migration'],
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/${organization.slug}/prompts-activity/`,
- body: {
- data: {
- dismissed_ts: moment().subtract(2, 'days').unix(),
- },
- },
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- contractPeriodEnd: now.add(20, 'day').toString(),
- isTrial: true,
- plan: 'am2_sponsored_team_auf',
- partner: {
- externalId: '123',
- name: 'FOO',
- partnership: {
- id: 'FOO',
- displayName: 'FOO',
- supportNote: '',
- },
- isActive: true,
- },
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openPartnerPlanEndingModal).not.toHaveBeenCalled());
- });
- it('opens partnerPlanEndingModal if dismissed in different time period', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'partner-plan-ending',
- features: ['partner-billing-migration'],
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/${organization.slug}/prompts-activity/`,
- body: {
- data: {
- dismissed_ts: moment().subtract(20, 'days').unix(),
- },
- },
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- contractPeriodEnd: now.add(1, 'day').toString(),
- isTrial: true,
- plan: 'am2_sponsored_team_auf',
- partner: {
- externalId: '123',
- name: 'FOO',
- partnership: {
- id: 'FOO',
- displayName: 'FOO',
- supportNote: '',
- },
- isActive: true,
- },
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openPartnerPlanEndingModal).toHaveBeenCalled());
- });
- it('opens partnerPlanEndingModal if dismissed with 2 days left on day plan ends', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'partner-plan-ending',
- features: ['partner-billing-migration'],
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/${organization.slug}/prompts-activity/`,
- body: {
- data: {
- dismissed_ts: moment().subtract(2, 'days').unix(),
- },
- },
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- contractPeriodEnd: now.toString(),
- isTrial: true,
- plan: 'am2_sponsored_team_auf',
- partner: {
- externalId: '123',
- name: 'FOO',
- partnership: {
- id: 'FOO',
- displayName: 'FOO',
- supportNote: '',
- },
- isActive: true,
- },
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openPartnerPlanEndingModal).toHaveBeenCalled());
- });
- it('does not open partnerPlanEndingModal if dismissed with two days left and logs in with one day left', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'partner-plan-ending',
- features: ['partner-billing-migration'],
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/${organization.slug}/prompts-activity/`,
- body: {
- data: {
- dismissed_ts: moment().subtract(1, 'days').unix(),
- },
- },
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- contractPeriodEnd: now.add(1, 'day').toString(),
- isTrial: true,
- plan: 'am2_sponsored_team_auf',
- partner: {
- externalId: '123',
- name: 'FOO',
- partnership: {
- id: 'FOO',
- displayName: 'FOO',
- supportNote: '',
- },
- isActive: true,
- },
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- await waitFor(() => expect(openPartnerPlanEndingModal).not.toHaveBeenCalled());
- });
- it('show disabled member header', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- membersDeactivatedFromLimit: 2,
- })
- );
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByText(textWithMarkupMatcher(/2 members have been deactivated/i))
- ).toBeInTheDocument();
- });
- it('loads pendo', async function () {
- guideMock.state.currentGuide = false;
- const organization = OrganizationFixture({
- slug: 'forced-trial',
- orgRole: 'admin',
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- plan: 'am1_business',
- onDemandMaxSpend: 1000,
- totalMembers: 26,
- reservedErrors: 5_000_000,
- reservedTransactions: 10_000_001,
- planDetails: PlanFixture({
- totalPrice: 100_000 * 12,
- billingInterval: 'annual',
- }),
- })
- );
- MockApiClient.addMockResponse({
- method: 'POST',
- url: `/organizations/${organization.slug}/promotions/lorem-ipsum/claim/`,
- body: {},
- });
- const now = moment();
- const promotionData = {
- availablePromotions: [
- {
- endDate: null,
- name: 'Lorem Ipsum',
- slug: 'lorem-ipsum',
- startDate: now.add(-14, 'day'),
- timeLimit: 'null',
- autoOptIn: true,
- },
- ],
- };
- MockApiClient.addMockResponse({
- method: 'POST',
- url: `/organizations/${organization.slug}/promotions/trigger-check/`,
- body: promotionData,
- });
- window.pendo = {
- initialize: jest.fn(),
- };
- MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/${organization.slug}/pendo-details/`,
- body: {
- userDetails: {
- fieldA: 'valueA',
- },
- organizationDetails: {
- fieldB: 'valueB',
- },
- },
- });
- const user = ConfigStore.get('user');
- render(<GSBanner organization={organization} />, {
- organization,
- });
- await waitFor(() => {
- expect(window.pendo.initialize).toHaveBeenCalledWith({
- visitor: {
- id: `${organization.id}.${user.id}`,
- userId: user.id,
- role: 'admin',
- isDarkMode: false,
- fieldA: 'valueA',
- },
- account: expect.objectContaining({
- id: organization.id,
- hasOnDemandSpend: true,
- reservedErrors: 'indigo',
- reservedTransactions: 'violet',
- totalMembers: 'blue',
- arr: 'yellow',
- fieldB: 'valueB',
- plan: 'am1_business',
- }),
- guides: {
- delay: false,
- },
- });
- });
- delete window.pendo;
- });
- it('delay pendo guides if other guides are active', async function () {
- guideMock.state.currentGuide = true;
- const organization = OrganizationFixture();
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- })
- );
- MockApiClient.addMockResponse({
- method: 'POST',
- url: `/organizations/${organization.slug}/promotions/lorem-ipsum/claim/`,
- body: {},
- });
- window.pendo = {
- initialize: jest.fn(),
- };
- const now = moment();
- const promotionData = {
- availablePromotions: [
- {
- endDate: null,
- name: 'Lorem Ipsum',
- slug: 'lorem-ipsum',
- startDate: now.add(-14, 'day'),
- timeLimit: 'null',
- autoOptIn: true,
- },
- ],
- };
- MockApiClient.addMockResponse({
- method: 'POST',
- url: `/organizations/${organization.slug}/promotions/trigger-check/`,
- body: promotionData,
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/${organization.slug}/pendo-details/`,
- body: {
- userDetails: {
- fieldA: 'valueA',
- },
- organizationDetails: {
- fieldB: 'valueB',
- },
- },
- });
- render(<GSBanner organization={organization} />, {
- organization,
- });
- await waitFor(() => {
- expect(window.pendo.initialize).toHaveBeenCalledWith(
- expect.objectContaining({
- guides: {
- delay: true,
- },
- })
- );
- });
- });
- it('forced trial automatically starts', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- });
- const subscription = SubscriptionFixture({
- plan: 'am1_f',
- organization,
- totalLicenses: 1,
- usedLicenses: 2,
- });
- SubscriptionStore.set(organization.slug, subscription);
- const mockForceTrial = MockApiClient.addMockResponse({
- method: 'POST',
- url: `/organizations/${organization.slug}/over-member-limit-trial/`,
- body: {},
- });
- render(<GSBanner organization={organization} />, {
- organization,
- });
- await waitFor(() => {
- expect(mockForceTrial).toHaveBeenCalledWith(
- `/organizations/${organization.slug}/over-member-limit-trial/`,
- expect.objectContaining({
- method: 'POST',
- })
- );
- });
- expect(openForcedTrialModal).toHaveBeenCalled();
- });
- it('forced trial automatically starts for restricted integration', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- plan: 'am1_f',
- organization,
- totalLicenses: 1,
- usedLicenses: 1,
- hasRestrictedIntegration: true,
- })
- );
- const mockForceTrial = MockApiClient.addMockResponse({
- method: 'POST',
- url: `/organizations/${organization.slug}/restricted-integration-trial/`,
- body: {},
- });
- render(<GSBanner organization={organization} />, {
- organization,
- });
- await waitFor(() => {
- expect(mockForceTrial).toHaveBeenCalledWith(
- `/organizations/${organization.slug}/restricted-integration-trial/`,
- expect.objectContaining({
- method: 'POST',
- })
- );
- });
- expect(openForcedTrialModal).toHaveBeenCalled();
- });
- it('open the forced trial modal', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'forced-trial',
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- hasDismissedForcedTrialNotice: false,
- plan: 'am1_t',
- trialEnd: now.add(14, 'day').toString(),
- isForcedTrial: true,
- isTrial: true,
- })
- );
- render(<GSBanner organization={organization} />, {
- organization,
- });
- await waitFor(() => expect(openForcedTrialModal).toHaveBeenCalled());
- });
- it('does not open forced trial modal if dismissed', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'forced-trial',
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- hasDismissedForcedTrialNotice: true,
- plan: 'am1_t',
- trialEnd: now.add(14, 'day').toString(),
- isForcedTrial: true,
- isTrial: true,
- })
- );
- render(<GSBanner organization={organization} />, {
- organization,
- });
- await act(tick);
- expect(openForcedTrialModal).not.toHaveBeenCalled();
- });
- it('activates the first available promotion', async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'promotion-platform',
- });
- const promotionData = {
- availablePromotions: [
- {
- endDate: null,
- name: 'Lorem Ipsum',
- slug: 'lorem-ipsum',
- startDate: now.add(-14, 'day'),
- timeLimit: 'null',
- autoOptIn: true,
- },
- ],
- };
- MockApiClient.addMockResponse({
- method: 'POST',
- url: `/organizations/${organization.slug}/promotions/trigger-check/`,
- body: promotionData,
- });
- const activatePromoEndpoint = MockApiClient.addMockResponse({
- method: 'POST',
- url: `/organizations/${organization.slug}/promotions/lorem-ipsum/claim/`,
- body: {},
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- plan: 'am1_team',
- })
- );
- render(<GSBanner organization={organization} />, {
- organization,
- });
- await waitFor(() => {
- expect(activatePromoEndpoint).toHaveBeenCalledWith(
- `/organizations/${organization.slug}/promotions/lorem-ipsum/claim/`,
- expect.objectContaining({
- method: 'POST',
- })
- );
- });
- });
- it("doesn't activate non auto-opt-in promos", async function () {
- const now = moment();
- const organization = OrganizationFixture({
- slug: 'promotion-platform',
- });
- const promotionData = {
- availablePromotions: [
- {
- endDate: null,
- name: 'Lorem Ipsum',
- slug: 'lorem-ipsum',
- startDate: now.add(-14, 'day'),
- timeLimit: 'null',
- autoOptIn: false,
- },
- ],
- };
- MockApiClient.addMockResponse({
- method: 'POST',
- url: `/organizations/${organization.slug}/promotions/trigger-check/`,
- body: promotionData,
- });
- const activatePromoEndpoint = MockApiClient.addMockResponse({
- method: 'POST',
- url: `/organizations/${organization.slug}/promotions/lorem-ipsum/claim/`,
- body: {},
- });
- SubscriptionStore.set(
- organization.slug,
- SubscriptionFixture({
- organization,
- plan: 'am1_team',
- })
- );
- render(<GSBanner organization={organization} />, {
- organization,
- });
- await waitFor(() => {
- expect(activatePromoEndpoint).not.toHaveBeenCalledWith(
- `/organizations/${organization.slug}/promotions/lorem-ipsum/claim/`,
- expect.objectContaining({
- method: 'POST',
- })
- );
- });
- });
- it('shows correct past due modal and banner for billing admins', async function () {
- const organization = OrganizationFixture({
- slug: 'past-due',
- access: ['org:billing'],
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- isPastDue: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- renderGlobalModal();
- expect(await screen.findByTestId('banner-alert-past-due')).toBeInTheDocument();
- expect(
- screen.getByRole('button', {name: /update payment information/i})
- ).toHaveAttribute(
- 'href',
- `/settings/past-due/billing/details/?referrer=banner-billing-failure`
- );
- expect(await screen.findByTestId('modal-past-due')).toBeInTheDocument();
- expect(screen.getByTestId('modal-continue-button')).toBeInTheDocument();
- expect(
- screen.getByText(
- 'There was an issue with your payment. Update your payment information to ensure uniterrupted access to Sentry.'
- )
- ).toBeInTheDocument();
- await userEvent.click(screen.getByTestId('modal-continue-button'));
- expect(browserHistory.push).toHaveBeenCalledWith(
- `/settings/past-due/billing/details/?referrer=banner-billing-failure`
- );
- });
- it('shows past due modal and banner for non-billing users', async function () {
- const organization = OrganizationFixture({
- slug: 'past-due-4',
- access: ['org:read'],
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- isPastDue: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- renderGlobalModal();
- expect(await screen.findByTestId('banner-alert-past-due')).toBeInTheDocument();
- expect(await screen.findByTestId('modal-past-due')).toBeInTheDocument();
- expect(screen.getByTestId('modal-continue-button')).toBeInTheDocument();
- });
- it('does not show past due modal for users without access', async function () {
- const organization = OrganizationFixture({
- slug: 'past-due-4',
- access: [],
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- isPastDue: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- renderGlobalModal();
- await act(tick);
- expect(screen.queryByTestId('modal-past-due')).not.toBeInTheDocument();
- expect(screen.queryByTestId('modal-continue-button')).not.toBeInTheDocument();
- });
- it('shows specific banner text just for cron overages', async function () {
- const organization = OrganizationFixture({access: ['org:billing']});
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am2_team',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: false}),
- transactions: MetricHistoryFixture({usageExceeded: false}),
- replays: MetricHistoryFixture({usageExceeded: false}),
- attachments: MetricHistoryFixture({usageExceeded: false}),
- monitorSeats: MetricHistoryFixture({usageExceeded: true}),
- profileDuration: MetricHistoryFixture({usageExceeded: false}),
- },
- canSelfServe: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByText(
- "We can't enable additional Cron Monitors because you don't have a sufficient on-demand budget."
- )
- ).toBeInTheDocument();
- expect(await screen.findByRole('button', {name: 'Update Plan'})).toBeInTheDocument();
- });
- it('shows specific banner text just for uptime overages', async function () {
- const organization = OrganizationFixture({access: ['org:billing']});
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am2_team',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: false}),
- transactions: MetricHistoryFixture({usageExceeded: false}),
- replays: MetricHistoryFixture({usageExceeded: false}),
- attachments: MetricHistoryFixture({usageExceeded: false}),
- monitorSeats: MetricHistoryFixture({usageExceeded: false}),
- profileDuration: MetricHistoryFixture({usageExceeded: false}),
- uptime: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByText(
- "We can't enable additional Uptime Monitors because you don't have a sufficient on-demand budget."
- )
- ).toBeInTheDocument();
- expect(
- await screen.findByRole('button', {name: 'Increase Reserved Limits'})
- ).toBeInTheDocument();
- });
- it('does not show past due modal for enterprise orgs', async function () {
- const organization = OrganizationFixture({
- slug: 'past-due-3',
- access: ['org:billing'],
- });
- const subscription = InvoicedSubscriptionFixture({
- organization,
- plan: 'am2_business_ent',
- isPastDue: true,
- canSelfServe: false,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- renderGlobalModal();
- await act(tick);
- expect(screen.queryByTestId('banner-alert-past-due')).not.toBeInTheDocument();
- expect(
- screen.queryByRole('button', {name: /update payment information/i})
- ).not.toBeInTheDocument();
- expect(
- screen.queryByRole('button', {name: /update billing details/i})
- ).not.toBeInTheDocument();
- });
- it('shows overage notification banner for the spans category', async function () {
- const organization = OrganizationFixture();
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_t',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: false}),
- transactions: MetricHistoryFixture({usageExceeded: false}),
- replays: MetricHistoryFixture({usageExceeded: false}),
- attachments: MetricHistoryFixture({usageExceeded: false}),
- monitorSeats: MetricHistoryFixture({usageExceeded: false}),
- spans: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(await screen.findByTestId('overage-banner-span')).toBeInTheDocument();
- expect(screen.getByText('span')).toBeInTheDocument();
- });
- it('shows overage notification banner for multiple categories including spans', async function () {
- const organization = OrganizationFixture();
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_t',
- categories: {
- errors: MetricHistoryFixture({usageExceeded: true}),
- transactions: MetricHistoryFixture({usageExceeded: true}),
- spans: MetricHistoryFixture({usageExceeded: true}),
- replays: MetricHistoryFixture({usageExceeded: false}),
- attachments: MetricHistoryFixture({usageExceeded: true}),
- monitorSeats: MetricHistoryFixture({usageExceeded: true}),
- uptime: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByTestId(
- 'overage-banner-error-transaction-attachment-monitorSeat-span-uptime'
- )
- ).toBeInTheDocument();
- expect(screen.getByText('span')).toBeInTheDocument();
- });
- it('does not show overage notification banner for spans if overage notifications are disabled', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-2',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- categories: {
- spans: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- hasOverageNotificationsDisabled: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(
- screen.queryByRole('button', {name: /increase reserved limits/i})
- ).not.toBeInTheDocument();
- });
- it('shows overage warning banner for spans', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-1',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- categories: {
- errors: MetricHistoryFixture({sentUsageWarning: false}),
- spans: MetricHistoryFixture({sentUsageWarning: true}),
- replays: MetricHistoryFixture({usageExceeded: false}),
- attachments: MetricHistoryFixture({sentUsageWarning: false}),
- monitorSeats: MetricHistoryFixture({sentUsageWarning: false}),
- },
- canSelfServe: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByRole('button', {name: /increase reserved limits/i})
- ).toBeInTheDocument();
- });
- it('does not show overage warning banner for spans if on-demand is set', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-1',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- categories: {spans: MetricHistoryFixture({sentUsageWarning: true})},
- canSelfServe: true,
- onDemandMaxSpend: 10,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(
- screen.queryByRole('button', {name: /increase reserved limits/i})
- ).not.toBeInTheDocument();
- });
- it('does not show overage notification banner for spans if active product trial', async function () {
- const organization = OrganizationFixture();
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am3_team',
- categories: {spans: MetricHistoryFixture({usageExceeded: true})},
- canSelfServe: true,
- productTrials: [
- {
- category: DataCategory.SPANS,
- isStarted: true,
- reasonCode: 1001,
- startDate: moment().utc().subtract(10, 'days').format(),
- endDate: moment().utc().add(20, 'days').format(),
- },
- ],
- });
- SubscriptionStore.set(organization.slug, subscription);
- const {container} = render(<GSBanner organization={organization} />, {organization});
- await act(tick);
- expect(container).toBeEmptyDOMElement();
- });
- it('shows overage notification banner for spans even if other category is on active trial', async function () {
- const organization = OrganizationFixture();
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am3_team',
- categories: {
- spans: MetricHistoryFixture({usageExceeded: true}),
- replays: MetricHistoryFixture({usageExceeded: true}),
- },
- canSelfServe: true,
- productTrials: [
- {
- category: DataCategory.REPLAYS,
- isStarted: true,
- reasonCode: 1001,
- startDate: moment().utc().subtract(10, 'days').format(),
- endDate: moment().utc().add(20, 'days').format(),
- },
- ],
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(await screen.findByTestId('overage-banner-span')).toBeInTheDocument();
- expect(screen.queryByTestId('overage-banner-replay')).not.toBeInTheDocument();
- });
- it('shows overage warning banner for profileDuration', async function () {
- const organization = OrganizationFixture({
- access: ['org:billing'],
- slug: 'another-slug-1',
- });
- const subscription = SubscriptionFixture({
- organization,
- plan: 'am1_team',
- categories: {
- errors: MetricHistoryFixture({sentUsageWarning: false}),
- spans: MetricHistoryFixture({sentUsageWarning: false}),
- profileDuration: MetricHistoryFixture({sentUsageWarning: true}), // Warning sent
- replays: MetricHistoryFixture({usageExceeded: false}),
- attachments: MetricHistoryFixture({sentUsageWarning: false}),
- monitorSeats: MetricHistoryFixture({sentUsageWarning: false}),
- },
- canSelfServe: true,
- });
- SubscriptionStore.set(organization.slug, subscription);
- render(<GSBanner organization={organization} />, {organization});
- expect(
- await screen.findByRole('button', {name: /increase reserved limits/i})
- ).toBeInTheDocument();
- });
- });
|