Tests. Autocomplete. Few Fixes. Mocks for Electrum Service. Template-to-Json parser. Fix global paths. Use IO Dependency injection for logging from cli. Additional commands in CLI.
This commit is contained in:
86
tests/cli/commands/handler-contracts.test.ts
Normal file
86
tests/cli/commands/handler-contracts.test.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { handleMnemonicCommand } from "../../../src/cli/commands/mnemonic";
|
||||
import { handleTemplateCommand } from "../../../src/cli/commands/template";
|
||||
import { handleReceiveCommand } from "../../../src/cli/commands/receive";
|
||||
import { handleResourceCommand } from "../../../src/cli/commands/resource";
|
||||
import { CommandError } from "../../../src/cli/commands/types";
|
||||
import {
|
||||
createBaseCommandDeps,
|
||||
createCommandDeps,
|
||||
createMockIO,
|
||||
} from "../mocks/command";
|
||||
|
||||
const fakeApp = {
|
||||
engine: {},
|
||||
invitations: [],
|
||||
unreserveAllResources: async () => 0,
|
||||
} as any;
|
||||
|
||||
describe("command handler contracts", () => {
|
||||
test("mnemonic throws and prints help for missing subcommand", async () => {
|
||||
const { io, capture } = createMockIO();
|
||||
|
||||
await expect(
|
||||
handleMnemonicCommand(createBaseCommandDeps(io), [], {}),
|
||||
).rejects.toThrow(CommandError);
|
||||
|
||||
try {
|
||||
await handleMnemonicCommand(createBaseCommandDeps(io), [], {});
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(CommandError);
|
||||
expect((error as CommandError).event).toBe("mnemonic.subcommand.missing");
|
||||
}
|
||||
|
||||
expect(capture.out.join("\n")).toContain("Usage:");
|
||||
});
|
||||
|
||||
test("template throws for missing subcommand", async () => {
|
||||
const { io, capture } = createMockIO();
|
||||
|
||||
await expect(
|
||||
handleTemplateCommand(createCommandDeps(fakeApp, io), [], {}),
|
||||
).rejects.toThrow(CommandError);
|
||||
|
||||
try {
|
||||
await handleTemplateCommand(createCommandDeps(fakeApp, io), [], {});
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(CommandError);
|
||||
expect((error as CommandError).event).toBe("template.subcommand.missing");
|
||||
}
|
||||
|
||||
expect(capture.out.join("\n")).toContain("Usage:");
|
||||
});
|
||||
|
||||
test("receive throws for missing args", async () => {
|
||||
const { io, capture } = createMockIO();
|
||||
|
||||
await expect(
|
||||
handleReceiveCommand(createCommandDeps(fakeApp, io), [], {}),
|
||||
).rejects.toThrow(CommandError);
|
||||
|
||||
try {
|
||||
await handleReceiveCommand(createCommandDeps(fakeApp, io), [], {});
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(CommandError);
|
||||
expect((error as CommandError).event).toBe("receive.arguments.missing");
|
||||
}
|
||||
|
||||
expect(capture.out.join("\n")).toContain("Usage:");
|
||||
});
|
||||
|
||||
test("resource throws for unknown subcommand", async () => {
|
||||
const { io } = createMockIO();
|
||||
|
||||
await expect(
|
||||
handleResourceCommand(createCommandDeps(fakeApp, io), ["does-not-exist"], {}),
|
||||
).rejects.toThrow(CommandError);
|
||||
|
||||
try {
|
||||
await handleResourceCommand(createCommandDeps(fakeApp, io), ["does-not-exist"], {});
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(CommandError);
|
||||
expect((error as CommandError).event).toBe("resource.subcommand.unknown");
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user