18 lines
942 B
TypeScript
18 lines
942 B
TypeScript
import { expect, spyOn, test } from "bun:test";
|
|
import * as service from "../service.js";
|
|
import { parseArgs } from "../parser.js";
|
|
import { handleServiceCommand } from "./service.js";
|
|
test("service lifecycle previews never dispatch process or state mutations", async () => {
|
|
const dispatch = spyOn(service, "runServiceCommand").mockResolvedValue({ running: false } as any);
|
|
try {
|
|
for (const action of ["start", "stop", "restart", "run"]) {
|
|
const result = await handleServiceCommand(parseArgs(["service", action, "--dry-run", "--yes"]), { jsonMode: true } as any);
|
|
expect(JSON.parse(result.stdout).dryRun).toBe(true);
|
|
expect(JSON.parse(result.stdout).changes.action).toBe(action);
|
|
}
|
|
expect(dispatch).not.toHaveBeenCalled();
|
|
await handleServiceCommand(parseArgs(["service", "status"]), { jsonMode: true } as any);
|
|
expect(dispatch).toHaveBeenCalledTimes(1);
|
|
} finally { dispatch.mockRestore(); }
|
|
});
|