mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 15:47:28 +00:00
test: guard thread ownership mock calls
This commit is contained in:
@@ -39,6 +39,14 @@ describe("thread-ownership plugin", () => {
|
||||
expect(init?.body).toBe(JSON.stringify({ agent_id: agentId }));
|
||||
}
|
||||
|
||||
function requireFirstLogMessage(mock: ReturnType<typeof vi.fn>, label: string): string {
|
||||
const [call] = mock.mock.calls;
|
||||
if (!call || typeof call[0] !== "string") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return call[0];
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
for (const key of Object.keys(hooks)) {
|
||||
@@ -256,8 +264,7 @@ describe("thread-ownership plugin", () => {
|
||||
const result = await sendSlackThreadMessage();
|
||||
|
||||
expect(result).toEqual({ cancel: true });
|
||||
const infoMessage = vi.mocked(api.logger.info).mock.calls[0]?.[0];
|
||||
expect(typeof infoMessage).toBe("string");
|
||||
const infoMessage = requireFirstLogMessage(api.logger.info, "ownership cancel info log");
|
||||
expect(infoMessage).toContain("cancelled send");
|
||||
});
|
||||
|
||||
@@ -267,8 +274,7 @@ describe("thread-ownership plugin", () => {
|
||||
const result = await sendSlackThreadMessage();
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
const warningMessage = vi.mocked(api.logger.warn).mock.calls[0]?.[0];
|
||||
expect(typeof warningMessage).toBe("string");
|
||||
const warningMessage = requireFirstLogMessage(api.logger.warn, "ownership check warning log");
|
||||
expect(warningMessage).toContain("ownership check failed");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user