Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions __tests__/bin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ import { execFileSync } from "node:child_process";

describe("CLI version", () => {
it("reports the version from package.json", () => {
const pkg = JSON.parse(
readFileSync(join(__dirname, "..", "package.json"), "utf-8"),
);
const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));

const output = execFileSync(
"node",
[join(__dirname, "..", "dist", "bin.cjs"), "--version"],
{ encoding: "utf-8" },
).trim();
const output = execFileSync("node", [join(__dirname, "..", "dist", "bin.cjs"), "--version"], {
encoding: "utf-8",
}).trim();

expect(output).toBe(pkg.version);
});
Expand Down
6 changes: 2 additions & 4 deletions __tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ describe("get", () => {
it("throws on API error status", async () => {
mockFetch.mockResolvedValue({
ok: true,
json: () =>
Promise.resolve({ status: "error", error: "Something went wrong" }),
json: () => Promise.resolve({ status: "error", error: "Something went wrong" }),
});

await expect(get("/api/test")).rejects.toThrow("Something went wrong");
Expand Down Expand Up @@ -105,8 +104,7 @@ describe("post", () => {
mockFetch.mockResolvedValue({
ok: false,
status: 400,
json: () =>
Promise.resolve({ status: "error", message: "Bad request" }),
json: () => Promise.resolve({ status: "error", message: "Bad request" }),
});

await expect(post("/api/test", {})).rejects.toThrow("Bad request");
Expand Down
10 changes: 4 additions & 6 deletions __tests__/commands/artists.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";

import { artistsCommand } from "../../src/commands/artists.js";
import { get } from "../../src/client.js";

vi.mock("../../src/client.js", () => ({
get: vi.fn(),
post: vi.fn(),
}));

import { artistsCommand } from "../../src/commands/artists.js";
import { get } from "../../src/client.js";

let logSpy: ReturnType<typeof vi.spyOn>;
let errorSpy: ReturnType<typeof vi.spyOn>;
let exitSpy: ReturnType<typeof vi.spyOn>;

beforeEach(() => {
logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
exitSpy = vi
.spyOn(process, "exit")
.mockImplementation(() => undefined as never);
exitSpy = vi.spyOn(process, "exit").mockImplementation(() => undefined as never);
});

afterEach(() => {
Expand Down
10 changes: 4 additions & 6 deletions __tests__/commands/chats.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";

import { chatsCommand } from "../../src/commands/chats.js";
import { get, post } from "../../src/client.js";

vi.mock("../../src/client.js", () => ({
get: vi.fn(),
post: vi.fn(),
}));

import { chatsCommand } from "../../src/commands/chats.js";
import { get, post } from "../../src/client.js";

let logSpy: ReturnType<typeof vi.spyOn>;
let errorSpy: ReturnType<typeof vi.spyOn>;
let exitSpy: ReturnType<typeof vi.spyOn>;

beforeEach(() => {
logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
exitSpy = vi
.spyOn(process, "exit")
.mockImplementation(() => undefined as never);
exitSpy = vi.spyOn(process, "exit").mockImplementation(() => undefined as never);
});

afterEach(() => {
Expand Down
56 changes: 13 additions & 43 deletions __tests__/commands/notifications.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";

import { notificationsCommand } from "../../src/commands/notifications.js";
import { post } from "../../src/client.js";

vi.mock("../../src/client.js", () => ({
get: vi.fn(),
post: vi.fn(),
}));

import { notificationsCommand } from "../../src/commands/notifications.js";
import { post } from "../../src/client.js";

let logSpy: ReturnType<typeof vi.spyOn>;
let errorSpy: ReturnType<typeof vi.spyOn>;
let exitSpy: ReturnType<typeof vi.spyOn>;

beforeEach(() => {
logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
exitSpy = vi
.spyOn(process, "exit")
.mockImplementation(() => undefined as never);
exitSpy = vi.spyOn(process, "exit").mockImplementation(() => undefined as never);
});

afterEach(() => {
Expand All @@ -32,10 +30,9 @@ describe("notifications command", () => {
id: "email-123",
});

await notificationsCommand.parseAsync(
["--subject", "Test Subject", "--text", "Hello world"],
{ from: "user" },
);
await notificationsCommand.parseAsync(["--subject", "Test Subject", "--text", "Hello world"], {
from: "user",
});

expect(post).toHaveBeenCalledWith("/api/notifications", {
subject: "Test Subject",
Expand Down Expand Up @@ -70,16 +67,7 @@ describe("notifications command", () => {
});

await notificationsCommand.parseAsync(
[
"--subject",
"Update",
"--text",
"Hello",
"--cc",
"cc@example.com",
"--room-id",
"room-abc",
],
["--subject", "Update", "--text", "Hello", "--cc", "cc@example.com", "--room-id", "room-abc"],
{ from: "user" },
);

Expand All @@ -99,14 +87,7 @@ describe("notifications command", () => {
});

await notificationsCommand.parseAsync(
[
"--subject",
"Update",
"--cc",
"a@example.com",
"--cc",
"b@example.com",
],
["--subject", "Update", "--cc", "a@example.com", "--cc", "b@example.com"],
{ from: "user" },
);

Expand All @@ -124,14 +105,9 @@ describe("notifications command", () => {
};
vi.mocked(post).mockResolvedValue(response);

await notificationsCommand.parseAsync(
["--subject", "Test", "--json"],
{ from: "user" },
);
await notificationsCommand.parseAsync(["--subject", "Test", "--json"], { from: "user" });

expect(logSpy).toHaveBeenCalledWith(
JSON.stringify(response, null, 2),
);
expect(logSpy).toHaveBeenCalledWith(JSON.stringify(response, null, 2));
});

it("passes account_id when --account flag is provided", async () => {
Expand Down Expand Up @@ -167,10 +143,7 @@ describe("notifications command", () => {
id: "email-no-account",
});

await notificationsCommand.parseAsync(
["--subject", "Test"],
{ from: "user" },
);
await notificationsCommand.parseAsync(["--subject", "Test"], { from: "user" });

expect(post).toHaveBeenCalledWith("/api/notifications", {
subject: "Test",
Expand All @@ -180,10 +153,7 @@ describe("notifications command", () => {
it("prints error on failure", async () => {
vi.mocked(post).mockRejectedValue(new Error("No email address found"));

await notificationsCommand.parseAsync(
["--subject", "Test"],
{ from: "user" },
);
await notificationsCommand.parseAsync(["--subject", "Test"], { from: "user" });

expect(errorSpy).toHaveBeenCalledWith("Error: No email address found");
expect(exitSpy).toHaveBeenCalledWith(1);
Expand Down
10 changes: 4 additions & 6 deletions __tests__/commands/orgs.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";

import { orgsCommand } from "../../src/commands/orgs.js";
import { get } from "../../src/client.js";

vi.mock("../../src/client.js", () => ({
get: vi.fn(),
post: vi.fn(),
}));

import { orgsCommand } from "../../src/commands/orgs.js";
import { get } from "../../src/client.js";

let logSpy: ReturnType<typeof vi.spyOn>;
let errorSpy: ReturnType<typeof vi.spyOn>;
let exitSpy: ReturnType<typeof vi.spyOn>;

beforeEach(() => {
logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
exitSpy = vi
.spyOn(process, "exit")
.mockImplementation(() => undefined as never);
exitSpy = vi.spyOn(process, "exit").mockImplementation(() => undefined as never);
});

afterEach(() => {
Expand Down
19 changes: 6 additions & 13 deletions __tests__/commands/sandboxes.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";

import { sandboxesCommand } from "../../src/commands/sandboxes.js";
import { get, post } from "../../src/client.js";

vi.mock("../../src/client.js", () => ({
get: vi.fn(),
post: vi.fn(),
}));

import { sandboxesCommand } from "../../src/commands/sandboxes.js";
import { get, post } from "../../src/client.js";

let logSpy: ReturnType<typeof vi.spyOn>;
let errorSpy: ReturnType<typeof vi.spyOn>;
let exitSpy: ReturnType<typeof vi.spyOn>;

beforeEach(() => {
logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
exitSpy = vi
.spyOn(process, "exit")
.mockImplementation(() => undefined as never);
exitSpy = vi.spyOn(process, "exit").mockImplementation(() => undefined as never);
});

afterEach(() => {
Expand All @@ -44,9 +42,7 @@ describe("sandboxes list", () => {
});

it("prints JSON with --json flag", async () => {
const sandboxes = [
{ sandboxId: "sb-1", sandboxStatus: "running", createdAt: "2025-01-01" },
];
const sandboxes = [{ sandboxId: "sb-1", sandboxStatus: "running", createdAt: "2025-01-01" }];
vi.mocked(get).mockResolvedValue({ status: "success", sandboxes });

await sandboxesCommand.parseAsync(["list", "--json"], { from: "user" });
Expand Down Expand Up @@ -74,10 +70,7 @@ describe("sandboxes create", () => {
sandboxes: [{ sandboxId: "sb-new" }],
});

await sandboxesCommand.parseAsync(
["create", "--command", "echo hello"],
{ from: "user" },
);
await sandboxesCommand.parseAsync(["create", "--command", "echo hello"], { from: "user" });

expect(post).toHaveBeenCalledWith("/api/sandboxes", {
command: "echo hello",
Expand Down
Loading
Loading