test: dedupe repeated test fixtures and assertions

This commit is contained in:
Peter Steinberger
2026-02-22 18:37:01 +00:00
parent 0e4f3ccbdf
commit 53ed7a0f5c
10 changed files with 166 additions and 212 deletions

View File

@@ -1,43 +1,13 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import type { ChannelPlugin } from "../channels/plugins/types.js";
import type { PluginRegistry } from "../plugins/registry.js";
import { setActivePluginRegistry } from "../plugins/runtime.js";
import { createMSTeamsTestPluginBase, createTestRegistry } from "../test-utils/channel-plugins.js";
import { resolveGatewayMessageChannel } from "./message-channel.js";
const createRegistry = (channels: PluginRegistry["channels"]): PluginRegistry => ({
plugins: [],
tools: [],
hooks: [],
typedHooks: [],
channels,
commands: [],
providers: [],
gatewayHandlers: {},
httpHandlers: [],
httpRoutes: [],
cliRegistrars: [],
services: [],
diagnostics: [],
});
const emptyRegistry = createRegistry([]);
const msteamsPlugin = {
id: "msteams",
meta: {
id: "msteams",
label: "Microsoft Teams",
selectionLabel: "Microsoft Teams (Bot Framework)",
docsPath: "/channels/msteams",
blurb: "Bot Framework; enterprise support.",
aliases: ["teams"],
},
capabilities: { chatTypes: ["direct"] },
config: {
listAccountIds: () => [],
resolveAccount: () => ({}),
},
} satisfies ChannelPlugin;
const emptyRegistry = createTestRegistry([]);
const msteamsPlugin: ChannelPlugin = {
...createMSTeamsTestPluginBase(),
};
describe("message-channel", () => {
beforeEach(() => {
@@ -57,7 +27,7 @@ describe("message-channel", () => {
it("normalizes plugin aliases when registered", () => {
setActivePluginRegistry(
createRegistry([{ pluginId: "msteams", plugin: msteamsPlugin, source: "test" }]),
createTestRegistry([{ pluginId: "msteams", plugin: msteamsPlugin, source: "test" }]),
);
expect(resolveGatewayMessageChannel("teams")).toBe("msteams");
});