Add trial rollout date fallback
This commit is contained in:
parent
8fc463313d
commit
a735c063ab
2 changed files with 25 additions and 4 deletions
|
|
@ -3,9 +3,25 @@ import {
|
|||
getBillableMemberCount,
|
||||
getOrganizationOwner,
|
||||
getTrialWindow,
|
||||
parseTrialRolloutDate,
|
||||
} from "../../helpers/billing.js";
|
||||
|
||||
describe("billing helpers", () => {
|
||||
it("falls back to default rollout date when env value is missing", () => {
|
||||
const rolloutAt = parseTrialRolloutDate(undefined);
|
||||
expect(rolloutAt?.toISOString()).toBe("2026-03-08T00:00:00.000Z");
|
||||
});
|
||||
|
||||
it("falls back to default rollout date when env value is invalid", () => {
|
||||
const rolloutAt = parseTrialRolloutDate("not-a-date");
|
||||
expect(rolloutAt?.toISOString()).toBe("2026-03-08T00:00:00.000Z");
|
||||
});
|
||||
|
||||
it("uses configured rollout date when env value is valid", () => {
|
||||
const rolloutAt = parseTrialRolloutDate("2026-03-10T00:00:00.000Z");
|
||||
expect(rolloutAt?.toISOString()).toBe("2026-03-10T00:00:00.000Z");
|
||||
});
|
||||
|
||||
it("returns the earliest organization member as billing owner", () => {
|
||||
const owner = getOrganizationOwner([
|
||||
{
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ export type OrganizationBillingState = {
|
|||
|
||||
const ACTIVE_BILLING_STATUSES = ["active", "trialing", "past_due"];
|
||||
const DEFAULT_BILLING_TRIAL_DAYS = 14;
|
||||
const DEFAULT_BILLING_TRIAL_ROLLOUT_AT = "2026-03-08T00:00:00.000Z";
|
||||
|
||||
const parseTrialDays = () => {
|
||||
const parsed = Number.parseInt(process.env.BILLING_TRIAL_DAYS ?? "", 10);
|
||||
|
|
@ -65,15 +66,19 @@ const parseTrialDays = () => {
|
|||
return parsed;
|
||||
};
|
||||
|
||||
const parseTrialRolloutDate = () => {
|
||||
const raw = process.env.BILLING_TRIAL_ROLLOUT_AT;
|
||||
export const parseTrialRolloutDate = (
|
||||
rawInput: string | null | undefined = process.env.BILLING_TRIAL_ROLLOUT_AT
|
||||
) => {
|
||||
const raw = rawInput?.trim();
|
||||
const fallback = new Date(DEFAULT_BILLING_TRIAL_ROLLOUT_AT);
|
||||
|
||||
if (!raw) {
|
||||
return null;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const parsed = new Date(raw);
|
||||
if (Number.isNaN(parsed.getTime())) {
|
||||
return null;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return parsed;
|
||||
|
|
|
|||
Loading…
Reference in a new issue