mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test(mattermost): cover defaultAccount resolution
This commit is contained in:
52
extensions/mattermost/src/mattermost/accounts.test.ts
Normal file
52
extensions/mattermost/src/mattermost/accounts.test.ts
Normal 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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user