Enforce cloud website limits by subscription tier
This commit is contained in:
1 parent
7d4c68cebe
commit
c41bf7c93e
4 files changed
+73
-10
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import {
|
||||
CLOUD_FREE_WEBSITE_LIMIT,
|
||||
CLOUD_PRO_WEBSITE_LIMIT,
|
||||
getCloudWebsiteLimit,
|
||||
} from './subscription';
|
||||
|
||||
describe('getCloudWebsiteLimit', () => {
|
||||
test('limits accounts without a subscription to the free website limit', () => {
|
||||
expect(getCloudWebsiteLimit(null)).toBe(CLOUD_FREE_WEBSITE_LIMIT);
|
||||
expect(getCloudWebsiteLimit({ hasSubscription: false })).toBe(CLOUD_FREE_WEBSITE_LIMIT);
|
||||
});
|
||||
|
||||
test('limits Pro accounts to the Pro website limit', () => {
|
||||
expect(getCloudWebsiteLimit({ hasSubscription: true, isPro: true })).toBe(
|
||||
CLOUD_PRO_WEBSITE_LIMIT,
|
||||
);
|
||||
});
|
||||
|
||||
test('does not limit Business or no-billing accounts', () => {
|
||||
expect(getCloudWebsiteLimit({ hasSubscription: true, isBusiness: true })).toBeNull();
|
||||
expect(getCloudWebsiteLimit({ hasSubscription: true, isNoBilling: true })).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
export interface SubscriptionAccount {
|
||||
isPro?: boolean | null;
|
||||
isBusiness?: boolean | null;
|
||||
isNoBilling?: boolean | null;
|
||||
hasSubscription?: boolean | null;
|
||||
}
|
||||
|
||||
export const CLOUD_FREE_WEBSITE_LIMIT = 3;
|
||||
export const CLOUD_PRO_WEBSITE_LIMIT = 20;
|
||||
|
||||
export function getCloudWebsiteLimit(account?: SubscriptionAccount | null): number | null {
|
||||
if (!account?.hasSubscription) {
|
||||
return CLOUD_FREE_WEBSITE_LIMIT;
|
||||
}
|
||||
|
||||
if (account.isNoBilling || account.isBusiness) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (account.isPro) {
|
||||
return CLOUD_PRO_WEBSITE_LIMIT;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in new issue
Block a user