Skip to content

Commit 4d6176e

Browse files
authored
test: consolidate Slack thread-root predicate cases (#133878)
1 parent 419bc1f commit 4d6176e

1 file changed

Lines changed: 31 additions & 81 deletions

File tree

‎extensions/slack/src/monitor/message-handler/prepare-thread-context-root.test.ts‎

Lines changed: 31 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,14 @@ type SlackThreadRootCandidate = {
1919
describe("isSlackThreadAuthorCurrentBot", () => {
2020
const identity = { botUserId: "U_BOT", botId: "B1" };
2121

22-
it("matches the configured bot user id", () => {
23-
expect(
24-
isSlackThreadAuthorCurrentBot({
25-
identity,
26-
author: { userId: "U_BOT" },
27-
}),
28-
).toBe(true);
29-
});
30-
31-
it("matches the configured bot id", () => {
32-
expect(
33-
isSlackThreadAuthorCurrentBot({
34-
identity,
35-
author: { botId: "B1" },
36-
}),
37-
).toBe(true);
38-
});
39-
40-
it("does not match a different bot id", () => {
41-
expect(
42-
isSlackThreadAuthorCurrentBot({
43-
identity,
44-
author: { botId: "B2" },
45-
}),
46-
).toBe(false);
47-
});
48-
49-
it("does not match a regular user", () => {
50-
expect(
51-
isSlackThreadAuthorCurrentBot({
52-
identity,
53-
author: { userId: "U1" },
54-
}),
55-
).toBe(false);
56-
});
57-
58-
it("returns false when identity has no bot ids", () => {
59-
expect(
60-
isSlackThreadAuthorCurrentBot({
61-
identity: {},
62-
author: { userId: "U_BOT", botId: "B1" },
63-
}),
64-
).toBe(false);
22+
it.each([
23+
["matches the configured bot user id", identity, { userId: "U_BOT" }, true],
24+
["matches the configured bot id", identity, { botId: "B1" }, true],
25+
["does not match a different bot id", identity, { botId: "B2" }, false],
26+
["does not match a regular user", identity, { userId: "U1" }, false],
27+
["returns false when identity has no bot ids", {}, { userId: "U_BOT", botId: "B1" }, false],
28+
] as const)("%s", (_name, botIdentity, author, expected) => {
29+
expect(isSlackThreadAuthorCurrentBot({ identity: botIdentity, author })).toBe(expected);
6530
});
6631
});
6732

@@ -156,44 +121,29 @@ describe("applySlackThreadHistoryFilterPolicy", () => {
156121
});
157122

158123
describe("shouldIncludeBotThreadStarterContext", () => {
159-
it("includes when starter is bot, session is new, and starter has text", () => {
160-
expect(
161-
shouldIncludeBotThreadStarterContext({
162-
starterIsCurrentBot: true,
163-
isNewThreadSession: true,
164-
hasStarterText: true,
165-
}),
166-
).toBe(true);
167-
});
168-
169-
it("does not include when starter is not the current bot", () => {
170-
expect(
171-
shouldIncludeBotThreadStarterContext({
172-
starterIsCurrentBot: false,
173-
isNewThreadSession: true,
174-
hasStarterText: true,
175-
}),
176-
).toBe(false);
177-
});
178-
179-
it("does not include when session is not new", () => {
180-
expect(
181-
shouldIncludeBotThreadStarterContext({
182-
starterIsCurrentBot: true,
183-
isNewThreadSession: false,
184-
hasStarterText: true,
185-
}),
186-
).toBe(false);
187-
});
188-
189-
it("does not include when starter has no text", () => {
190-
expect(
191-
shouldIncludeBotThreadStarterContext({
192-
starterIsCurrentBot: true,
193-
isNewThreadSession: true,
194-
hasStarterText: false,
195-
}),
196-
).toBe(false);
124+
it.each([
125+
[
126+
"includes when starter is bot, session is new, and starter has text",
127+
{ starterIsCurrentBot: true, isNewThreadSession: true, hasStarterText: true },
128+
true,
129+
],
130+
[
131+
"does not include when starter is not the current bot",
132+
{ starterIsCurrentBot: false, isNewThreadSession: true, hasStarterText: true },
133+
false,
134+
],
135+
[
136+
"does not include when session is not new",
137+
{ starterIsCurrentBot: true, isNewThreadSession: false, hasStarterText: true },
138+
false,
139+
],
140+
[
141+
"does not include when starter has no text",
142+
{ starterIsCurrentBot: true, isNewThreadSession: true, hasStarterText: false },
143+
false,
144+
],
145+
] as const)("%s", (_name, params, expected) => {
146+
expect(shouldIncludeBotThreadStarterContext(params)).toBe(expected);
197147
});
198148
});
199149

0 commit comments

Comments
 (0)