mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-20 14:30:57 +00:00
61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
import type { OpenClawConfig } from "openclaw/plugin-sdk/line";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { buildChannelSetupWizardAdapterFromSetupWizard } from "../../../src/channels/plugins/setup-wizard.js";
|
|
import {
|
|
listLineAccountIds,
|
|
resolveDefaultLineAccountId,
|
|
resolveLineAccount,
|
|
} from "../../../src/line/accounts.js";
|
|
import { createRuntimeEnv } from "../../../test/helpers/extensions/runtime-env.js";
|
|
import {
|
|
createTestWizardPrompter,
|
|
type WizardPrompter,
|
|
} from "../../../test/helpers/extensions/setup-wizard.js";
|
|
import { lineSetupAdapter, lineSetupWizard } from "./setup-surface.js";
|
|
|
|
const lineConfigureAdapter = buildChannelSetupWizardAdapterFromSetupWizard({
|
|
plugin: {
|
|
id: "line",
|
|
meta: { label: "LINE" },
|
|
config: {
|
|
listAccountIds: listLineAccountIds,
|
|
defaultAccountId: resolveDefaultLineAccountId,
|
|
resolveAllowFrom: ({ cfg, accountId }: { cfg: OpenClawConfig; accountId?: string | null }) =>
|
|
resolveLineAccount({ cfg, accountId: accountId ?? undefined }).config.allowFrom,
|
|
},
|
|
setup: lineSetupAdapter,
|
|
} as Parameters<typeof buildChannelSetupWizardAdapterFromSetupWizard>[0]["plugin"],
|
|
wizard: lineSetupWizard,
|
|
});
|
|
|
|
describe("line setup wizard", () => {
|
|
it("configures token and secret for the default account", async () => {
|
|
const prompter = createTestWizardPrompter({
|
|
text: vi.fn(async ({ message }: { message: string }) => {
|
|
if (message === "Enter LINE channel access token") {
|
|
return "line-token";
|
|
}
|
|
if (message === "Enter LINE channel secret") {
|
|
return "line-secret";
|
|
}
|
|
throw new Error(`Unexpected prompt: ${message}`);
|
|
}) as WizardPrompter["text"],
|
|
});
|
|
|
|
const result = await lineConfigureAdapter.configure({
|
|
cfg: {} as OpenClawConfig,
|
|
runtime: createRuntimeEnv(),
|
|
prompter,
|
|
options: {},
|
|
accountOverrides: {},
|
|
shouldPromptAccountIds: false,
|
|
forceAllowFrom: false,
|
|
});
|
|
|
|
expect(result.accountId).toBe("default");
|
|
expect(result.cfg.channels?.line?.enabled).toBe(true);
|
|
expect(result.cfg.channels?.line?.channelAccessToken).toBe("line-token");
|
|
expect(result.cfg.channels?.line?.channelSecret).toBe("line-secret");
|
|
});
|
|
});
|