test: tighten discord gateway opcode assertions · openclaw/openclaw@8eb1480
shakkernerd
·
2026-05-11
·
via Recent Commits to openclaw:main
File tree
extensions/discord/src/internal
| Original file line number | Diff line number | Diff line change |
|---|
@@ -21,6 +21,14 @@ function attachOpenSocket(gateway: GatewayPlugin) {
|
21 | 21 | return send; |
22 | 22 | } |
23 | 23 | |
| 24 | +function sentGatewayOpcodes(send: ReturnType<typeof attachOpenSocket>) { |
| 25 | +return send.mock.calls.map((call) => { |
| 26 | +const [rawPayload] = call; |
| 27 | +const payload = JSON.parse(String(rawPayload)) as { op?: unknown }; |
| 28 | +return payload.op; |
| 29 | +}); |
| 30 | +} |
| 31 | + |
24 | 32 | function presenceUpdate( |
25 | 33 | status: PresenceUpdateStatus.Online | PresenceUpdateStatus.Idle = PresenceUpdateStatus.Online, |
26 | 34 | ): GatewaySendPayload { |
@@ -553,17 +561,11 @@ describe("GatewayPlugin", () => {
|
553 | 561 | } |
554 | 562 | |
555 | 563 | await vi.advanceTimersByTimeAsync(0); |
556 | | -expect(firstSend).toHaveBeenCalledWith( |
557 | | -expect.stringContaining(`"op":${GatewayOpcodes.Identify}`), |
558 | | -); |
559 | | -expect(secondSend).not.toHaveBeenCalledWith( |
560 | | -expect.stringContaining(`"op":${GatewayOpcodes.Identify}`), |
561 | | -); |
| 564 | +expect(sentGatewayOpcodes(firstSend)).toContain(GatewayOpcodes.Identify); |
| 565 | +expect(sentGatewayOpcodes(secondSend)).not.toContain(GatewayOpcodes.Identify); |
562 | 566 | |
563 | 567 | await vi.advanceTimersByTimeAsync(5_000); |
564 | | -expect(secondSend).toHaveBeenCalledWith( |
565 | | -expect.stringContaining(`"op":${GatewayOpcodes.Identify}`), |
566 | | -); |
| 568 | +expect(sentGatewayOpcodes(secondSend)).toContain(GatewayOpcodes.Identify); |
567 | 569 | }); |
568 | 570 | |
569 | 571 | it("validates requestGuildMembers before sending", () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。