Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/dashboard/Data/AppOverview/usageAlert.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { getUsagePercent } from '../../AppPlan/usageClassUtils';
const WARNING_PERCENT = 70;
const DANGER_PERCENT = 90;

// Over-quota prices from the pricing page FAQ. Requests depend on the plan. Only the current
// MVP and Pay As You Go publish them, and Advanced has the same limits and prices as
// Pay As You Go: the other legacy plans get the warning without a price.
const EXTRA_REQUESTS_PRICE = { MVP: '$5', 'Pay As You Go': '$2', Advanced: '$2' };
// Over-quota prices from the pricing page FAQ. Only Pay As You Go is billed for the overage:
// every other paid plan is told an upgrade is required instead.
const EXTRA_REQUESTS_PRICE = { 'Pay As You Go': '$2' };

// The next plan up, by kind. Legacy plans follow the current plan of their size.
const UPGRADE_TARGET = { free: 'MVP', starter: 'MVP', mvp: 'Pay As You Go', payg: 'Dedicated' };
Expand Down Expand Up @@ -65,8 +64,9 @@ const planLabelOf = planData => {
return /pay\s*as\s*you\s*go/i.test(name) ? 'Pay As You Go' : name;
};

// " Above 100%, extra requests are billed at ..." when the plan publishes its overage price.
const overageOf = (worst, plan, lead) => (plan in EXTRA_REQUESTS_PRICE ? ` ${lead}${worst.overage(plan)}.` : '');
// " Above 100%, extra requests are billed at ..." on Pay As You Go, the upgrade notice on the other plans.
const overageOf = (worst, plan, lead, upgradeRequired) =>
plan in EXTRA_REQUESTS_PRICE ? ` ${lead}${worst.overage(plan)}.` : ` ${upgradeRequired}`;

// The limit to talk about: most urgent first (over 100%, then red, then yellow) and, within
// the same level, the list order above. Also returns the others, most urgent first.
Expand All @@ -92,7 +92,7 @@ export const upgradeTargetOf = planData => UPGRADE_TARGET[planKindOf(planData)];
// or { level, message, action, actionLabel }. The action is 'checkout' with the `plan` to sell
// (the next one up) or, when there is no next plan to name, 'plans' for the Plan Usage page.
// Every plan follows the Free thresholds: yellow above 70%, red above 90%. Only the consequence
// changes: Free stops responding at 100%, paid plans keep running and pay the overage.
// changes: Free stops responding at 100%, Pay As You Go pays the overage, other paid plans must upgrade.
// The app is really blocked only when the server answers 402 or the plan is paused
// ("Free Plan - Paused"); a Free app over its limit still serves requests until then.
export const getUsageAlert = (planData, blocked = false) => {
Expand Down Expand Up @@ -138,12 +138,12 @@ export const getUsageAlert = (planData, blocked = false) => {
};
}

// Paid plans keep running over their limits and pay the overage, so the message names the
// price instead of an outage. Legacy plans have no published price and point at the next plan up.
// Pay As You Go keeps running over its limits and pays the overage, so the message names the
// price. The other paid plans are told an upgrade is required.
const plan = planLabelOf(planData);
const message = worst.percent >= 100
? `This app used ${percent}% of its ${plan} ${worst.label} ${amount}.${overageOf(worst, plan, 'It keeps running, and ')}`
: `${usageSummary(worst, percent, amount, ` on ${plan}`)}${othersClose(usage)}${overageOf(worst, plan, 'Above 100%, ')}`;
? `This app used ${percent}% of its ${plan} ${worst.label} ${amount}.${overageOf(worst, plan, 'It keeps running, and ', 'An upgrade is required.')}`
: `${usageSummary(worst, percent, amount, ` on ${plan}`)}${othersClose(usage)}${overageOf(worst, plan, 'Above 100%, ', 'At 100%, an upgrade is required.')}`;
return { level, message, ...upgrade };
};

Expand Down
24 changes: 12 additions & 12 deletions src/lib/tests/usageAlert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,28 @@ describe('getUsageAlert', () => {
expect(getUsageAlert(mvp({ apiCallUsed: '490 K' })).level).toBe('danger');
});

