mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-25 08:02:04 +00:00
fix: label whatsapp setup account status
This commit is contained in:
@@ -2,12 +2,15 @@ import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
|
||||
import { DEFAULT_ACCOUNT_ID, type OpenClawConfig } from "openclaw/plugin-sdk/setup";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createPluginSetupWizardStatus,
|
||||
createQueuedWizardPrompter,
|
||||
runSetupWizardFinalize,
|
||||
} from "../../../test/helpers/plugins/setup-wizard.js";
|
||||
import { whatsappSetupPlugin } from "./channel.setup.js";
|
||||
import { whatsappSetupWizard } from "./setup-surface.js";
|
||||
|
||||
const hoisted = vi.hoisted(() => ({
|
||||
detectWhatsAppLinked: vi.fn(async () => false),
|
||||
loginWeb: vi.fn(async () => {}),
|
||||
pathExists: vi.fn(async () => false),
|
||||
resolveWhatsAppAuthDir: vi.fn(() => ({
|
||||
@@ -19,6 +22,14 @@ vi.mock("./login.js", () => ({
|
||||
loginWeb: hoisted.loginWeb,
|
||||
}));
|
||||
|
||||
vi.mock("./setup-finalize.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./setup-finalize.js")>("./setup-finalize.js");
|
||||
return {
|
||||
...actual,
|
||||
detectWhatsAppLinked: hoisted.detectWhatsAppLinked,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/setup", async () => {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/setup")>(
|
||||
"openclaw/plugin-sdk/setup",
|
||||
@@ -43,6 +54,10 @@ function createRuntime(): RuntimeEnv {
|
||||
} as unknown as RuntimeEnv;
|
||||
}
|
||||
|
||||
const whatsappGetStatus = createPluginSetupWizardStatus({
|
||||
...whatsappSetupPlugin,
|
||||
} as never);
|
||||
|
||||
async function runFinalizeWithHarness(params: {
|
||||
harness: ReturnType<typeof createQueuedWizardPrompter>;
|
||||
cfg?: Parameters<NonNullable<typeof whatsappSetupWizard.finalize>>[0]["cfg"];
|
||||
@@ -94,6 +109,8 @@ async function runSeparatePhoneFlow(params: { selectValues: string[]; textValues
|
||||
|
||||
describe("whatsapp setup wizard", () => {
|
||||
beforeEach(() => {
|
||||
hoisted.detectWhatsAppLinked.mockReset();
|
||||
hoisted.detectWhatsAppLinked.mockResolvedValue(false);
|
||||
hoisted.loginWeb.mockReset();
|
||||
hoisted.pathExists.mockReset();
|
||||
hoisted.pathExists.mockResolvedValue(false);
|
||||
@@ -177,6 +194,28 @@ describe("whatsapp setup wizard", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("labels the selected named account in setup status even when not linked", async () => {
|
||||
const status = await whatsappGetStatus({
|
||||
cfg: {
|
||||
channels: {
|
||||
whatsapp: {
|
||||
accounts: {
|
||||
work: {
|
||||
authDir: "/tmp/work",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig,
|
||||
accountOverrides: {
|
||||
whatsapp: "work",
|
||||
},
|
||||
});
|
||||
|
||||
expect(status.configured).toBe(false);
|
||||
expect(status.statusLines).toEqual(["WhatsApp (work): not linked"]);
|
||||
});
|
||||
|
||||
it("normalizes allowFrom entries when list mode is selected", async () => {
|
||||
const { result } = await runSeparatePhoneFlow({
|
||||
selectValues: ["separate", "allowlist", "list"],
|
||||
|
||||
@@ -36,8 +36,9 @@ export const whatsappSetupWizard: ChannelSetupWizard = {
|
||||
})),
|
||||
)
|
||||
).find((entry) => entry.linked)?.accountId;
|
||||
const label = linkedAccountId
|
||||
? `WhatsApp (${linkedAccountId === DEFAULT_ACCOUNT_ID ? "default" : linkedAccountId})`
|
||||
const labelAccountId = accountId ?? linkedAccountId;
|
||||
const label = labelAccountId
|
||||
? `WhatsApp (${labelAccountId === DEFAULT_ACCOUNT_ID ? "default" : labelAccountId})`
|
||||
: "WhatsApp";
|
||||
return [`${label}: ${configured ? "linked" : "not linked"}`];
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user