test: guard inbound claim logger mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 05:20:50 +01:00
parent ff7e6c7fb3
commit a786d8dfcb

View File

@@ -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 {