mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-22 06:08:13 +00:00
test: guard inbound claim logger mock calls
This commit is contained in:
@@ -33,6 +33,18 @@ function createInboundClaimForumCtx() {
|
||||
};
|
||||
}
|
||||
|
||||
function expectFirstErrorLog(
|
||||
logger: { error: ReturnType<typeof vi.fn> },
|
||||
expected: readonly unknown[],
|
||||
): void {
|
||||
expect(logger.error).toHaveBeenCalledTimes(1);
|
||||
const call = logger.error.mock.calls.at(0);
|
||||
if (!call) {
|
||||
throw new Error("expected logger.error call");
|
||||
}
|
||||
expect(call).toEqual(expected);
|
||||
}
|
||||
|
||||
describe("inbound_claim hook runner", () => {
|
||||
it("stops at the first handler that claims the event", async () => {
|
||||
const first = vi.fn().mockResolvedValue({ handled: true });
|
||||
@@ -81,10 +93,7 @@ describe("inbound_claim hook runner", () => {
|
||||
);
|
||||
|
||||
expect(result).toEqual({ handled: true });
|
||||
expect(logger.error).toHaveBeenCalledTimes(1);
|
||||
expect(logger.error.mock.calls[0]).toEqual([
|
||||
"[hooks] inbound_claim handler from test-plugin failed: boom",
|
||||
]);
|
||||
expectFirstErrorLog(logger, ["[hooks] inbound_claim handler from test-plugin failed: boom"]);
|
||||
expect(succeeding).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
@@ -194,8 +203,7 @@ describe("inbound_claim hook runner", () => {
|
||||
await vi.advanceTimersByTimeAsync(5);
|
||||
|
||||
await expect(run).resolves.toEqual({ status: "error", error: "timed out after 5ms" });
|
||||
expect(logger.error).toHaveBeenCalledTimes(1);
|
||||
expect(logger.error.mock.calls[0]).toEqual([
|
||||
expectFirstErrorLog(logger, [
|
||||
"[hooks] inbound_claim handler from test-plugin failed: timed out after 5ms",
|
||||
]);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user