@lizard-build/cli 4.0.89 → 4.0.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/commands/billing.d.ts +19 -0
- package/dist/commands/billing.js +88 -16
- package/dist/commands/billing.js.map +1 -1
- package/dist/lib/skills-data.generated.js +3 -3
- package/dist/lib/skills-data.generated.js.map +1 -1
- package/dist/lib/updater.d.ts +1 -1
- package/dist/lib/updater.js +1 -1
- package/package.json +1 -1
- package/skill-data/core/SKILL.md +17 -8
- package/skill-data/core/references/sandboxes.md +1 -1
- package/skill-data/core/references/sdk.md +1 -1
- package/src/commands/billing.ts +112 -17
- package/src/lib/updater.ts +1 -1
- package/test/unit/billing.test.ts +99 -10
package/src/commands/billing.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { api, withQuery, getBaseURL, isNotFound } from "../lib/api.js";
|
|
|
6
6
|
import { success, isJSONMode, printJSON, table, isTTY, timeAgo, info, warn } from "../lib/format.js";
|
|
7
7
|
|
|
8
8
|
// `lizard billing` — the account's plan (docs/pro-billing-api.md on the platform
|
|
9
|
-
// repo). Pro is $19/month
|
|
10
|
-
// that is pay as you go. Unlike most commands this never takes --project/--service:
|
|
9
|
+
// repo). Pro is $19/month with $19 of usage included each month (Pro 5x $99, Pro 20x
|
|
10
|
+
// $499, on the same terms); usage above that is pay as you go. Unlike most commands this never takes --project/--service:
|
|
11
11
|
// billing belongs to the account, not a workspace. `lizard credits` is the old name.
|
|
12
12
|
|
|
13
13
|
/** Old prepaid credits (`plan: "payg"`) keep working until this date. */
|
|
@@ -22,9 +22,15 @@ export interface Subscription {
|
|
|
22
22
|
plan: "none" | "pro" | "payg" | "enterprise" | string;
|
|
23
23
|
status: "none" | "trialing" | "active" | "past_due" | "canceled" | string;
|
|
24
24
|
isOwner?: boolean;
|
|
25
|
+
/** "pro" | "pro_99" | "pro_499"; null without a live subscription. Older servers omit it. */
|
|
26
|
+
tier?: string | null;
|
|
27
|
+
/** A move to a lower tier that starts with the next period. */
|
|
28
|
+
pendingTier?: string | null;
|
|
29
|
+
/** Of the current tier. */
|
|
25
30
|
priceCents: number;
|
|
26
31
|
taxIncluded: boolean;
|
|
27
32
|
includedCents: number;
|
|
33
|
+
tiers?: TierOption[];
|
|
28
34
|
trial: {
|
|
29
35
|
eligible: boolean;
|
|
30
36
|
days: number | null;
|
|
@@ -50,10 +56,46 @@ export interface Subscription {
|
|
|
50
56
|
pastDue: boolean;
|
|
51
57
|
openInvoiceUrl: string | null;
|
|
52
58
|
paymentMethod: { brand: string; last4: string; expMonth: number; expYear: number } | null;
|
|
53
|
-
limits: { tier: string; replicasPerApp: number } | null;
|
|
59
|
+
limits: { tier: string; replicasPerApp: number; sandboxVcpu?: number; maxSandboxCpus?: number } | null;
|
|
54
60
|
checkoutAvailable: boolean;
|
|
55
61
|
}
|
|
56
62
|
|
|
63
|
+
export interface TierOption {
|
|
64
|
+
tier: string;
|
|
65
|
+
priceCents: number;
|
|
66
|
+
includedCents: number;
|
|
67
|
+
sandboxVcpu: number;
|
|
68
|
+
trial: boolean;
|
|
69
|
+
available: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface TierChange {
|
|
73
|
+
status: "upgraded" | "scheduled" | "unchanged" | "requires_action" | string;
|
|
74
|
+
tier: string;
|
|
75
|
+
pendingTier: string | null;
|
|
76
|
+
effectiveAt: number | null;
|
|
77
|
+
invoiceUrl: string | null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Pro's tiers: what the API calls them, what people call them, and what `lizard billing tier` takes. */
|
|
81
|
+
const TIERS = [
|
|
82
|
+
{ tier: "pro", label: "Pro", arg: "pro", aliases: ["pro", "1x", "19"] },
|
|
83
|
+
{ tier: "pro_99", label: "Pro 5x", arg: "5x", aliases: ["5x", "pro-5x", "pro5x", "pro_99", "99"] },
|
|
84
|
+
{ tier: "pro_499", label: "Pro 20x", arg: "20x", aliases: ["20x", "pro-20x", "pro20x", "pro_499", "499"] },
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
export function tierLabel(tier: string | null | undefined): string {
|
|
88
|
+
return TIERS.find((t) => t.tier === tier)?.label ?? "Pro";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** `5x`, `pro-5x`, `pro_99` → `pro_99`. */
|
|
92
|
+
export function parseTier(input: string): string {
|
|
93
|
+
const key = input.trim().toLowerCase().replace(/\s+/g, "-");
|
|
94
|
+
const found = TIERS.find((t) => t.aliases.includes(key));
|
|
95
|
+
if (!found) throw new Error(`Unknown tier "${input}". Use pro, 5x or 20x.`);
|
|
96
|
+
return found.tier;
|
|
97
|
+
}
|
|
98
|
+
|
|
57
99
|
interface BalanceView {
|
|
58
100
|
plan: string;
|
|
59
101
|
status: "active" | "grace" | "frozen";
|
|
@@ -165,14 +207,14 @@ export function describeSubscription(sub: Subscription, now = Date.now()): strin
|
|
|
165
207
|
lines.push("Pro is not open for this account yet.");
|
|
166
208
|
} else if (sub.trial.eligible && sub.trial.days) {
|
|
167
209
|
lines.push(
|
|
168
|
-
`Start a ${sub.trial.days}-day Pro trial with ${usd(sub.trial.creditCents ?? 0)}
|
|
210
|
+
`Start a ${sub.trial.days}-day Pro trial with ${usd(sub.trial.creditCents ?? 0)} of usage: ` +
|
|
169
211
|
chalk.cyan("lizard billing start"),
|
|
170
212
|
);
|
|
171
213
|
lines.push(chalk.dim(`No charge today, then ${usd(sub.priceCents)}/month.`));
|
|
172
214
|
if (sub.trial.promoCode) lines.push(label("Promo code: ") + `${sub.trial.promoCode} (saved for the trial)`);
|
|
173
215
|
} else {
|
|
174
216
|
lines.push(
|
|
175
|
-
`Start Pro: ${usd(sub.priceCents)}/month, with ${usd(sub.includedCents)}
|
|
217
|
+
`Start Pro: ${usd(sub.priceCents)}/month, with ${usd(sub.includedCents)} of usage included each month: ` +
|
|
176
218
|
chalk.cyan("lizard billing start"),
|
|
177
219
|
);
|
|
178
220
|
}
|
|
@@ -180,7 +222,7 @@ export function describeSubscription(sub: Subscription, now = Date.now()): strin
|
|
|
180
222
|
}
|
|
181
223
|
|
|
182
224
|
lines.push(
|
|
183
|
-
`${chalk.bold(
|
|
225
|
+
`${chalk.bold(tierLabel(sub.tier))} ${statusLabel(sub.status)}${owner} ` +
|
|
184
226
|
chalk.dim(`${usd(sub.priceCents)}/month`),
|
|
185
227
|
);
|
|
186
228
|
|
|
@@ -190,7 +232,7 @@ export function describeSubscription(sub: Subscription, now = Date.now()): strin
|
|
|
190
232
|
const credit = sub.trial.creditCents ?? period?.includedCents ?? 0;
|
|
191
233
|
const used = sub.trial.usedCents ?? period?.usedCents ?? 0;
|
|
192
234
|
const left = sub.trial.remainingCents ?? Math.max(0, credit - used);
|
|
193
|
-
lines.push(label("Trial
|
|
235
|
+
lines.push(label("Trial usage: ") + `${usd(used)} of ${usd(credit)} used, ${usd(left)} left`);
|
|
194
236
|
} else if (period) {
|
|
195
237
|
lines.push(
|
|
196
238
|
label("This month: ") +
|
|
@@ -212,6 +254,14 @@ export function describeSubscription(sub: Subscription, now = Date.now()): strin
|
|
|
212
254
|
if (sub.nextCharge?.at) {
|
|
213
255
|
lines.push(label("Next charge: ") + `${usd(sub.nextCharge.amountCents)} on ${fmtDate(sub.nextCharge.at)}`);
|
|
214
256
|
}
|
|
257
|
+
if (sub.pendingTier && sub.pendingTier !== sub.tier) {
|
|
258
|
+
const when = period ? ` on ${fmtDate(period.end)}` : " with the next period";
|
|
259
|
+
const stay = TIERS.find((t) => t.tier === sub.tier)?.arg ?? "pro";
|
|
260
|
+
lines.push(
|
|
261
|
+
label("Next period: ") + `moves to ${tierLabel(sub.pendingTier)}${when}. Run ` +
|
|
262
|
+
chalk.cyan(`lizard billing tier ${stay}`) + ` to stay on ${tierLabel(sub.tier)}.`,
|
|
263
|
+
);
|
|
264
|
+
}
|
|
215
265
|
if (sub.cancelAt) {
|
|
216
266
|
lines.push(chalk.yellow(`Ends on ${fmtDate(sub.cancelAt)}.`) + " Run " + chalk.cyan("lizard billing resume") + " to keep Pro.");
|
|
217
267
|
}
|
|
@@ -222,6 +272,9 @@ export function describeSubscription(sub: Subscription, now = Date.now()): strin
|
|
|
222
272
|
if (sub.limits) {
|
|
223
273
|
const n = sub.limits.replicasPerApp;
|
|
224
274
|
lines.push(label("Replicas: ") + `up to ${n} per service`);
|
|
275
|
+
if (sub.limits.sandboxVcpu) {
|
|
276
|
+
lines.push(label("Sandboxes: ") + `up to ${sub.limits.sandboxVcpu.toLocaleString("en-US")} vCPU at once`);
|
|
277
|
+
}
|
|
225
278
|
}
|
|
226
279
|
if (sub.paymentMethod) {
|
|
227
280
|
const pm = sub.paymentMethod;
|
|
@@ -338,10 +391,10 @@ export function describePromo(out: PromoResult): string {
|
|
|
338
391
|
const credits = usd(out.trialCreditCents ?? out.creditCents);
|
|
339
392
|
if (out.appliesTo === "current_trial") {
|
|
340
393
|
const until = out.expiresAt ? `, until ${fmtDate(out.expiresAt)}` : "";
|
|
341
|
-
return `Your trial now runs ${out.trialDays} days with ${credits}
|
|
394
|
+
return `Your trial now runs ${out.trialDays} days with ${credits} of usage${until}.`;
|
|
342
395
|
}
|
|
343
396
|
const code = out.code ? `Code ${out.code} saved: ` : "Code saved: ";
|
|
344
|
-
return `${code}a ${out.trialDays}-day Pro trial with ${credits}
|
|
397
|
+
return `${code}a ${out.trialDays}-day Pro trial with ${credits} of usage. Start it with \`lizard billing start\`.`;
|
|
345
398
|
}
|
|
346
399
|
if (out.status === "pending_payment_method") {
|
|
347
400
|
return `Code saved: ${fmtCents(out.creditCents)} in credits. They unlock when you start your trial in Billing.`;
|
|
@@ -353,7 +406,7 @@ export function registerBilling(program: Command) {
|
|
|
353
406
|
const cmd = program
|
|
354
407
|
.command("billing")
|
|
355
408
|
.alias("credits")
|
|
356
|
-
.description("Your plan: Pro trial, this month's
|
|
409
|
+
.description("Your plan: Pro tier, trial, this month's usage, next charge, cancel or resume (`credits` is the old name)")
|
|
357
410
|
.option("-w, --workspace <id>", "Show the plan of this workspace's owner")
|
|
358
411
|
.action(async () => {
|
|
359
412
|
await showStatus(cmd.opts());
|
|
@@ -367,7 +420,7 @@ export function registerBilling(program: Command) {
|
|
|
367
420
|
|
|
368
421
|
cmd
|
|
369
422
|
.command("status")
|
|
370
|
-
.description("Show the plan, trial, this month's
|
|
423
|
+
.description("Show the plan, trial, this month's usage and the next charge")
|
|
371
424
|
.option("-w, --workspace <id>", "Show the plan of this workspace's owner")
|
|
372
425
|
.action(async (opts) => {
|
|
373
426
|
// `billing` takes -w too and claims it wherever it appears on the line.
|
|
@@ -392,20 +445,24 @@ export function registerBilling(program: Command) {
|
|
|
392
445
|
.command("start")
|
|
393
446
|
.description("Start Pro in Stripe Checkout: the trial if the account can have one, otherwise Pro at once")
|
|
394
447
|
.option("--return-url <path>", "Dashboard path to come back to after Checkout, e.g. /projects/abc")
|
|
448
|
+
.option("--tier <tier>", "pro (default), 5x ($99/month) or 20x ($499/month); 5x and 20x have no trial")
|
|
395
449
|
.option("--no-open", "Print the Checkout link instead of opening a browser")
|
|
396
450
|
.action(async (opts) => {
|
|
397
|
-
const
|
|
451
|
+
const tier = opts.tier ? parseTier(opts.tier) : undefined;
|
|
452
|
+
const out = await api.post<CheckoutResult>("/api/billing/subscription/checkout", { returnUrl: opts.returnUrl, tier });
|
|
398
453
|
if (isJSONMode()) {
|
|
399
454
|
printJSON(out);
|
|
400
455
|
return;
|
|
401
456
|
}
|
|
402
457
|
if (out.trialDays) {
|
|
403
458
|
console.log(
|
|
404
|
-
`Your ${out.trialDays}-day trial includes ${usd(out.trialCreditCents ?? 0)}
|
|
459
|
+
`Your ${out.trialDays}-day trial includes ${usd(out.trialCreditCents ?? 0)} of usage. ` +
|
|
405
460
|
"No charge today, then $19/month.",
|
|
406
461
|
);
|
|
462
|
+
} else if (tier && tier !== "pro") {
|
|
463
|
+
console.log(`${tierLabel(tier)} starts today and is charged from day one.`);
|
|
407
464
|
} else {
|
|
408
|
-
console.log("Pro starts today: $19/month, with $19
|
|
465
|
+
console.log("Pro starts today: $19/month, with $19 of usage included each month.");
|
|
409
466
|
}
|
|
410
467
|
console.log(`Finish in Stripe Checkout:\n${chalk.cyan(out.url)}`);
|
|
411
468
|
await openInBrowser(out.url, opts.open !== false);
|
|
@@ -414,7 +471,7 @@ export function registerBilling(program: Command) {
|
|
|
414
471
|
|
|
415
472
|
cmd
|
|
416
473
|
.command("start-now")
|
|
417
|
-
.description("End the trial now: charge $19 and start the first paid month with $19
|
|
474
|
+
.description("End the trial now: charge $19 and start the first paid month with $19 of usage included")
|
|
418
475
|
.option("-y, --yes", "Skip confirmation")
|
|
419
476
|
.option("--no-open", "Print the payment link instead of opening a browser")
|
|
420
477
|
.action(async (opts) => {
|
|
@@ -435,7 +492,45 @@ export function registerBilling(program: Command) {
|
|
|
435
492
|
await openInBrowser(out.invoiceUrl, opts.open !== false);
|
|
436
493
|
return;
|
|
437
494
|
}
|
|
438
|
-
success("Pro is active. We charged $19 and
|
|
495
|
+
success("Pro is active. We charged $19, and this month includes $19 of usage.");
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
cmd
|
|
499
|
+
.command("tier <tier>")
|
|
500
|
+
.description("Move a paid Pro subscription to pro, 5x ($99/month) or 20x ($499/month): up is charged now, prorated; down starts with the next period")
|
|
501
|
+
.option("-y, --yes", "Skip confirmation")
|
|
502
|
+
.option("--no-open", "Print the payment link instead of opening a browser")
|
|
503
|
+
.action(async (input: string, opts) => {
|
|
504
|
+
const tier = parseTier(input);
|
|
505
|
+
const sub = await api.get<Subscription>("/api/billing/subscription");
|
|
506
|
+
const name = tierLabel(tier);
|
|
507
|
+
const price = (t: string | null | undefined) => sub.tiers?.find((o) => o.tier === t)?.priceCents ?? 0;
|
|
508
|
+
if (tier !== sub.tier || sub.pendingTier) {
|
|
509
|
+
const question = tier === sub.tier
|
|
510
|
+
? `Stay on ${name}? The move to ${tierLabel(sub.pendingTier)} is cancelled.`
|
|
511
|
+
: price(tier) > price(sub.tier)
|
|
512
|
+
? `Move to ${name} now? We charge the prorated difference today, and your included usage and limits rise at once.`
|
|
513
|
+
: `Move to ${name} from the next period? Nothing is charged today.`;
|
|
514
|
+
await confirmOrExit(question, opts.yes);
|
|
515
|
+
}
|
|
516
|
+
const out = await api.post<TierChange>("/api/billing/subscription/tier", { tier });
|
|
517
|
+
if (isJSONMode()) {
|
|
518
|
+
printJSON(out);
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (out.status === "requires_action" && out.invoiceUrl) {
|
|
522
|
+
console.log(`Your bank needs you to confirm the payment. You stay on ${tierLabel(sub.tier)} until you do:\n${chalk.cyan(out.invoiceUrl)}`);
|
|
523
|
+
await openInBrowser(out.invoiceUrl, opts.open !== false);
|
|
524
|
+
} else if (out.status === "upgraded") {
|
|
525
|
+
success(`You are on ${name} now. We charged the prorated difference, and this month's included usage rose by the same amount.`);
|
|
526
|
+
} else if (out.status === "scheduled") {
|
|
527
|
+
const when = out.effectiveAt ? `on ${fmtDate(out.effectiveAt)}` : "with the next period";
|
|
528
|
+
success(`${name} starts ${when}. Until then you keep ${tierLabel(sub.tier)}.`);
|
|
529
|
+
} else if (sub.pendingTier && sub.pendingTier !== tier) {
|
|
530
|
+
success(`You stay on ${name}. The move to ${tierLabel(sub.pendingTier)} is cancelled.`);
|
|
531
|
+
} else {
|
|
532
|
+
info(`You are already on ${name}.`);
|
|
533
|
+
}
|
|
439
534
|
});
|
|
440
535
|
|
|
441
536
|
cmd
|
|
@@ -470,7 +565,7 @@ export function registerBilling(program: Command) {
|
|
|
470
565
|
|
|
471
566
|
cmd
|
|
472
567
|
.command("promo <code>")
|
|
473
|
-
.description("Redeem a promo code: a longer Pro trial with more trial
|
|
568
|
+
.description("Redeem a promo code: a longer Pro trial with more trial usage")
|
|
474
569
|
.action(async (code: string) => {
|
|
475
570
|
const out = await api.post<PromoResult>("/api/billing/promo/redeem", { code });
|
|
476
571
|
if (isJSONMode()) {
|
package/src/lib/updater.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { join, dirname } from "node:path";
|
|
|
5
5
|
import os from "node:os";
|
|
6
6
|
import { spawn } from "node:child_process";
|
|
7
7
|
|
|
8
|
-
export const CURRENT_VERSION = "4.0.
|
|
8
|
+
export const CURRENT_VERSION = "4.0.90";
|
|
9
9
|
const RELEASES_API = "https://api.github.com/repos/lizard-build/lizard-cli/releases/latest";
|
|
10
10
|
const RELEASE_BASE = "https://github.com/lizard-build/lizard-cli/releases/latest/download";
|
|
11
11
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
-
import { registerBilling, describePromo, type Subscription } from "../../src/commands/billing.js";
|
|
3
|
+
import { registerBilling, describePromo, parseTier, type Subscription, type TierOption } from "../../src/commands/billing.js";
|
|
4
4
|
import { setAccessToken, setBaseURL } from "../../src/lib/api.js";
|
|
5
5
|
import { setJSONMode } from "../../src/lib/format.js";
|
|
6
6
|
|
|
@@ -75,6 +75,12 @@ const paid: Subscription = {
|
|
|
75
75
|
limits: { tier: "pro", replicasPerApp: 5 },
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
+
const tiers: TierOption[] = [
|
|
79
|
+
{ tier: "pro", priceCents: 1900, includedCents: 1900, sandboxVcpu: 40, trial: true, available: true },
|
|
80
|
+
{ tier: "pro_99", priceCents: 9900, includedCents: 9900, sandboxVcpu: 220, trial: false, available: true },
|
|
81
|
+
{ tier: "pro_499", priceCents: 49900, includedCents: 49900, sandboxVcpu: 1200, trial: false, available: true },
|
|
82
|
+
];
|
|
83
|
+
|
|
78
84
|
const none: Subscription = {
|
|
79
85
|
...base,
|
|
80
86
|
plan: "none",
|
|
@@ -112,14 +118,14 @@ afterEach(() => {
|
|
|
112
118
|
});
|
|
113
119
|
|
|
114
120
|
describe("lizard billing (status)", () => {
|
|
115
|
-
test("a trial shows days left, trial
|
|
121
|
+
test("a trial shows days left, trial usage, the next charge and the Billing link", async () => {
|
|
116
122
|
routes({ "GET /api/billing/subscription": () => reply(200, base) });
|
|
117
123
|
await run(["billing"]);
|
|
118
124
|
const text = out();
|
|
119
125
|
expect(text).toContain("Pro trial");
|
|
120
126
|
expect(text).toContain("$19/month");
|
|
121
127
|
expect(text).toContain("Trial: 5 days left");
|
|
122
|
-
expect(text).toContain("Trial
|
|
128
|
+
expect(text).toContain("Trial usage: $1.20 of $5 used, $3.80 left");
|
|
123
129
|
expect(text).toMatch(/Next charge: \$19 on \w{3} \d+, \d{4}/);
|
|
124
130
|
expect(text).toContain("Replicas: up to 1 per service");
|
|
125
131
|
expect(text).toContain("Card: visa •••• 4242");
|
|
@@ -153,12 +159,27 @@ describe("lizard billing (status)", () => {
|
|
|
153
159
|
expect(text).not.toContain("Next charge");
|
|
154
160
|
});
|
|
155
161
|
|
|
162
|
+
test("a paid tier shows its name, a pending move down and the vCPU limit", async () => {
|
|
163
|
+
routes({
|
|
164
|
+
"GET /api/billing/subscription": () => reply(200, {
|
|
165
|
+
...paid, tier: "pro_499", pendingTier: "pro_99", priceCents: 49900, includedCents: 49900, tiers,
|
|
166
|
+
limits: { tier: "pro_499", replicasPerApp: 5, sandboxVcpu: 1200, maxSandboxCpus: 8 },
|
|
167
|
+
}),
|
|
168
|
+
});
|
|
169
|
+
await run(["billing"]);
|
|
170
|
+
const text = out();
|
|
171
|
+
expect(text).toContain("Pro 20x active");
|
|
172
|
+
expect(text).toContain("$499/month");
|
|
173
|
+
expect(text).toMatch(/Next period: moves to Pro 5x on \w{3} \d+, \d{4}\. Run lizard billing tier 20x to stay on Pro 20x\./);
|
|
174
|
+
expect(text).toContain("Sandboxes: up to 1,200 vCPU at once");
|
|
175
|
+
});
|
|
176
|
+
|
|
156
177
|
test("no plan offers the trial", async () => {
|
|
157
178
|
routes({ "GET /api/billing/subscription": () => reply(200, { ...none, trial: { ...none.trial, promoCode: "ROST", days: 31, creditCents: 10000 } }) });
|
|
158
179
|
await run(["billing"]);
|
|
159
180
|
const text = out();
|
|
160
181
|
expect(text).toContain("No plan");
|
|
161
|
-
expect(text).toContain("Start a 31-day Pro trial with $100
|
|
182
|
+
expect(text).toContain("Start a 31-day Pro trial with $100 of usage: lizard billing start");
|
|
162
183
|
expect(text).toContain("No charge today, then $19/month.");
|
|
163
184
|
expect(text).toContain("Promo code: ROST");
|
|
164
185
|
});
|
|
@@ -167,7 +188,7 @@ describe("lizard billing (status)", () => {
|
|
|
167
188
|
routes({ "GET /api/billing/subscription": () => reply(200, { ...none, status: "canceled", trial: { ...none.trial, eligible: false } }) });
|
|
168
189
|
await run(["billing"]);
|
|
169
190
|
expect(out()).toContain("Pro has ended.");
|
|
170
|
-
expect(out()).toContain("Start Pro: $19/month, with $19
|
|
191
|
+
expect(out()).toContain("Start Pro: $19/month, with $19 of usage included each month: lizard billing start");
|
|
171
192
|
});
|
|
172
193
|
|
|
173
194
|
test("enterprise is invoiced monthly", async () => {
|
|
@@ -249,7 +270,7 @@ describe("lizard billing actions", () => {
|
|
|
249
270
|
});
|
|
250
271
|
await run(["billing", "start", "--return-url", "/projects/abc", "--no-open"]);
|
|
251
272
|
expect(calls()).toEqual([{ key: "POST /api/billing/subscription/checkout", body: { returnUrl: "/projects/abc" } }]);
|
|
252
|
-
expect(out()).toContain("Your 7-day trial includes $5
|
|
273
|
+
expect(out()).toContain("Your 7-day trial includes $5 of usage. No charge today, then $19/month.");
|
|
253
274
|
expect(out()).toContain("https://checkout.stripe.com/c/pay/cs_1");
|
|
254
275
|
});
|
|
255
276
|
|
|
@@ -257,13 +278,73 @@ describe("lizard billing actions", () => {
|
|
|
257
278
|
const session = { url: "https://checkout.stripe.com/c/pay/cs_2", sessionId: "cs_2", trialDays: null, trialCreditCents: null };
|
|
258
279
|
routes({ "POST /api/billing/subscription/checkout": () => reply(200, session) });
|
|
259
280
|
await run(["billing", "start", "--no-open"]);
|
|
260
|
-
expect(out()).toContain("Pro starts today: $19/month, with $19
|
|
281
|
+
expect(out()).toContain("Pro starts today: $19/month, with $19 of usage included each month.");
|
|
261
282
|
setJSONMode(true);
|
|
262
283
|
stdout = [];
|
|
263
284
|
await run(["billing", "start"]);
|
|
264
285
|
expect(JSON.parse(stdout.join("\n"))).toEqual(session);
|
|
265
286
|
});
|
|
266
287
|
|
|
288
|
+
test("start --tier opens Checkout for Pro 5x, charged from day one", async () => {
|
|
289
|
+
routes({ "POST /api/billing/subscription/checkout": () => reply(200, { url: "https://checkout.stripe.com/c/pay/cs_5", sessionId: "cs_5", trialDays: null, trialCreditCents: null }) });
|
|
290
|
+
await run(["billing", "start", "--tier", "5x", "--no-open"]);
|
|
291
|
+
expect(calls()).toEqual([{ key: "POST /api/billing/subscription/checkout", body: { tier: "pro_99" } }]);
|
|
292
|
+
expect(out()).toContain("Pro 5x starts today and is charged from day one.");
|
|
293
|
+
await expect(run(["billing", "start", "--tier", "10x"])).rejects.toThrow('Unknown tier "10x". Use pro, 5x or 20x.');
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test("tier moves up now, down next period, and cancels a pending move", async () => {
|
|
297
|
+
const at = Date.UTC(2026, 10, 20, 12);
|
|
298
|
+
const onPro = { ...paid, tier: "pro", pendingTier: null, tiers };
|
|
299
|
+
routes({
|
|
300
|
+
"GET /api/billing/subscription": () => reply(200, onPro),
|
|
301
|
+
"POST /api/billing/subscription/tier": () => reply(200, { status: "upgraded", tier: "pro_99", pendingTier: null, effectiveAt: now, invoiceUrl: null }),
|
|
302
|
+
});
|
|
303
|
+
await expect(run(["billing", "tier", "5x"])).rejects.toThrow("Use -y to confirm");
|
|
304
|
+
await run(["billing", "tier", "5x", "-y"]);
|
|
305
|
+
expect(calls().at(-1)).toEqual({ key: "POST /api/billing/subscription/tier", body: { tier: "pro_99" } });
|
|
306
|
+
expect(err()).toContain("You are on Pro 5x now.");
|
|
307
|
+
|
|
308
|
+
routes({
|
|
309
|
+
"GET /api/billing/subscription": () => reply(200, { ...onPro, tier: "pro_99" }),
|
|
310
|
+
"POST /api/billing/subscription/tier": () => reply(200, { status: "scheduled", tier: "pro_99", pendingTier: "pro", effectiveAt: at, invoiceUrl: null }),
|
|
311
|
+
});
|
|
312
|
+
await run(["billing", "tier", "pro", "-y"]);
|
|
313
|
+
expect(err()).toContain("Pro starts on Nov 20, 2026. Until then you keep Pro 5x.");
|
|
314
|
+
|
|
315
|
+
routes({
|
|
316
|
+
"GET /api/billing/subscription": () => reply(200, { ...onPro, tier: "pro_99", pendingTier: "pro" }),
|
|
317
|
+
"POST /api/billing/subscription/tier": () => reply(200, { status: "unchanged", tier: "pro_99", pendingTier: null, effectiveAt: null, invoiceUrl: null }),
|
|
318
|
+
});
|
|
319
|
+
await run(["billing", "tier", "pro-5x", "-y"]);
|
|
320
|
+
expect(err()).toContain("You stay on Pro 5x. The move to Pro is cancelled.");
|
|
321
|
+
|
|
322
|
+
routes({
|
|
323
|
+
"GET /api/billing/subscription": () => reply(200, onPro),
|
|
324
|
+
"POST /api/billing/subscription/tier": () => reply(200, { status: "requires_action", tier: "pro", pendingTier: null, effectiveAt: null, invoiceUrl: "https://invoice.stripe.com/i/up" }),
|
|
325
|
+
});
|
|
326
|
+
await run(["billing", "tier", "20x", "-y", "--no-open"]);
|
|
327
|
+
expect(out()).toContain("Your bank needs you to confirm the payment. You stay on Pro until you do:");
|
|
328
|
+
expect(out()).toContain("https://invoice.stripe.com/i/up");
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test("tier on the current tier asks nothing and says so", async () => {
|
|
332
|
+
routes({
|
|
333
|
+
"GET /api/billing/subscription": () => reply(200, { ...paid, tier: "pro", pendingTier: null, tiers }),
|
|
334
|
+
"POST /api/billing/subscription/tier": () => reply(200, { status: "unchanged", tier: "pro", pendingTier: null, effectiveAt: null, invoiceUrl: null }),
|
|
335
|
+
});
|
|
336
|
+
await run(["billing", "tier", "pro"]);
|
|
337
|
+
expect(err()).toContain("You are already on Pro.");
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test("tier passes the platform's refusal through", async () => {
|
|
341
|
+
routes({
|
|
342
|
+
"GET /api/billing/subscription": () => reply(200, { ...base, tier: "pro", tiers }),
|
|
343
|
+
"POST /api/billing/subscription/tier": () => reply(409, { error: "TRIAL_ACTIVE", message: "Start Pro now to change tiers." }),
|
|
344
|
+
});
|
|
345
|
+
await expect(run(["billing", "tier", "5x", "-y"])).rejects.toMatchObject({ status: 409, code: "TRIAL_ACTIVE" });
|
|
346
|
+
});
|
|
347
|
+
|
|
267
348
|
test("start passes the platform's refusal through", async () => {
|
|
268
349
|
routes({
|
|
269
350
|
"POST /api/billing/subscription/checkout": () => reply(409, { error: "ALREADY_SUBSCRIBED", message: "This account already has Pro" }),
|
|
@@ -279,7 +360,7 @@ describe("lizard billing actions", () => {
|
|
|
279
360
|
test("start-now charges and reports each outcome", async () => {
|
|
280
361
|
routes({ "POST /api/billing/subscription/start-now": () => reply(200, { status: "active" }) });
|
|
281
362
|
await run(["billing", "start-now", "-y"]);
|
|
282
|
-
expect(err()).toContain("Pro is active. We charged $19 and
|
|
363
|
+
expect(err()).toContain("Pro is active. We charged $19, and this month includes $19 of usage.");
|
|
283
364
|
|
|
284
365
|
routes({ "POST /api/billing/subscription/start-now": () => reply(200, { status: "requires_action", invoiceUrl: "https://invoice.stripe.com/i/3ds" }) });
|
|
285
366
|
await run(["billing", "start-now", "-y", "--no-open"]);
|
|
@@ -313,7 +394,7 @@ describe("lizard billing actions", () => {
|
|
|
313
394
|
});
|
|
314
395
|
await run(["billing", "promo", "ROST"]);
|
|
315
396
|
expect(calls()).toEqual([{ key: "POST /api/billing/promo/redeem", body: { code: "ROST" } }]);
|
|
316
|
-
expect(err()).toContain("Code ROST saved: a 31-day Pro trial with $100
|
|
397
|
+
expect(err()).toContain("Code ROST saved: a 31-day Pro trial with $100 of usage. Start it with `lizard billing start`.");
|
|
317
398
|
});
|
|
318
399
|
|
|
319
400
|
test("promo errors keep their code", async () => {
|
|
@@ -330,12 +411,20 @@ describe("lizard billing actions", () => {
|
|
|
330
411
|
});
|
|
331
412
|
});
|
|
332
413
|
|
|
414
|
+
describe("parseTier", () => {
|
|
415
|
+
test("takes the names people type", () => {
|
|
416
|
+
expect(["pro", "1x", "Pro"].map(parseTier)).toEqual(["pro", "pro", "pro"]);
|
|
417
|
+
expect(["5x", "pro-5x", "Pro 5x", "pro_99", "99"].map(parseTier)).toEqual(Array(5).fill("pro_99"));
|
|
418
|
+
expect(["20x", "pro-20x", "pro_499", "499"].map(parseTier)).toEqual(Array(4).fill("pro_499"));
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
|
|
333
422
|
describe("describePromo", () => {
|
|
334
423
|
test("a code applied to the running trial", () => {
|
|
335
424
|
expect(describePromo({
|
|
336
425
|
status: "applied", code: "ROST", creditCents: 10000, expiresAt: Date.UTC(2026, 10, 7, 12), balanceCents: 0,
|
|
337
426
|
trialDays: 31, trialCreditCents: 10000, appliesTo: "current_trial",
|
|
338
|
-
})).toBe("Your trial now runs 31 days with $100
|
|
427
|
+
})).toBe("Your trial now runs 31 days with $100 of usage, until Nov 7, 2026.");
|
|
339
428
|
});
|
|
340
429
|
|
|
341
430
|
test("an older server's answers", () => {
|