mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Signed-off-by: Taylor Ho <taylorkmho@gmail.com> Co-authored-by: npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6w <52a228d6edf316ec6812ac3c9fc0d696ab59fc7954d77e7be31eedcddf91335b@sprout-oss.stage.blox.sqprod.co>
85 lines
2.2 KiB
JavaScript
85 lines
2.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
|
|
import {
|
|
isChannelOpenable,
|
|
resolveOpenableActivityChannelId,
|
|
} from "./useOpenAgentActivity.ts";
|
|
|
|
describe("isChannelOpenable", () => {
|
|
it("allows joined channels regardless of visibility", () => {
|
|
assert.equal(
|
|
isChannelOpenable({ isMember: true, visibility: "private" }),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
isChannelOpenable({ isMember: true, visibility: "open" }),
|
|
true,
|
|
);
|
|
});
|
|
|
|
it("allows open channels the viewer hasn't joined (read-only)", () => {
|
|
assert.equal(
|
|
isChannelOpenable({ isMember: false, visibility: "open" }),
|
|
true,
|
|
);
|
|
});
|
|
|
|
it("rejects private channels the viewer hasn't joined", () => {
|
|
assert.equal(
|
|
isChannelOpenable({ isMember: false, visibility: "private" }),
|
|
false,
|
|
);
|
|
});
|
|
|
|
it("rejects channels missing from the viewer's channel list", () => {
|
|
assert.equal(isChannelOpenable(undefined), false);
|
|
});
|
|
});
|
|
|
|
describe("resolveOpenableActivityChannelId", () => {
|
|
it("prefers the first openable working channel", () => {
|
|
assert.equal(
|
|
resolveOpenableActivityChannelId({
|
|
agentChannelIds: ["member-1"],
|
|
openableChannelIds: new Set(["working-2", "member-1"]),
|
|
workingChannelIds: ["working-1", "working-2"],
|
|
}),
|
|
"working-2",
|
|
);
|
|
});
|
|
|
|
it("falls back to the agent's first openable member channel", () => {
|
|
assert.equal(
|
|
resolveOpenableActivityChannelId({
|
|
agentChannelIds: ["hidden-2", "member-1"],
|
|
openableChannelIds: new Set(["member-1"]),
|
|
workingChannelIds: ["hidden-1"],
|
|
}),
|
|
"member-1",
|
|
);
|
|
});
|
|
|
|
it("returns null when the agent is only active in inaccessible rooms", () => {
|
|
assert.equal(
|
|
resolveOpenableActivityChannelId({
|
|
agentChannelIds: ["hidden-2"],
|
|
openableChannelIds: new Set(["unrelated"]),
|
|
workingChannelIds: ["hidden-1"],
|
|
}),
|
|
null,
|
|
);
|
|
});
|
|
|
|
it("returns null with no candidate channels at all", () => {
|
|
assert.equal(
|
|
resolveOpenableActivityChannelId({
|
|
agentChannelIds: [],
|
|
openableChannelIds: new Set(),
|
|
workingChannelIds: [],
|
|
}),
|
|
null,
|
|
);
|
|
});
|
|
});
|