diff --git a/extensions/matrix/src/matrix/actions/devices.test.ts b/extensions/matrix/src/matrix/actions/devices.test.ts index 578e48471c2..33e45e3c6ac 100644 --- a/extensions/matrix/src/matrix/actions/devices.test.ts +++ b/extensions/matrix/src/matrix/actions/devices.test.ts @@ -33,16 +33,18 @@ describe("matrix device actions", () => { const result = await listMatrixOwnDevices({ accountId: "poe" }); - expect(withResolvedActionClientMock).toHaveBeenCalledWith( - { accountId: "poe" }, - expect.any(Function), - ); + 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(); expect(result).toEqual([ - expect.objectContaining({ + { deviceId: "A7hWrQ70ea", + displayName: "OpenClaw Gateway", + lastSeenIp: null, + lastSeenTs: null, current: true, - }), + }, ]); }); @@ -70,15 +72,30 @@ describe("matrix device actions", () => { const result = await getMatrixDeviceHealth({ accountId: "poe" }); - expect(result.staleOpenClawDevices).toEqual([ - expect.objectContaining({ - deviceId: "old123", - }), - ]); - expect(withResolvedActionClientMock).toHaveBeenCalledWith( - { accountId: "poe" }, - expect.any(Function), - ); + expect(result).toEqual({ + currentDeviceId: "du314Zpw3A", + staleOpenClawDevices: [ + { + deviceId: "old123", + displayName: "OpenClaw Gateway", + lastSeenIp: null, + lastSeenTs: null, + current: false, + }, + ], + currentOpenClawDevices: [ + { + deviceId: "du314Zpw3A", + displayName: "OpenClaw Gateway", + lastSeenIp: null, + lastSeenTs: null, + current: true, + }, + ], + }); + 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(); }); @@ -142,18 +159,60 @@ describe("matrix device actions", () => { const result = await pruneMatrixStaleGatewayDevices({ accountId: "poe" }); expect(deleteOwnDevices).toHaveBeenCalledWith(["BritdXC6iL", "G6NJU9cTgs", "My3T0hkTE0"]); - expect(result.staleGatewayDeviceIds).toEqual(["BritdXC6iL", "G6NJU9cTgs", "My3T0hkTE0"]); - expect(result.deletedDeviceIds).toEqual(["BritdXC6iL", "G6NJU9cTgs", "My3T0hkTE0"]); - expect(result.remainingDevices).toEqual([ - expect.objectContaining({ - deviceId: "du314Zpw3A", - current: true, - }), - ]); - expect(withResolvedActionClientMock).toHaveBeenCalledWith( - { accountId: "poe" }, - expect.any(Function), - ); + expect(result).toEqual({ + before: [ + { + deviceId: "du314Zpw3A", + displayName: "OpenClaw Gateway", + lastSeenIp: null, + lastSeenTs: null, + current: true, + }, + { + deviceId: "BritdXC6iL", + displayName: "OpenClaw Gateway", + lastSeenIp: null, + lastSeenTs: null, + current: false, + }, + { + deviceId: "G6NJU9cTgs", + displayName: "OpenClaw Debug", + lastSeenIp: null, + lastSeenTs: null, + current: false, + }, + { + deviceId: "My3T0hkTE0", + displayName: "OpenClaw Gateway", + lastSeenIp: null, + lastSeenTs: null, + current: false, + }, + { + deviceId: "phone123", + displayName: "Element iPhone", + lastSeenIp: null, + lastSeenTs: null, + current: false, + }, + ], + staleGatewayDeviceIds: ["BritdXC6iL", "G6NJU9cTgs", "My3T0hkTE0"], + currentDeviceId: "du314Zpw3A", + deletedDeviceIds: ["BritdXC6iL", "G6NJU9cTgs", "My3T0hkTE0"], + remainingDevices: [ + { + deviceId: "du314Zpw3A", + displayName: "OpenClaw Gateway", + lastSeenIp: null, + lastSeenTs: null, + current: true, + }, + ], + }); + 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(); }); });