|
| 1 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | +import type { OpenClawConfig } from "../runtime-api.js"; |
| 3 | +import { mattermostSetupWizard } from "./setup-surface.js"; |
| 4 | + |
| 5 | +describe("mattermost setup surface", () => { |
| 6 | + afterEach(() => { |
| 7 | + vi.unstubAllEnvs(); |
| 8 | + }); |
| 9 | + |
| 10 | + it("treats secret-ref tokens plus base url as configured", async () => { |
| 11 | + const configured = await mattermostSetupWizard.status.resolveConfigured({ |
| 12 | + cfg: { |
| 13 | + channels: { |
| 14 | + mattermost: { |
| 15 | + baseUrl: "https://chat.example.com", |
| 16 | + botToken: { |
| 17 | + source: "env", |
| 18 | + provider: "default", |
| 19 | + id: "MATTERMOST_BOT_TOKEN", |
| 20 | + }, |
| 21 | + }, |
| 22 | + }, |
| 23 | + } as OpenClawConfig, |
| 24 | + }); |
| 25 | + |
| 26 | + expect(configured).toBe(true); |
| 27 | + }); |
| 28 | + |
| 29 | + it("shows intro note only when the target account is not configured", () => { |
| 30 | + expect( |
| 31 | + mattermostSetupWizard.introNote?.shouldShow?.({ |
| 32 | + cfg: { |
| 33 | + channels: { |
| 34 | + mattermost: {}, |
| 35 | + }, |
| 36 | + } as OpenClawConfig, |
| 37 | + accountId: "default", |
| 38 | + } as never), |
| 39 | + ).toBe(true); |
| 40 | + |
| 41 | + expect( |
| 42 | + mattermostSetupWizard.introNote?.shouldShow?.({ |
| 43 | + cfg: { |
| 44 | + channels: { |
| 45 | + mattermost: { |
| 46 | + baseUrl: "https://chat.example.com", |
| 47 | + botToken: { |
| 48 | + source: "env", |
| 49 | + provider: "default", |
| 50 | + id: "MATTERMOST_BOT_TOKEN", |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + } as OpenClawConfig, |
| 55 | + accountId: "default", |
| 56 | + } as never), |
| 57 | + ).toBe(false); |
| 58 | + }); |
| 59 | + |
| 60 | + it("offers env shortcut only for the default account when env is present and config is empty", () => { |
| 61 | + vi.stubEnv("MATTERMOST_BOT_TOKEN", "bot-token"); |
| 62 | + vi.stubEnv("MATTERMOST_URL", "https://chat.example.com"); |
| 63 | + |
| 64 | + expect( |
| 65 | + mattermostSetupWizard.envShortcut?.isAvailable?.({ |
| 66 | + cfg: { channels: { mattermost: {} } } as OpenClawConfig, |
| 67 | + accountId: "default", |
| 68 | + } as never), |
| 69 | + ).toBe(true); |
| 70 | + |
| 71 | + expect( |
| 72 | + mattermostSetupWizard.envShortcut?.isAvailable?.({ |
| 73 | + cfg: { channels: { mattermost: {} } } as OpenClawConfig, |
| 74 | + accountId: "work", |
| 75 | + } as never), |
| 76 | + ).toBe(false); |
| 77 | + }); |
| 78 | + |
| 79 | + it("keeps env shortcut as a no-op patch for the selected account", () => { |
| 80 | + expect( |
| 81 | + mattermostSetupWizard.envShortcut?.apply?.({ |
| 82 | + cfg: { channels: { mattermost: { enabled: false } } } as OpenClawConfig, |
| 83 | + accountId: "default", |
| 84 | + } as never), |
| 85 | + ).toEqual({ |
| 86 | + channels: { |
| 87 | + mattermost: { |
| 88 | + enabled: true, |
| 89 | + }, |
| 90 | + }, |
| 91 | + }); |
| 92 | + }); |
| 93 | +}); |
0 commit comments