mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:00:43 +00:00
test: share channel directory id assertions
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
import type {
|
||||
BaseProbeResult,
|
||||
BaseTokenResolution,
|
||||
ChannelDirectoryEntry,
|
||||
} from "openclaw/plugin-sdk/channel-contract";
|
||||
import type { BaseProbeResult, BaseTokenResolution } from "openclaw/plugin-sdk/channel-contract";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/testing";
|
||||
import { describe, expect, expectTypeOf, it } from "vitest";
|
||||
import { expectDirectoryIds } from "../../../test/helpers/channels/directory-ids.js";
|
||||
import {
|
||||
listDiscordDirectoryGroupsFromConfig,
|
||||
listDiscordDirectoryPeersFromConfig,
|
||||
@@ -12,43 +9,6 @@ import {
|
||||
import type { DiscordProbe } from "./probe.js";
|
||||
import type { DiscordTokenResolution } from "./token.js";
|
||||
|
||||
type DirectoryListFn = (params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string;
|
||||
query?: string | null;
|
||||
limit?: number | null;
|
||||
}) => Promise<ChannelDirectoryEntry[]>;
|
||||
|
||||
async function listDirectoryEntriesWithDefaults(listFn: DirectoryListFn, cfg: OpenClawConfig) {
|
||||
return await listFn({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
});
|
||||
}
|
||||
|
||||
async function expectDirectoryIds(
|
||||
listFn: DirectoryListFn,
|
||||
cfg: OpenClawConfig,
|
||||
expected: string[],
|
||||
options?: { sorted?: boolean },
|
||||
) {
|
||||
const entries = await listDirectoryEntriesWithDefaults(listFn, cfg);
|
||||
const ids = entries.map((entry) => entry.id);
|
||||
expect(options?.sorted ? sortDirectoryIds(ids) : ids).toEqual(
|
||||
options?.sorted ? sortDirectoryIds(expected) : expected,
|
||||
);
|
||||
}
|
||||
|
||||
function compareDirectoryIds(left: string, right: string) {
|
||||
return left < right ? -1 : left > right ? 1 : 0;
|
||||
}
|
||||
|
||||
function sortDirectoryIds(values: string[]) {
|
||||
return values.toSorted(compareDirectoryIds);
|
||||
}
|
||||
|
||||
describe("Discord directory contract", () => {
|
||||
it("keeps public probe and token resolution aligned with base contracts", () => {
|
||||
expectTypeOf<DiscordProbe>().toMatchTypeOf<BaseProbeResult>();
|
||||
|
||||
@@ -1,49 +1,13 @@
|
||||
import type { BaseProbeResult, ChannelDirectoryEntry } from "openclaw/plugin-sdk/channel-contract";
|
||||
import type { BaseProbeResult } from "openclaw/plugin-sdk/channel-contract";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/testing";
|
||||
import { describe, expect, expectTypeOf, it } from "vitest";
|
||||
import { expectDirectoryIds } from "../../../test/helpers/channels/directory-ids.js";
|
||||
import {
|
||||
listSlackDirectoryGroupsFromConfig,
|
||||
listSlackDirectoryPeersFromConfig,
|
||||
} from "../directory-contract-api.js";
|
||||
import type { SlackProbe } from "./probe.js";
|
||||
|
||||
type DirectoryListFn = (params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string;
|
||||
query?: string | null;
|
||||
limit?: number | null;
|
||||
}) => Promise<ChannelDirectoryEntry[]>;
|
||||
|
||||
async function listDirectoryEntriesWithDefaults(listFn: DirectoryListFn, cfg: OpenClawConfig) {
|
||||
return await listFn({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
});
|
||||
}
|
||||
|
||||
async function expectDirectoryIds(
|
||||
listFn: DirectoryListFn,
|
||||
cfg: OpenClawConfig,
|
||||
expected: string[],
|
||||
options?: { sorted?: boolean },
|
||||
) {
|
||||
const entries = await listDirectoryEntriesWithDefaults(listFn, cfg);
|
||||
const ids = entries.map((entry) => entry.id);
|
||||
expect(options?.sorted ? sortDirectoryIds(ids) : ids).toEqual(
|
||||
options?.sorted ? sortDirectoryIds(expected) : expected,
|
||||
);
|
||||
}
|
||||
|
||||
function compareDirectoryIds(left: string, right: string) {
|
||||
return left < right ? -1 : left > right ? 1 : 0;
|
||||
}
|
||||
|
||||
function sortDirectoryIds(values: string[]) {
|
||||
return values.toSorted(compareDirectoryIds);
|
||||
}
|
||||
|
||||
describe("Slack directory contract", () => {
|
||||
it("keeps public probe aligned with base contract", () => {
|
||||
expectTypeOf<SlackProbe>().toMatchTypeOf<BaseProbeResult>();
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import type {
|
||||
BaseProbeResult,
|
||||
BaseTokenResolution,
|
||||
ChannelDirectoryEntry,
|
||||
} from "openclaw/plugin-sdk/channel-contract";
|
||||
import type { BaseProbeResult, BaseTokenResolution } from "openclaw/plugin-sdk/channel-contract";
|
||||
import { type OpenClawConfig, withEnvAsync } from "openclaw/plugin-sdk/testing";
|
||||
import { describe, expect, expectTypeOf, it } from "vitest";
|
||||
import { expectDirectoryIds } from "../../../test/helpers/channels/directory-ids.js";
|
||||
import {
|
||||
listTelegramDirectoryGroupsFromConfig,
|
||||
listTelegramDirectoryPeersFromConfig,
|
||||
@@ -12,43 +9,6 @@ import {
|
||||
import type { TelegramProbe } from "./probe.js";
|
||||
import type { TelegramTokenResolution } from "./token.js";
|
||||
|
||||
type DirectoryListFn = (params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string;
|
||||
query?: string | null;
|
||||
limit?: number | null;
|
||||
}) => Promise<ChannelDirectoryEntry[]>;
|
||||
|
||||
async function listDirectoryEntriesWithDefaults(listFn: DirectoryListFn, cfg: OpenClawConfig) {
|
||||
return await listFn({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
});
|
||||
}
|
||||
|
||||
async function expectDirectoryIds(
|
||||
listFn: DirectoryListFn,
|
||||
cfg: OpenClawConfig,
|
||||
expected: string[],
|
||||
options?: { sorted?: boolean },
|
||||
) {
|
||||
const entries = await listDirectoryEntriesWithDefaults(listFn, cfg);
|
||||
const ids = entries.map((entry) => entry.id);
|
||||
expect(options?.sorted ? sortDirectoryIds(ids) : ids).toEqual(
|
||||
options?.sorted ? sortDirectoryIds(expected) : expected,
|
||||
);
|
||||
}
|
||||
|
||||
function compareDirectoryIds(left: string, right: string) {
|
||||
return left < right ? -1 : left > right ? 1 : 0;
|
||||
}
|
||||
|
||||
function sortDirectoryIds(values: string[]) {
|
||||
return values.toSorted(compareDirectoryIds);
|
||||
}
|
||||
|
||||
describe("Telegram directory contract", () => {
|
||||
it("keeps public probe and token resolution aligned with base contracts", () => {
|
||||
expectTypeOf<TelegramProbe>().toMatchTypeOf<BaseProbeResult>();
|
||||
|
||||
36
test/helpers/channels/directory-ids.ts
Normal file
36
test/helpers/channels/directory-ids.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { ChannelDirectoryEntry } from "openclaw/plugin-sdk/channel-contract";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/testing";
|
||||
import { expect } from "vitest";
|
||||
|
||||
export type DirectoryListFn = (params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string;
|
||||
query?: string | null;
|
||||
limit?: number | null;
|
||||
}) => Promise<ChannelDirectoryEntry[]>;
|
||||
|
||||
export async function expectDirectoryIds(
|
||||
listFn: DirectoryListFn,
|
||||
cfg: OpenClawConfig,
|
||||
expected: string[],
|
||||
options?: { sorted?: boolean },
|
||||
) {
|
||||
const entries = await listFn({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
query: null,
|
||||
limit: null,
|
||||
});
|
||||
const ids = entries.map((entry) => entry.id);
|
||||
expect(options?.sorted ? sortDirectoryIds(ids) : ids).toEqual(
|
||||
options?.sorted ? sortDirectoryIds(expected) : expected,
|
||||
);
|
||||
}
|
||||
|
||||
function compareDirectoryIds(left: string, right: string) {
|
||||
return left < right ? -1 : left > right ? 1 : 0;
|
||||
}
|
||||
|
||||
function sortDirectoryIds(values: string[]) {
|
||||
return values.toSorted(compareDirectoryIds);
|
||||
}
|
||||
Reference in New Issue
Block a user