Open History to see the last commit
1import { describe, expect, it, vi } from "vite-plus/test";
2
3import {
4 CloudPublicConfigMissingError,
5 hasTracingPublicConfig,
6 resolveCloudPublicConfig,
7 resolveRelayClerkTokenOptions,
8} from "./publicConfig";
9
10vi.mock("expo-constants", () => ({
11 default: {
12 expoConfig: {
13 extra: {},
14 },
15 },
16}));
17
18describe("resolveCloudPublicConfig", () => {
19 it("reports the missing Clerk JWT template as structured configuration", () => {
20 expect(() => resolveRelayClerkTokenOptions()).toThrowError(
21 new CloudPublicConfigMissingError({ key: "T3CODE_CLERK_JWT_TEMPLATE" }),
22 );
23 });
24
25 it("returns no cloud configuration for an unconfigured build", () => {
26 expect(resolveCloudPublicConfig({})).toEqual({
27 clerk: {
28 publishableKey: null,
29 jwtTemplate: null,
30 },
31 relay: {
32 url: null,
33 },
34 observability: {
35 tracesUrl: null,
36 tracesDataset: null,
37 tracesToken: null,
38 },
39 });
40 });
41
42 it("normalizes statically injected cloud configuration", () => {
43 expect(
44 resolveCloudPublicConfig({
45 clerk: { publishableKey: " pk_test_example ", jwtTemplate: " t3-relay " },
46 relay: { url: " https://relay.example.test/// " },
47 observability: {
48 tracesUrl: " https://api.axiom.co/v1/traces ",
49 tracesDataset: " mobile-traces ",
50 tracesToken: " public-ingest-token ",
51 },
52 }),
53 ).toEqual({
54 clerk: {
55 publishableKey: "pk_test_example",
56 jwtTemplate: "t3-relay",
57 },
58 relay: {
59 url: "https://relay.example.test",
60 },
61 observability: {
62 tracesUrl: "https://api.axiom.co/v1/traces",
63 tracesDataset: "mobile-traces",
64 tracesToken: "public-ingest-token",
65 },
66 });
67 });
68
69 it("rejects an insecure relay URL", () => {
70 expect(
71 resolveCloudPublicConfig({
72 clerk: { publishableKey: "pk_test_example", jwtTemplate: "t3-relay" },
73 relay: { url: "http://relay.example.test" },
74 }),
75 ).toEqual({
76 clerk: {
77 publishableKey: "pk_test_example",
78 jwtTemplate: "t3-relay",
79 },
80 relay: {
81 url: null,
82 },
83 observability: {
84 tracesUrl: null,
85 tracesDataset: null,
86 tracesToken: null,
87 },
88 });
89 });
90
91 it("rejects an insecure traces URL", () => {
92 expect(
93 resolveCloudPublicConfig({
94 observability: {
95 tracesUrl: "http://api.axiom.co/v1/traces",
96 tracesDataset: "mobile-traces",
97 tracesToken: "public-ingest-token",
98 },
99 }).observability,
100 ).toEqual({
101 tracesUrl: null,
102 tracesDataset: "mobile-traces",
103 tracesToken: "public-ingest-token",
104 });
105 });
106
107 it("keeps tracing disabled unless every public tracing value is configured", () => {
108 expect(hasTracingPublicConfig(resolveCloudPublicConfig({}))).toBe(false);
109 expect(
110 hasTracingPublicConfig(
111 resolveCloudPublicConfig({
112 observability: {
113 tracesUrl: "https://api.axiom.co/v1/traces",
114 tracesDataset: "mobile-traces",
115 },
116 }),
117 ),
118 ).toBe(false);
119 expect(
120 hasTracingPublicConfig(
121 resolveCloudPublicConfig({
122 observability: {
123 tracesUrl: "https://api.axiom.co/v1/traces",
124 tracesDataset: "mobile-traces",
125 tracesToken: "public-ingest-token",
126 },
127 }),
128 ),
129 ).toBe(true);
130 });
131});