refactor: unify target resolver metadata
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
listDiscordDirectoryGroupsFromConfig,
|
||||
listDiscordDirectoryPeersFromConfig,
|
||||
listSlackDirectoryGroupsFromConfig,
|
||||
listSlackDirectoryPeersFromConfig,
|
||||
listTelegramDirectoryGroupsFromConfig,
|
||||
listTelegramDirectoryPeersFromConfig,
|
||||
listWhatsAppDirectoryGroupsFromConfig,
|
||||
listWhatsAppDirectoryPeersFromConfig,
|
||||
} from "./directory-config.js";
|
||||
|
||||
describe("directory (config-backed)", () => {
|
||||
it("lists Slack peers/groups from config", async () => {
|
||||
const { slackPlugin } = await import("./slack.js");
|
||||
const runtime = { log: () => {}, error: () => {}, exit: () => {} } as any;
|
||||
const cfg = {
|
||||
channels: {
|
||||
slack: {
|
||||
@@ -16,12 +24,11 @@ describe("directory (config-backed)", () => {
|
||||
},
|
||||
} as any;
|
||||
|
||||
const peers = await slackPlugin.directory?.listPeers?.({
|
||||
const peers = await listSlackDirectoryPeersFromConfig({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
runtime,
|
||||
});
|
||||
expect(peers?.map((e) => e.id).sort()).toEqual([
|
||||
"user:u123",
|
||||
@@ -30,19 +37,16 @@ describe("directory (config-backed)", () => {
|
||||
"user:u999",
|
||||
]);
|
||||
|
||||
const groups = await slackPlugin.directory?.listGroups?.({
|
||||
const groups = await listSlackDirectoryGroupsFromConfig({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
runtime,
|
||||
});
|
||||
expect(groups?.map((e) => e.id)).toEqual(["channel:c111"]);
|
||||
});
|
||||
|
||||
it("lists Discord peers/groups from config (numeric ids only)", async () => {
|
||||
const { discordPlugin } = await import("./discord.js");
|
||||
const runtime = { log: () => {}, error: () => {}, exit: () => {} } as any;
|
||||
const cfg = {
|
||||
channels: {
|
||||
discord: {
|
||||
@@ -63,28 +67,24 @@ describe("directory (config-backed)", () => {
|
||||
},
|
||||
} as any;
|
||||
|
||||
const peers = await discordPlugin.directory?.listPeers?.({
|
||||
const peers = await listDiscordDirectoryPeersFromConfig({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
runtime,
|
||||
});
|
||||
expect(peers?.map((e) => e.id).sort()).toEqual(["user:111", "user:12345", "user:222"]);
|
||||
|
||||
const groups = await discordPlugin.directory?.listGroups?.({
|
||||
const groups = await listDiscordDirectoryGroupsFromConfig({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
runtime,
|
||||
});
|
||||
expect(groups?.map((e) => e.id).sort()).toEqual(["channel:555", "channel:666"]);
|
||||
});
|
||||
|
||||
it("lists Telegram peers/groups from config", async () => {
|
||||
const { telegramPlugin } = await import("./telegram.js");
|
||||
const runtime = { log: () => {}, error: () => {}, exit: () => {} } as any;
|
||||
const cfg = {
|
||||
channels: {
|
||||
telegram: {
|
||||
@@ -96,28 +96,24 @@ describe("directory (config-backed)", () => {
|
||||
},
|
||||
} as any;
|
||||
|
||||
const peers = await telegramPlugin.directory?.listPeers?.({
|
||||
const peers = await listTelegramDirectoryPeersFromConfig({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
runtime,
|
||||
});
|
||||
expect(peers?.map((e) => e.id).sort()).toEqual(["123", "456", "@alice", "@bob"]);
|
||||
|
||||
const groups = await telegramPlugin.directory?.listGroups?.({
|
||||
const groups = await listTelegramDirectoryGroupsFromConfig({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
runtime,
|
||||
});
|
||||
expect(groups?.map((e) => e.id)).toEqual(["-1001"]);
|
||||
});
|
||||
|
||||
it("lists WhatsApp peers/groups from config", async () => {
|
||||
const { whatsappPlugin } = await import("./whatsapp.js");
|
||||
const runtime = { log: () => {}, error: () => {}, exit: () => {} } as any;
|
||||
const cfg = {
|
||||
channels: {
|
||||
whatsapp: {
|
||||
@@ -127,21 +123,19 @@ describe("directory (config-backed)", () => {
|
||||
},
|
||||
} as any;
|
||||
|
||||
const peers = await whatsappPlugin.directory?.listPeers?.({
|
||||
const peers = await listWhatsAppDirectoryPeersFromConfig({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
runtime,
|
||||
});
|
||||
expect(peers?.map((e) => e.id)).toEqual(["+15550000000"]);
|
||||
|
||||
const groups = await whatsappPlugin.directory?.listGroups?.({
|
||||
const groups = await listWhatsAppDirectoryGroupsFromConfig({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
runtime,
|
||||
});
|
||||
expect(groups?.map((e) => e.id)).toEqual(["999@g.us"]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user