From 3b45ad6960288611d5f0a00c331d0a8f607d8ef5 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 14:48:14 +0100 Subject: [PATCH] test: dedupe matrix device mock calls --- .../matrix/src/matrix/actions/devices.test.ts | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/extensions/matrix/src/matrix/actions/devices.test.ts b/extensions/matrix/src/matrix/actions/devices.test.ts index 33e45e3c6ac..f131380d53e 100644 --- a/extensions/matrix/src/matrix/actions/devices.test.ts +++ b/extensions/matrix/src/matrix/actions/devices.test.ts @@ -11,6 +11,17 @@ vi.mock("./client.js", () => ({ const { getMatrixDeviceHealth, listMatrixOwnDevices, pruneMatrixStaleGatewayDevices } = await import("./devices.js"); +function expectResolvedActionClientCall(): void { + expect(withResolvedActionClientMock).toHaveBeenCalledTimes(1); + const call = withResolvedActionClientMock.mock.calls.at(0); + if (!call) { + throw new Error("Expected resolved action client call"); + } + expect(call[0]).toEqual({ accountId: "poe" }); + expect(call[1]).toBeTypeOf("function"); + expect(withStartedActionClientMock).not.toHaveBeenCalled(); +} + describe("matrix device actions", () => { beforeEach(() => { vi.clearAllMocks(); @@ -33,10 +44,7 @@ describe("matrix device actions", () => { const result = await listMatrixOwnDevices({ accountId: "poe" }); - expect(withResolvedActionClientMock).toHaveBeenCalledTimes(1); - expect(withResolvedActionClientMock.mock.calls[0]?.[0]).toEqual({ accountId: "poe" }); - expect(withResolvedActionClientMock.mock.calls[0]?.[1]).toBeTypeOf("function"); - expect(withStartedActionClientMock).not.toHaveBeenCalled(); + expectResolvedActionClientCall(); expect(result).toEqual([ { deviceId: "A7hWrQ70ea", @@ -93,10 +101,7 @@ describe("matrix device actions", () => { }, ], }); - expect(withResolvedActionClientMock).toHaveBeenCalledTimes(1); - expect(withResolvedActionClientMock.mock.calls[0]?.[0]).toEqual({ accountId: "poe" }); - expect(withResolvedActionClientMock.mock.calls[0]?.[1]).toBeTypeOf("function"); - expect(withStartedActionClientMock).not.toHaveBeenCalled(); + expectResolvedActionClientCall(); }); it("prunes stale OpenClaw-managed devices but preserves the current device", async () => { @@ -210,9 +215,6 @@ describe("matrix device actions", () => { }, ], }); - expect(withResolvedActionClientMock).toHaveBeenCalledTimes(1); - expect(withResolvedActionClientMock.mock.calls[0]?.[0]).toEqual({ accountId: "poe" }); - expect(withResolvedActionClientMock.mock.calls[0]?.[1]).toBeTypeOf("function"); - expect(withStartedActionClientMock).not.toHaveBeenCalled(); + expectResolvedActionClientCall(); }); });