| 1 | import { describe, expect, it, vi } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | CloudPublicConfigMissingError, |
| 5 | resolveCloudPublicConfig, |
| 6 | resolveRelayClerkTokenOptions, |
| 7 | } from "./publicConfig"; |
| 8 | |
| 9 | vi.mock("expo-constants", () => ({ |
| 10 | default: { |
| 11 | expoConfig: { |
| 12 | extra: {}, |
| 13 | }, |
| 14 | }, |
| 15 | })); |
| 16 | |
| 17 | describe("resolveCloudPublicConfig", () => { |
| 18 | it("reports the missing Clerk JWT template as structured configuration", () => { |
| 19 | expect(() => resolveRelayClerkTokenOptions()).toThrowError( |
| 20 | new CloudPublicConfigMissingError({ key: "T3CODE_CLERK_JWT_TEMPLATE" }), |
| 21 | ); |
| 22 | }); |
| 23 | |
| 24 | it("returns no cloud configuration for an unconfigured build", () => { |
| 25 | expect(resolveCloudPublicConfig({})).toEqual({ |
| 26 | clerk: { |
| 27 | publishableKey: null, |
| 28 | jwtTemplate: null, |
| 29 | }, |
| 30 | relay: { |
| 31 | url: null, |
| 32 | }, |
| 33 | }); |
| 34 | }); |
| 35 | |
| 36 | it("normalizes statically injected cloud configuration", () => { |
| 37 | expect( |
| 38 | resolveCloudPublicConfig({ |
| 39 | clerk: { publishableKey: " pk_test_example ", jwtTemplate: " t3-relay " }, |
| 40 | relay: { url: " https://relay.example.test/// " }, |
| 41 | }), |
| 42 | ).toEqual({ |
| 43 | clerk: { |
| 44 | publishableKey: "pk_test_example", |
| 45 | jwtTemplate: "t3-relay", |
| 46 | }, |
| 47 | relay: { |
| 48 | url: "https://relay.example.test", |
| 49 | }, |
| 50 | }); |
| 51 | }); |
| 52 | |
| 53 | it("rejects an insecure relay URL", () => { |
| 54 | expect( |
| 55 | resolveCloudPublicConfig({ |
| 56 | clerk: { publishableKey: "pk_test_example", jwtTemplate: "t3-relay" }, |
| 57 | relay: { url: "http://relay.example.test" }, |
| 58 | }), |
| 59 | ).toEqual({ |
| 60 | clerk: { |
| 61 | publishableKey: "pk_test_example", |
| 62 | jwtTemplate: "t3-relay", |
| 63 | }, |
| 64 | relay: { |
| 65 | url: null, |
| 66 | }, |
| 67 | }); |
| 68 | }); |
| 69 | }); |