it('names the overage price and opens the Pay As You Go checkout', () => {
it('says an upgrade is required at 100% and opens the Pay As You Go checkout', () => {
const alert = getUsageAlert(mvp({ apiCallUsed: '490 K' }));
expect(alert.message).toBe(
'You\'ve used 98% of this month\'s API requests on MVP (490 K of 500 K). Above 100%, extra requests are billed at $5 per 100K.'
'You\'ve used 98% of this month\'s API requests on MVP (490 K of 500 K). At 100%, an upgrade is required.'
);
expect(alert.action).toBe('checkout');
expect(alert.plan).toBe('Pay As You Go');
expect(alert.actionLabel).toBe('Upgrade to Pay As You Go');
});

it('past 100% it keeps running and pays the overage', () => {
it('past 100% says an upgrade is required, without an overage price', () => {
const alert = getUsageAlert(mvp({ apiCallUsed: '520 K' }));
expect(alert.level).toBe('danger');
expect(alert.message).toBe(
'This app used 104% of its MVP API requests (520 K of 500 K). It keeps running, and extra requests are billed at $5 per 100K.'
'This app used 104% of its MVP API requests (520 K of 500 K). An upgrade is required.'
);
expect(alert.message).not.toMatch(/stop/i);
});

it('uses the storage overage prices', () => {
expect(getUsageAlert(mvp({ dataStorageUsed: '1.1 GB' })).message).toContain('extra database storage is billed at $15 per GB');
expect(getUsageAlert(mvp({ fileStorageUsed: '55 GB' })).message).toContain('extra file storage is billed at $1 per 10 GB');
it('never names a storage overage price', () => {
expect(getUsageAlert(mvp({ dataStorageUsed: '1.1 GB' })).message).not.toMatch(/billed/);
expect(getUsageAlert(mvp({ fileStorageUsed: '55 GB' })).message).not.toMatch(/billed/);
});

it('a blocked app is offered the Pay As You Go checkout', () => {
Expand Down Expand Up @@ -158,10 +158,10 @@ describe('getUsageAlert', () => {
expect(alert.message).not.toMatch(/billed/);
});
expect(getUsageAlert(legacy('Starter Plan', { apiCallUsed: '49 K' })).message).toBe(
'You\'ve used 98% of this month\'s API requests on Starter (49 K of 50 K).'
'You\'ve used 98% of this month\'s API requests on Starter (49 K of 50 K). At 100%, an upgrade is required.'
);
expect(getUsageAlert(legacy('Starter Plan', { apiCallUsed: '52 K' })).message).toBe(
'This app used 104% of its Starter API requests (52 K of 50 K).'
'This app used 104% of its Starter API requests (52 K of 50 K). An upgrade is required.'
);
});

Expand All @@ -175,17 +175,17 @@ describe('getUsageAlert', () => {
});
});

it('Advanced follows Pay As You Go: same thresholds, overage price and next plan', () => {
it('Advanced follows Pay As You Go thresholds and next plan, but is told to upgrade instead of billed', () => {
const advanced = overrides => legacy('Advanced Plan', { apiCallLimit: '5 M', dataStorageLimit: '4 GB', fileStorageLimit: '250 GB', ...overrides });
expect(getUsageAlert(advanced({ apiCallUsed: '3.5 M' }))).toBe(null);
expect(getUsageAlert(advanced({ apiCallUsed: '4 M' })).level).toBe('warning');
const alert = getUsageAlert(advanced({ apiCallUsed: '5.5 M' }));
expect(alert.level).toBe('danger');
expect(alert.message).toBe(
'This app used 110% of its Advanced API requests (5.5 M of 5 M). It keeps running, and extra requests are billed at $2 per 100K.'
'This app used 110% of its Advanced API requests (5.5 M of 5 M). An upgrade is required.'
);
expect(alert.plan).toBe('Dedicated');
expect(getUsageAlert(advanced({ dataStorageUsed: '4.5 GB' })).message).toContain('and extra database storage is billed at $15 per GB');
expect(getUsageAlert(advanced({ dataStorageUsed: '4.5 GB' })).message).not.toMatch(/billed/);
});

it('a blocked legacy app is told which plan to move to', () => {
Expand Down
Loading