From 8eb14802fd0ff29efbe0444f95136adf992aa78b Mon Sep 17 00:00:00 2001 From: Shakker Date: Sun, 10 May 2026 21:39:31 +0100 Subject: [PATCH] test: tighten discord gateway opcode assertions --- .../discord/src/internal/gateway.test.ts | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/extensions/discord/src/internal/gateway.test.ts b/extensions/discord/src/internal/gateway.test.ts index 32d2e98bd4d..a1847fade3d 100644 --- a/extensions/discord/src/internal/gateway.test.ts +++ b/extensions/discord/src/internal/gateway.test.ts @@ -21,6 +21,14 @@ function attachOpenSocket(gateway: GatewayPlugin) { return send; } +function sentGatewayOpcodes(send: ReturnType) { + return send.mock.calls.map((call) => { + const [rawPayload] = call; + const payload = JSON.parse(String(rawPayload)) as { op?: unknown }; + return payload.op; + }); +} + function presenceUpdate( status: PresenceUpdateStatus.Online | PresenceUpdateStatus.Idle = PresenceUpdateStatus.Online, ): GatewaySendPayload { @@ -553,17 +561,11 @@ describe("GatewayPlugin", () => { } await vi.advanceTimersByTimeAsync(0); - expect(firstSend).toHaveBeenCalledWith( - expect.stringContaining(`"op":${GatewayOpcodes.Identify}`), - ); - expect(secondSend).not.toHaveBeenCalledWith( - expect.stringContaining(`"op":${GatewayOpcodes.Identify}`), - ); + expect(sentGatewayOpcodes(firstSend)).toContain(GatewayOpcodes.Identify); + expect(sentGatewayOpcodes(secondSend)).not.toContain(GatewayOpcodes.Identify); await vi.advanceTimersByTimeAsync(5_000); - expect(secondSend).toHaveBeenCalledWith( - expect.stringContaining(`"op":${GatewayOpcodes.Identify}`), - ); + expect(sentGatewayOpcodes(secondSend)).toContain(GatewayOpcodes.Identify); }); it("validates requestGuildMembers before sending", () => {