|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import type { OnboardOptions } from "../../commands/onboard-types.js"; |
| 3 | +import type { WizardSession } from "../../wizard/session.js"; |
| 4 | +import { type SetupWizardRunner, wizardHandlers } from "./wizard.js"; |
| 5 | + |
| 6 | +type ProjectedOptions = Pick< |
| 7 | + OnboardOptions, |
| 8 | + "installDaemon" | "skipUi" | "suppressGatewayTokenOutput" |
| 9 | +>; |
| 10 | + |
| 11 | +describe("wizard.start", () => { |
| 12 | + it.each([ |
| 13 | + { label: "false", params: { installDaemon: false }, expected: false }, |
| 14 | + { label: "true", params: { installDaemon: true }, expected: true }, |
| 15 | + { label: "omitted", params: {}, expected: undefined }, |
| 16 | + ])("projects installDaemon when $label", async ({ params, expected }) => { |
| 17 | + let receivedOptions: ProjectedOptions | undefined; |
| 18 | + const wizardSessions = new Map<string, WizardSession>(); |
| 19 | + const respond = vi.fn(); |
| 20 | + const wizardRunner: SetupWizardRunner = async (opts, _runtime, prompter) => { |
| 21 | + receivedOptions = { |
| 22 | + installDaemon: opts.installDaemon, |
| 23 | + skipUi: opts.skipUi, |
| 24 | + suppressGatewayTokenOutput: opts.suppressGatewayTokenOutput, |
| 25 | + }; |
| 26 | + await prompter.note("ready"); |
| 27 | + }; |
| 28 | + const context = { |
| 29 | + findRunningWizard: () => null, |
| 30 | + wizardSessions, |
| 31 | + purgeWizardSession: vi.fn(), |
| 32 | + wizardRunner, |
| 33 | + }; |
| 34 | + |
| 35 | + const startWizard = wizardHandlers["wizard.start"]; |
| 36 | + if (!startWizard) { |
| 37 | + throw new Error("wizard.start handler is not registered"); |
| 38 | + } |
| 39 | + |
| 40 | + await startWizard({ |
| 41 | + params: { mode: "local", ...params }, |
| 42 | + respond, |
| 43 | + context, |
| 44 | + } as never); |
| 45 | + |
| 46 | + expect(receivedOptions).toEqual({ |
| 47 | + installDaemon: expected, |
| 48 | + skipUi: true, |
| 49 | + suppressGatewayTokenOutput: true, |
| 50 | + }); |
| 51 | + expect(respond).toHaveBeenCalledWith( |
| 52 | + true, |
| 53 | + expect.objectContaining({ done: false, status: "running" }), |
| 54 | + undefined, |
| 55 | + ); |
| 56 | + |
| 57 | + for (const session of wizardSessions.values()) { |
| 58 | + session.cancel(); |
| 59 | + } |
| 60 | + }); |
| 61 | +}); |
0 commit comments