mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
test(matrix): cover directory context and group exact-match resolution
This commit is contained in:
@@ -51,4 +51,24 @@ describe("matrix directory live", () => {
|
||||
|
||||
expect(resolveMatrixAuth).toHaveBeenCalledWith({ cfg, accountId: "assistant" });
|
||||
});
|
||||
|
||||
it("returns no peer results for empty query without resolving auth", async () => {
|
||||
const result = await listMatrixDirectoryPeersLive({
|
||||
cfg,
|
||||
query: " ",
|
||||
});
|
||||
|
||||
expect(result).toEqual([]);
|
||||
expect(resolveMatrixAuth).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns no group results for empty query without resolving auth", async () => {
|
||||
const result = await listMatrixDirectoryGroupsLive({
|
||||
cfg,
|
||||
query: "",
|
||||
});
|
||||
|
||||
expect(result).toEqual([]);
|
||||
expect(resolveMatrixAuth).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ChannelDirectoryEntry } from "openclaw/plugin-sdk";
|
||||
import { describe, expect, it, vi, beforeEach } from "vitest";
|
||||
import { listMatrixDirectoryPeersLive } from "./directory-live.js";
|
||||
import { listMatrixDirectoryGroupsLive, listMatrixDirectoryPeersLive } from "./directory-live.js";
|
||||
import { resolveMatrixTargets } from "./resolve-targets.js";
|
||||
|
||||
vi.mock("./directory-live.js", () => ({
|
||||
@@ -11,6 +11,7 @@ vi.mock("./directory-live.js", () => ({
|
||||
describe("resolveMatrixTargets (users)", () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(listMatrixDirectoryPeersLive).mockReset();
|
||||
vi.mocked(listMatrixDirectoryGroupsLive).mockReset();
|
||||
});
|
||||
|
||||
it("resolves exact unique display name matches", async () => {
|
||||
@@ -45,4 +46,22 @@ describe("resolveMatrixTargets (users)", () => {
|
||||
expect(result?.resolved).toBe(false);
|
||||
expect(result?.note).toMatch(/use full Matrix ID/i);
|
||||
});
|
||||
|
||||
it("prefers exact group matches over first partial result", async () => {
|
||||
const matches: ChannelDirectoryEntry[] = [
|
||||
{ kind: "group", id: "!one:example.org", name: "General", handle: "#general" },
|
||||
{ kind: "group", id: "!two:example.org", name: "Team", handle: "#team" },
|
||||
];
|
||||
vi.mocked(listMatrixDirectoryGroupsLive).mockResolvedValue(matches);
|
||||
|
||||
const [result] = await resolveMatrixTargets({
|
||||
cfg: {},
|
||||
inputs: ["#team"],
|
||||
kind: "group",
|
||||
});
|
||||
|
||||
expect(result?.resolved).toBe(true);
|
||||
expect(result?.id).toBe("!two:example.org");
|
||||
expect(result?.note).toBe("multiple matches; chose first");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user