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
55 changes: 31 additions & 24 deletions __tests__/commands/content.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

import { contentCommand } from "../../src/commands/content.js";
import { get, post } from "../../src/client.js";

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

import { contentCommand } from "../../src/commands/content.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>;
Expand All @@ -26,17 +26,13 @@ describe("content command", () => {
it("lists templates", async () => {
vi.mocked(get).mockResolvedValue({
status: "success",
templates: [
{ name: "artist-caption-bedroom", description: "Moody purple bedroom setting" },
],
templates: [{ name: "artist-caption-bedroom", description: "Moody purple bedroom setting" }],
});

await contentCommand.parseAsync(["templates"], { from: "user" });

expect(get).toHaveBeenCalledWith("/api/content/templates");
expect(logSpy).toHaveBeenCalledWith(
"- artist-caption-bedroom: Moody purple bedroom setting",
);
expect(logSpy).toHaveBeenCalledWith("- artist-caption-bedroom: Moody purple bedroom setting");
});

it("validates an artist", async () => {
Expand All @@ -47,7 +43,10 @@ describe("content command", () => {
missing: [],
});

await contentCommand.parseAsync(["validate", "--artist", "550e8400-e29b-41d4-a716-446655440000"], { from: "user" });
await contentCommand.parseAsync(
["validate", "--artist", "550e8400-e29b-41d4-a716-446655440000"],
{ from: "user" },
);

expect(get).toHaveBeenCalledWith("/api/content/validate", {
artist_account_id: "550e8400-e29b-41d4-a716-446655440000",
Expand Down Expand Up @@ -79,7 +78,13 @@ describe("content command", () => {
});

await contentCommand.parseAsync(
["create", "--artist", "550e8400-e29b-41d4-a716-446655440000", "--template", "artist-caption-bedroom"],
[
"create",
"--artist",
"550e8400-e29b-41d4-a716-446655440000",
"--template",
"artist-caption-bedroom",
],
{ from: "user" },
);

Expand Down Expand Up @@ -129,10 +134,9 @@ describe("content command", () => {
});

it("errors when --batch is not a positive integer", async () => {
await contentCommand.parseAsync(
["create", "--artist", "test-artist", "--batch", "abc"],
{ from: "user" },
);
await contentCommand.parseAsync(["create", "--artist", "test-artist", "--batch", "abc"], {
from: "user",
});

expect(errorSpy).toHaveBeenCalledWith("Error: --batch must be a positive integer");
expect(exitSpy).toHaveBeenCalledWith(1);
Expand All @@ -155,14 +159,9 @@ describe("content command", () => {
status: "error",
});

await contentCommand.parseAsync(
["create", "--artist", "test-artist"],
{ from: "user" },
);
await contentCommand.parseAsync(["create", "--artist", "test-artist"], { from: "user" });

expect(errorSpy).toHaveBeenCalledWith(
"Error: Response did not include any run IDs",
);
expect(errorSpy).toHaveBeenCalledWith("Error: Response did not include any run IDs");
expect(exitSpy).toHaveBeenCalledWith(1);
});

Expand All @@ -173,7 +172,16 @@ describe("content command", () => {
});

await contentCommand.parseAsync(
["create", "--artist", "test-artist", "--caption-length", "long", "--upscale", "--batch", "3"],
[
"create",
"--artist",
"test-artist",
"--caption-length",
"long",
"--upscale",
"--batch",
"3",
],
{ from: "user" },
);

Expand All @@ -188,4 +196,3 @@ describe("content command", () => {
expect(logSpy).toHaveBeenCalledWith("Batch started: 3 videos");
});
});

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
Loading
Loading