test(msteams): cover routing and setup

This commit is contained in:
Vincent Koc
2026-03-22 18:27:27 -07:00
parent 645c9210b3
commit 774a2064c9
2 changed files with 103 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
import { describe, expect, it } from "vitest";
import { resolveMSTeamsOutboundSessionRoute } from "./session-route.js";
describe("msteams session route", () => {
it("builds direct routes for explicit user targets", () => {
const route = resolveMSTeamsOutboundSessionRoute({
cfg: {},
agentId: "main",
accountId: "default",
target: "msteams:user:alice-id",
});
expect(route).toMatchObject({
peer: {
kind: "direct",
id: "alice-id",
},
from: "msteams:alice-id",
to: "user:alice-id",
});
});
it("builds channel routes for thread conversations and strips suffix metadata", () => {
const route = resolveMSTeamsOutboundSessionRoute({
cfg: {},
agentId: "main",
accountId: "default",
target: "teams:19:abc123@thread.tacv2;messageid=42",
});
expect(route).toMatchObject({
peer: {
kind: "channel",
id: "19:abc123@thread.tacv2",
},
from: "msteams:channel:19:abc123@thread.tacv2",
to: "conversation:19:abc123@thread.tacv2",
});
});
it("returns group routes for non-user, non-channel conversations", () => {
const route = resolveMSTeamsOutboundSessionRoute({
cfg: {},
agentId: "main",
accountId: "default",
target: "msteams:conversation:19:groupchat",
});
expect(route).toMatchObject({
peer: {
kind: "group",
id: "19:groupchat",
},
from: "msteams:group:19:groupchat",
to: "conversation:19:groupchat",
});
});
it("returns null when the target cannot be normalized", () => {
expect(
resolveMSTeamsOutboundSessionRoute({
cfg: {},
agentId: "main",
accountId: "default",
target: "msteams:",
}),
).toBeNull();
});
});

View File

@@ -0,0 +1,34 @@
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/setup";
import { describe, expect, it } from "vitest";
import { msteamsSetupAdapter } from "./setup-core.js";
describe("msteams setup core", () => {
it("always resolves to the default account", () => {
expect(msteamsSetupAdapter.resolveAccountId?.({ accountId: "work" } as never)).toBe(
DEFAULT_ACCOUNT_ID,
);
});
it("enables the msteams channel without dropping existing config", () => {
expect(
msteamsSetupAdapter.applyAccountConfig?.({
cfg: {
channels: {
msteams: {
appId: "existing-app",
},
},
},
accountId: DEFAULT_ACCOUNT_ID,
input: {},
} as never),
).toEqual({
channels: {
msteams: {
appId: "existing-app",
enabled: true,
},
},
});
});
});