|
7 | 7 | resolveAuthHintKind, |
8 | 8 | resolvePairingHint, |
9 | 9 | shouldShowInsecureContextHint, |
10 | | - shouldShowPairingHint, |
11 | 10 | } from "./overview-hints.ts"; |
12 | 11 |
|
13 | 12 | afterEach(() => { |
@@ -74,43 +73,31 @@ describe("resolveGatewayTokenForUrlEdit", () => { |
74 | 73 | }); |
75 | 74 | }); |
76 | 75 |
|
77 | | -describe("shouldShowPairingHint", () => { |
78 | | - it("returns true for 'pairing required' close reason", () => { |
79 | | - expect(shouldShowPairingHint(false, "disconnected (1008): pairing required")).toBe(true); |
80 | | - }); |
81 | | - |
82 | | - it("matches case-insensitively", () => { |
83 | | - expect(shouldShowPairingHint(false, "Pairing Required")).toBe(true); |
84 | | - }); |
85 | | - |
86 | | - it("returns false when connected", () => { |
87 | | - expect(shouldShowPairingHint(true, "disconnected (1008): pairing required")).toBe(false); |
88 | | - }); |
89 | | - |
90 | | - it("returns false when lastError is null", () => { |
91 | | - expect(shouldShowPairingHint(false, null)).toBe(false); |
92 | | - }); |
93 | | - |
94 | | - it("returns false for unrelated errors", () => { |
95 | | - expect(shouldShowPairingHint(false, "disconnected (1006): no reason")).toBe(false); |
96 | | - }); |
97 | | - |
98 | | - it("returns false for auth errors", () => { |
99 | | - expect(shouldShowPairingHint(false, "disconnected (4008): unauthorized")).toBe(false); |
| 76 | +describe("resolvePairingHint", () => { |
| 77 | + it.each([ |
| 78 | + ["close reason", "disconnected (1008): pairing required", undefined], |
| 79 | + ["case-insensitive close reason", "Pairing Required", undefined], |
| 80 | + [ |
| 81 | + "structured pairing code", |
| 82 | + "disconnected (4008): connect failed", |
| 83 | + ConnectErrorDetailCodes.PAIRING_REQUIRED, |
| 84 | + ], |
| 85 | + ])("detects pairing required from %s", (_name, lastError, lastErrorCode) => { |
| 86 | + expect(resolvePairingHint(false, lastError, lastErrorCode)).toEqual({ |
| 87 | + kind: "pairing-required", |
| 88 | + requestId: null, |
| 89 | + }); |
100 | 90 | }); |
101 | 91 |
|
102 | | - it("returns true for structured pairing code", () => { |
103 | | - expect( |
104 | | - shouldShowPairingHint( |
105 | | - false, |
106 | | - "disconnected (4008): connect failed", |
107 | | - ConnectErrorDetailCodes.PAIRING_REQUIRED, |
108 | | - ), |
109 | | - ).toBe(true); |
| 92 | + it.each([ |
| 93 | + ["connected clients", true, "disconnected (1008): pairing required"], |
| 94 | + ["missing errors", false, null], |
| 95 | + ["unrelated errors", false, "disconnected (1006): no reason"], |
| 96 | + ["auth errors", false, "disconnected (4008): unauthorized"], |
| 97 | + ])("ignores %s", (_name, connected, lastError) => { |
| 98 | + expect(resolvePairingHint(connected, lastError)).toBeNull(); |
110 | 99 | }); |
111 | | -}); |
112 | 100 |
|
113 | | -describe("resolvePairingHint", () => { |
114 | 101 | it("detects scope-upgrade pending approval and keeps the request id", () => { |
115 | 102 | expect( |
116 | 103 | resolvePairingHint( |
|
0 commit comments