test(mattermost): cover defaultAccount resolution

This commit is contained in:
Peter Steinberger
2026-03-02 04:03:55 +00:00
parent 41537e9303
commit f4f094fc3b

View File

@@ -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");
});
});