Formatting
This commit is contained in:
@@ -3,14 +3,26 @@ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { createMockAppService, createMockEngine, DEFAULT_SEED } from "../mocks/engine";
|
||||
import {
|
||||
createMockAppService,
|
||||
createMockEngine,
|
||||
DEFAULT_SEED,
|
||||
} from "../mocks/engine";
|
||||
import { type Engine } from "@xo-cash/engine";
|
||||
import { p2pkhTemplate, p2pkhTemplateIdentifier } from "../mocks/template-p2pkh";
|
||||
import {
|
||||
p2pkhTemplate,
|
||||
p2pkhTemplateIdentifier,
|
||||
} from "../mocks/template-p2pkh";
|
||||
import { AppService } from "../../../src/services/app";
|
||||
|
||||
import { handleTemplateCommand } from "../../../src/cli/commands/template";
|
||||
import { CommandError } from "../../../src/cli/commands/types";
|
||||
import { createCommandDeps, createMockIO, expectLogs, type LogExpectation } from "../mocks/command";
|
||||
import {
|
||||
createCommandDeps,
|
||||
createMockIO,
|
||||
expectLogs,
|
||||
type LogExpectation,
|
||||
} from "../mocks/command";
|
||||
|
||||
type TestCase = {
|
||||
name: string;
|
||||
@@ -184,42 +196,60 @@ describe("template command", () => {
|
||||
rmSync(tempDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test.each(testCases)("$name", async ({ inputs, options, shouldThrow, expectedEvent, expectedData, logs }) => {
|
||||
const { io, spies } = createMockIO();
|
||||
test.each(testCases)(
|
||||
"$name",
|
||||
async ({
|
||||
inputs,
|
||||
options,
|
||||
shouldThrow,
|
||||
expectedEvent,
|
||||
expectedData,
|
||||
logs,
|
||||
}) => {
|
||||
const { io, spies } = createMockIO();
|
||||
|
||||
if (shouldThrow) {
|
||||
try {
|
||||
await handleTemplateCommand(createCommandDeps(app, io), inputs, options ?? {});
|
||||
expect.fail("Expected command to throw");
|
||||
} catch (error) {
|
||||
if (expectedEvent) {
|
||||
expect(error).toBeInstanceOf(CommandError);
|
||||
expect((error as CommandError).event).toBe(expectedEvent);
|
||||
if (shouldThrow) {
|
||||
try {
|
||||
await handleTemplateCommand(
|
||||
createCommandDeps(app, io),
|
||||
inputs,
|
||||
options ?? {},
|
||||
);
|
||||
expect.fail("Expected command to throw");
|
||||
} catch (error) {
|
||||
if (expectedEvent) {
|
||||
expect(error).toBeInstanceOf(CommandError);
|
||||
expect((error as CommandError).event).toBe(expectedEvent);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const result = await handleTemplateCommand(
|
||||
createCommandDeps(app, io),
|
||||
inputs,
|
||||
options ?? {},
|
||||
);
|
||||
if (expectedData) {
|
||||
Object.entries(expectedData).forEach(([key, value]) => {
|
||||
expect(result[key as keyof typeof result]).toEqual(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const result = await handleTemplateCommand(createCommandDeps(app, io), inputs, options ?? {});
|
||||
if (expectedData) {
|
||||
Object.entries(expectedData).forEach(([key, value]) => {
|
||||
expect(result[key as keyof typeof result]).toEqual(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (logs) {
|
||||
expectLogs(spies, logs);
|
||||
}
|
||||
});
|
||||
if (logs) {
|
||||
expectLogs(spies, logs);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test("import imports template from file", async () => {
|
||||
const templatePath = path.join(tempDir, "test-template.json");
|
||||
writeFileSync(templatePath, JSON.stringify(p2pkhTemplate));
|
||||
|
||||
const { io } = createMockIO();
|
||||
|
||||
|
||||
const originalCwd = process.cwd();
|
||||
process.chdir(tempDir);
|
||||
|
||||
|
||||
try {
|
||||
const result = await handleTemplateCommand(
|
||||
createCommandDeps(app, io),
|
||||
|
||||
Reference in New Issue
Block a user