Skip to content

Commit d21877e

Browse files
feat(cli): billing top-up is renamed to add-credits with no alias (#7121)
1 parent e46ecd8 commit d21877e

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

‎packages/cli/src/commands/billing.test.ts‎

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,30 @@ describe("billing subscribe", () => {
6666
});
6767

6868
describe("billing add-credits", () => {
69-
it.each(["add-credits", "top-up"])(
70-
"opens the credits page for `%s`, with no notice",
71-
async (name) => {
72-
vi.stubEnv("HYPERFRAMES_PLANS_URL", "https://plans.test/p");
73-
vi.stubEnv("HYPERFRAMES_CREDITS_URL", "https://credits.test/c");
74-
const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
75-
const error = vi.spyOn(console, "error").mockImplementation(() => undefined);
76-
vi.useFakeTimers();
77-
const done = runCommand(billing, { rawArgs: [name] });
78-
await vi.advanceTimersByTimeAsync(2000);
79-
await done;
80-
vi.useRealTimers();
81-
vi.unstubAllEnvs();
82-
expect(new URL(opened[0] ?? "").origin).toBe("https://credits.test");
83-
expect(error).not.toHaveBeenCalled();
84-
expect(log.mock.calls.flat().join("\n")).not.toMatch(/deprecat|renamed|top-up/i);
85-
},
86-
);
69+
it("opens the credits page", async () => {
70+
vi.stubEnv("HYPERFRAMES_PLANS_URL", "https://plans.test/p");
71+
vi.stubEnv("HYPERFRAMES_CREDITS_URL", "https://credits.test/c");
72+
const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
73+
const error = vi.spyOn(console, "error").mockImplementation(() => undefined);
74+
vi.useFakeTimers();
75+
const done = runCommand(billing, { rawArgs: ["add-credits"] });
76+
await vi.advanceTimersByTimeAsync(2000);
77+
await done;
78+
vi.useRealTimers();
79+
vi.unstubAllEnvs();
80+
expect(new URL(opened[0] ?? "").origin).toBe("https://credits.test");
81+
expect(error).not.toHaveBeenCalled();
82+
expect(log.mock.calls.flat().join("\n")).not.toMatch(/deprecat|renamed|top-up/i);
83+
});
84+
85+
it("refuses the old name `top-up` like any unknown action, naming the valid ones", async () => {
86+
const error = vi.spyOn(console, "error").mockImplementation(() => undefined);
87+
await expect(runCommand(billing, { rawArgs: ["top-up"] })).rejects.toThrow();
88+
expect(error.mock.calls.flat().join("\n")).toContain(
89+
"Use `billing subscribe` or `billing add-credits`.",
90+
);
91+
expect(opened).toEqual([]);
92+
});
8793
});
8894

8995
describe("billing without a terminal", () => {

‎packages/cli/src/commands/billing.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default defineCommand({
8787
},
8888
// fallow-ignore-next-line complexity
8989
async run({ args }) {
90-
const action = String(args.action) === "top-up" ? "add-credits" : String(args.action);
90+
const action = String(args.action);
9191
if (action !== "subscribe" && action !== "add-credits") {
9292
console.error(c.error("Use `billing subscribe` or `billing add-credits`."));
9393
failCommand();

0 commit comments

Comments
 (0)