* Build a device/code response whose `state` echoes back the value * extracted from the actual request body — so it always matches.
(reqBody: URLSearchParams, overrides: Record<string, unknown> = {})
| 29 | * extracted from the actual request body — so it always matches. |
| 30 | */ |
| 31 | function deviceCodeResponse(reqBody: URLSearchParams, overrides: Record<string, unknown> = {}): Response { |
| 32 | capturedState = reqBody.get('state'); |
| 33 | capturedCodeVerifier = reqBody.get('code_verifier') ?? reqBody.get('code_challenge'); |
| 34 | return { |
| 35 | status: 200, |
| 36 | ok: true, |
| 37 | headers: new Headers({ 'Content-Type': 'application/json' }), |
| 38 | json: async () => ({ |
| 39 | user_code: 'TEST-CODE', |
| 40 | verification_uri: 'about:blank', |
| 41 | expired_in: Date.now() + 120_000, |
| 42 | interval: 10, |
| 43 | state: capturedState, |
| 44 | ...overrides, |
| 45 | }), |
| 46 | } as Response; |
| 47 | } |
| 48 | |
| 49 | function tokenResponse(overrides: Record<string, unknown> = {}) { |
| 50 | return { |
no outgoing calls
no test coverage detected