From f4f094fc3b8a36ed8d6705394a82e8c2613db76f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 2 Mar 2026 04:03:55 +0000 Subject: [PATCH] test(mattermost): cover defaultAccount resolution --- .../src/mattermost/accounts.test.ts | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 extensions/mattermost/src/mattermost/accounts.test.ts diff --git a/extensions/mattermost/src/mattermost/accounts.test.ts b/extensions/mattermost/src/mattermost/accounts.test.ts new file mode 100644 index 00000000000..2fd6b253163 --- /dev/null +++ b/extensions/mattermost/src/mattermost/accounts.test.ts @@ -0,0 +1,52 @@ +import type { OpenClawConfig } from "openclaw/plugin-sdk"; +import { describe, expect, it } from "vitest"; +import { resolveDefaultMattermostAccountId } from "./accounts.js"; + +describe("resolveDefaultMattermostAccountId", () => { + it("prefers channels.mattermost.defaultAccount when it matches a configured account", () => { + const cfg: OpenClawConfig = { + channels: { + mattermost: { + defaultAccount: "alerts", + accounts: { + default: { botToken: "tok-default", baseUrl: "https://chat.example.com" }, + alerts: { botToken: "tok-alerts", baseUrl: "https://alerts.example.com" }, + }, + }, + }, + }; + + expect(resolveDefaultMattermostAccountId(cfg)).toBe("alerts"); + }); + + it("normalizes channels.mattermost.defaultAccount before lookup", () => { + const cfg: OpenClawConfig = { + channels: { + mattermost: { + defaultAccount: "Ops Team", + accounts: { + "ops-team": { botToken: "tok-ops", baseUrl: "https://chat.example.com" }, + }, + }, + }, + }; + + expect(resolveDefaultMattermostAccountId(cfg)).toBe("ops-team"); + }); + + it("falls back when channels.mattermost.defaultAccount is missing", () => { + const cfg: OpenClawConfig = { + channels: { + mattermost: { + defaultAccount: "missing", + accounts: { + default: { botToken: "tok-default", baseUrl: "https://chat.example.com" }, + alerts: { botToken: "tok-alerts", baseUrl: "https://alerts.example.com" }, + }, + }, + }, + }; + + expect(resolveDefaultMattermostAccountId(cfg)).toBe("default"); + }); +});