Enforce a per-plan team limit when creating teams in cloud mode
This commit is contained in:
1 parent
889b2b7952
commit
bc97f9f439
4 files changed
+89
-18
No files matched your search
@@ -1,7 +1,10 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import {
|
||||
CLOUD_FREE_TEAM_LIMIT,
|
||||
CLOUD_FREE_WEBSITE_LIMIT,
|
||||
CLOUD_PRO_TEAM_LIMIT,
|
||||
CLOUD_PRO_WEBSITE_LIMIT,
|
||||
getCloudTeamLimit,
|
||||
getCloudWebsiteLimit,
|
||||
} from './subscription';
|
||||
|
||||
@@ -43,3 +46,28 @@ describe('getCloudWebsiteLimit', () => {
|
||||
).toBe(CLOUD_FREE_WEBSITE_LIMIT);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getCloudTeamLimit', () => {
|
||||
test('does not allow teams for accounts without a subscription', () => {
|
||||
expect(CLOUD_FREE_TEAM_LIMIT).toBe(0);
|
||||
expect(getCloudTeamLimit(null)).toBe(CLOUD_FREE_TEAM_LIMIT);
|
||||
expect(getCloudTeamLimit(undefined)).toBe(CLOUD_FREE_TEAM_LIMIT);
|
||||
expect(getCloudTeamLimit({ hasSubscription: false })).toBe(CLOUD_FREE_TEAM_LIMIT);
|
||||
});
|
||||
|
||||
test('limits Pro accounts to the Pro team limit', () => {
|
||||
expect(getCloudTeamLimit({ hasSubscription: true, isPro: true })).toBe(CLOUD_PRO_TEAM_LIMIT);
|
||||
});
|
||||
|
||||
test('does not limit Business or no-billing accounts', () => {
|
||||
expect(getCloudTeamLimit({ hasSubscription: true, isBusiness: true })).toBeNull();
|
||||
expect(getCloudTeamLimit({ hasSubscription: true, isNoBilling: true })).toBeNull();
|
||||
});
|
||||
|
||||
// unlimitedWebsites is a website-only entitlement; it must not lift the team limit.
|
||||
test('ignores the unlimited websites flag for team limits', () => {
|
||||
expect(getCloudTeamLimit({ hasSubscription: true, isPro: true, unlimitedWebsites: true })).toBe(
|
||||
CLOUD_PRO_TEAM_LIMIT,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -9,6 +9,9 @@ export interface SubscriptionAccount {
|
||||
export const CLOUD_FREE_WEBSITE_LIMIT = 1;
|
||||
export const CLOUD_PRO_WEBSITE_LIMIT = 20;
|
||||
|
||||
export const CLOUD_FREE_TEAM_LIMIT = 0;
|
||||
export const CLOUD_PRO_TEAM_LIMIT = 10;
|
||||
|
||||
export function getCloudWebsiteLimit(account?: SubscriptionAccount | null): number | null {
|
||||
if (!account?.hasSubscription) {
|
||||
return CLOUD_FREE_WEBSITE_LIMIT;
|
||||
@@ -28,3 +31,19 @@ export function getCloudWebsiteLimit(account?: SubscriptionAccount | null): numb
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getCloudTeamLimit(account?: SubscriptionAccount | null): number | null {
|
||||
if (!account?.hasSubscription) {
|
||||
return CLOUD_FREE_TEAM_LIMIT;
|
||||
}
|
||||
|
||||
if (account.isNoBilling || account.isBusiness) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (account.isPro) {
|
||||
return CLOUD_PRO_TEAM_LIMIT;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in new issue
Block a user