The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { Linking } from "react-native"; |
| 2 | import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; |
| 3 | |
| 4 | import { tryOpenExternalUrl } from "./openExternalUrl"; |
| 5 | |
| 6 | vi.mock("react-native", () => ({ |
| 7 | Linking: { openURL: vi.fn() }, |
| 8 | })); |
| 9 | |
| 10 | const openURL = vi.mocked(Linking.openURL); |
| 11 | |
| 12 | beforeEach(() => { |
| 13 | vi.clearAllMocks(); |
| 14 | }); |
| 15 | |
| 16 | afterEach(() => { |
| 17 | vi.restoreAllMocks(); |
| 18 | }); |
| 19 | |
| 20 | describe("tryOpenExternalUrl", () => { |
| 21 | it("keeps provider sign-in URLs unchanged and out of failure logs", async () => { |
| 22 | const url = |
| 23 | "https://accounts.google.com/o/oauth2/v2/auth?state=private-state&code_challenge=private-challenge&redirect_uri=http%3A%2F%2F127.0.0.1%3A43123%2F"; |
| 24 | openURL.mockRejectedValue(new Error(`Cannot open ${url}`)); |
| 25 | const consoleError = vi.spyOn(console, "error").mockImplementation(() => undefined); |
| 26 | |
| 27 | await expect(tryOpenExternalUrl(url, "provider-auth")).resolves.toBe(false); |
| 28 | |
| 29 | expect(openURL).toHaveBeenCalledWith(url); |
| 30 | const diagnostics = JSON.stringify(consoleError.mock.calls); |
| 31 | expect(diagnostics).toContain("accounts.google.com"); |
| 32 | expect(diagnostics).not.toContain("private-state"); |
| 33 | expect(diagnostics).not.toContain("private-challenge"); |
| 34 | expect(diagnostics).not.toContain("43123"); |
| 35 | }); |
| 36 | }); |