@frak-labs/core-sdk 0.1.0-beta.8d103039 → 0.1.0-beta.d9302e66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +20 -16
- package/src/actions/displayEmbeddedWallet.test.ts +194 -0
- package/src/actions/displayModal.test.ts +387 -0
- package/src/actions/getProductInformation.test.ts +133 -0
- package/src/actions/index.ts +19 -19
- package/src/actions/openSso.test.ts +407 -0
- package/src/actions/prepareSso.test.ts +223 -0
- package/src/actions/referral/processReferral.ts +1 -1
- package/src/actions/referral/referralInteraction.ts +1 -1
- package/src/actions/sendInteraction.test.ts +219 -0
- package/src/actions/trackPurchaseStatus.test.ts +287 -0
- package/src/actions/watchWalletStatus.test.ts +372 -0
- package/src/bundle.ts +1 -1
- package/src/clients/createIFrameFrakClient.ts +2 -2
- package/src/clients/index.ts +1 -1
- package/src/clients/setupClient.ts +3 -1
- package/src/clients/transports/iframeLifecycleManager.ts +3 -1
- package/src/index.ts +72 -74
- package/src/interactions/index.ts +2 -2
- package/src/interactions/pressEncoder.test.ts +215 -0
- package/src/interactions/pressEncoder.ts +1 -1
- package/src/interactions/purchaseEncoder.test.ts +291 -0
- package/src/interactions/purchaseEncoder.ts +8 -3
- package/src/interactions/referralEncoder.test.ts +170 -0
- package/src/interactions/retailEncoder.test.ts +107 -0
- package/src/interactions/retailEncoder.ts +1 -1
- package/src/interactions/webshopEncoder.test.ts +56 -0
- package/src/types/index.ts +51 -50
- package/src/types/lifecycle/index.ts +1 -1
- package/src/types/rpc/embedded/loggedIn.ts +1 -1
- package/src/types/rpc/embedded/loggedOut.ts +1 -1
- package/src/types/rpc/modal/index.ts +11 -11
- package/src/utils/FrakContext.test.ts +338 -0
- package/src/utils/FrakContext.ts +8 -2
- package/src/utils/compression/b64.test.ts +181 -0
- package/src/utils/compression/compress.test.ts +123 -0
- package/src/utils/compression/decompress.test.ts +145 -0
- package/src/utils/compression/index.ts +1 -1
- package/src/utils/computeProductId.test.ts +80 -0
- package/src/utils/constants.test.ts +23 -0
- package/src/utils/formatAmount.test.ts +113 -0
- package/src/utils/getCurrencyAmountKey.test.ts +44 -0
- package/src/utils/getSupportedCurrency.test.ts +51 -0
- package/src/utils/getSupportedLocale.test.ts +64 -0
- package/src/utils/iframeHelper.test.ts +450 -0
- package/src/utils/iframeHelper.ts +4 -3
- package/src/utils/index.ts +12 -12
- package/src/utils/sso.test.ts +361 -0
- package/src/utils/trackEvent.test.ts +162 -0
- package/cdn/bundle.js +0 -19
- package/cdn/bundle.js.LICENSE.txt +0 -10
- package/dist/actions.cjs +0 -1
- package/dist/actions.d.cts +0 -1481
- package/dist/actions.d.ts +0 -1481
- package/dist/actions.js +0 -1
- package/dist/bundle.cjs +0 -13
- package/dist/bundle.d.cts +0 -2087
- package/dist/bundle.d.ts +0 -2087
- package/dist/bundle.js +0 -13
- package/dist/index.cjs +0 -13
- package/dist/index.d.cts +0 -1387
- package/dist/index.d.ts +0 -1387
- package/dist/index.js +0 -13
- package/dist/interactions.cjs +0 -1
- package/dist/interactions.d.cts +0 -182
- package/dist/interactions.d.ts +0 -182
- package/dist/interactions.js +0 -1
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for SSO URL generation utility
|
|
3
|
+
* Tests generateSsoUrl and compressed parameter formatting
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { vi } from "vitest";
|
|
7
|
+
|
|
8
|
+
// Mock compression functions
|
|
9
|
+
vi.mock("./compression/compress", () => ({
|
|
10
|
+
compressJsonToB64: vi.fn((data: unknown) => {
|
|
11
|
+
// Return base64url-like string for testing
|
|
12
|
+
return `compressed_${JSON.stringify(data)}`;
|
|
13
|
+
}),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
import type { Hex } from "viem";
|
|
17
|
+
import { describe, expect, it } from "../../tests/vitest-fixtures";
|
|
18
|
+
import type { PrepareSsoParamsType } from "../types";
|
|
19
|
+
import { compressJsonToB64 } from "./compression/compress";
|
|
20
|
+
import { generateSsoUrl } from "./sso";
|
|
21
|
+
|
|
22
|
+
describe("generateSsoUrl", () => {
|
|
23
|
+
const mockProductId =
|
|
24
|
+
"0x1234567890123456789012345678901234567890123456789012345678901234" as Hex;
|
|
25
|
+
const walletUrl = "https://wallet.frak.id";
|
|
26
|
+
|
|
27
|
+
describe("basic URL generation", () => {
|
|
28
|
+
it("should generate SSO URL with basic params", () => {
|
|
29
|
+
const params: PrepareSsoParamsType = {};
|
|
30
|
+
const name = "Test App";
|
|
31
|
+
|
|
32
|
+
const result = generateSsoUrl(
|
|
33
|
+
walletUrl,
|
|
34
|
+
params,
|
|
35
|
+
mockProductId,
|
|
36
|
+
name
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(result).toContain("https://wallet.frak.id/sso");
|
|
40
|
+
expect(result).toContain("?p=");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should include compressed parameters in URL", () => {
|
|
44
|
+
const params: PrepareSsoParamsType = {
|
|
45
|
+
directExit: true,
|
|
46
|
+
};
|
|
47
|
+
const name = "My App";
|
|
48
|
+
|
|
49
|
+
const result = generateSsoUrl(
|
|
50
|
+
walletUrl,
|
|
51
|
+
params,
|
|
52
|
+
mockProductId,
|
|
53
|
+
name
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
expect(result).toContain("?p=compressed_");
|
|
57
|
+
expect(compressJsonToB64).toHaveBeenCalled();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should set /sso pathname", () => {
|
|
61
|
+
const params: PrepareSsoParamsType = {};
|
|
62
|
+
const name = "App";
|
|
63
|
+
|
|
64
|
+
const result = generateSsoUrl(
|
|
65
|
+
walletUrl,
|
|
66
|
+
params,
|
|
67
|
+
mockProductId,
|
|
68
|
+
name
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const url = new URL(result);
|
|
72
|
+
expect(url.pathname).toBe("/sso");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should preserve wallet base URL", () => {
|
|
76
|
+
const customWalletUrl = "https://custom-wallet.com";
|
|
77
|
+
const params: PrepareSsoParamsType = {};
|
|
78
|
+
const name = "App";
|
|
79
|
+
|
|
80
|
+
const result = generateSsoUrl(
|
|
81
|
+
customWalletUrl,
|
|
82
|
+
params,
|
|
83
|
+
mockProductId,
|
|
84
|
+
name
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
expect(result).toContain("https://custom-wallet.com/sso");
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe("parameter compression format", () => {
|
|
92
|
+
it("should compress params with name and productId", () => {
|
|
93
|
+
const params: PrepareSsoParamsType = {};
|
|
94
|
+
const name = "Test App";
|
|
95
|
+
|
|
96
|
+
generateSsoUrl(walletUrl, params, mockProductId, name);
|
|
97
|
+
|
|
98
|
+
expect(compressJsonToB64).toHaveBeenCalledWith(
|
|
99
|
+
expect.objectContaining({
|
|
100
|
+
p: mockProductId,
|
|
101
|
+
m: expect.objectContaining({
|
|
102
|
+
n: name,
|
|
103
|
+
}),
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("should include redirectUrl in compressed params", () => {
|
|
109
|
+
const params: PrepareSsoParamsType = {
|
|
110
|
+
redirectUrl: "https://example.com/callback",
|
|
111
|
+
};
|
|
112
|
+
const name = "App";
|
|
113
|
+
|
|
114
|
+
generateSsoUrl(walletUrl, params, mockProductId, name);
|
|
115
|
+
|
|
116
|
+
expect(compressJsonToB64).toHaveBeenCalledWith(
|
|
117
|
+
expect.objectContaining({
|
|
118
|
+
r: "https://example.com/callback",
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("should include directExit in compressed params", () => {
|
|
124
|
+
const params: PrepareSsoParamsType = {
|
|
125
|
+
directExit: true,
|
|
126
|
+
};
|
|
127
|
+
const name = "App";
|
|
128
|
+
|
|
129
|
+
generateSsoUrl(walletUrl, params, mockProductId, name);
|
|
130
|
+
|
|
131
|
+
expect(compressJsonToB64).toHaveBeenCalledWith(
|
|
132
|
+
expect.objectContaining({
|
|
133
|
+
d: true,
|
|
134
|
+
})
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("should include lang in compressed params", () => {
|
|
139
|
+
const params: PrepareSsoParamsType = {
|
|
140
|
+
lang: "fr",
|
|
141
|
+
};
|
|
142
|
+
const name = "App";
|
|
143
|
+
|
|
144
|
+
generateSsoUrl(walletUrl, params, mockProductId, name);
|
|
145
|
+
|
|
146
|
+
expect(compressJsonToB64).toHaveBeenCalledWith(
|
|
147
|
+
expect.objectContaining({
|
|
148
|
+
l: "fr",
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("should include custom CSS when provided", () => {
|
|
154
|
+
const params: PrepareSsoParamsType = {};
|
|
155
|
+
const name = "App";
|
|
156
|
+
const css = "body { color: red; }";
|
|
157
|
+
|
|
158
|
+
generateSsoUrl(walletUrl, params, mockProductId, name, css);
|
|
159
|
+
|
|
160
|
+
expect(compressJsonToB64).toHaveBeenCalledWith(
|
|
161
|
+
expect.objectContaining({
|
|
162
|
+
m: expect.objectContaining({
|
|
163
|
+
css: "body { color: red; }",
|
|
164
|
+
}),
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("should include metadata logoUrl", () => {
|
|
170
|
+
const params: PrepareSsoParamsType = {
|
|
171
|
+
metadata: {
|
|
172
|
+
logoUrl: "https://example.com/logo.png",
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
const name = "App";
|
|
176
|
+
|
|
177
|
+
generateSsoUrl(walletUrl, params, mockProductId, name);
|
|
178
|
+
|
|
179
|
+
expect(compressJsonToB64).toHaveBeenCalledWith(
|
|
180
|
+
expect.objectContaining({
|
|
181
|
+
m: expect.objectContaining({
|
|
182
|
+
l: "https://example.com/logo.png",
|
|
183
|
+
}),
|
|
184
|
+
})
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("should include metadata homepageLink", () => {
|
|
189
|
+
const params: PrepareSsoParamsType = {
|
|
190
|
+
metadata: {
|
|
191
|
+
homepageLink: "https://example.com",
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
const name = "App";
|
|
195
|
+
|
|
196
|
+
generateSsoUrl(walletUrl, params, mockProductId, name);
|
|
197
|
+
|
|
198
|
+
expect(compressJsonToB64).toHaveBeenCalledWith(
|
|
199
|
+
expect.objectContaining({
|
|
200
|
+
m: expect.objectContaining({
|
|
201
|
+
h: "https://example.com",
|
|
202
|
+
}),
|
|
203
|
+
})
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("should include all metadata fields together", () => {
|
|
208
|
+
const params: PrepareSsoParamsType = {
|
|
209
|
+
metadata: {
|
|
210
|
+
logoUrl: "https://example.com/logo.png",
|
|
211
|
+
homepageLink: "https://example.com",
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
const name = "Full App";
|
|
215
|
+
const css = "body { background: blue; }";
|
|
216
|
+
|
|
217
|
+
generateSsoUrl(walletUrl, params, mockProductId, name, css);
|
|
218
|
+
|
|
219
|
+
expect(compressJsonToB64).toHaveBeenCalledWith(
|
|
220
|
+
expect.objectContaining({
|
|
221
|
+
m: {
|
|
222
|
+
n: "Full App",
|
|
223
|
+
css: "body { background: blue; }",
|
|
224
|
+
l: "https://example.com/logo.png",
|
|
225
|
+
h: "https://example.com",
|
|
226
|
+
},
|
|
227
|
+
})
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
describe("full parameter combinations", () => {
|
|
233
|
+
it("should handle all parameters together", () => {
|
|
234
|
+
const params: PrepareSsoParamsType = {
|
|
235
|
+
redirectUrl: "https://example.com/callback",
|
|
236
|
+
directExit: false,
|
|
237
|
+
lang: "fr",
|
|
238
|
+
metadata: {
|
|
239
|
+
logoUrl: "https://example.com/logo.png",
|
|
240
|
+
homepageLink: "https://example.com/home",
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
const name = "Complete App";
|
|
244
|
+
const css = "body { margin: 0; }";
|
|
245
|
+
|
|
246
|
+
const result = generateSsoUrl(
|
|
247
|
+
walletUrl,
|
|
248
|
+
params,
|
|
249
|
+
mockProductId,
|
|
250
|
+
name,
|
|
251
|
+
css
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
expect(result).toContain("https://wallet.frak.id/sso");
|
|
255
|
+
expect(result).toContain("?p=");
|
|
256
|
+
expect(compressJsonToB64).toHaveBeenCalledWith({
|
|
257
|
+
r: "https://example.com/callback",
|
|
258
|
+
d: false,
|
|
259
|
+
l: "fr",
|
|
260
|
+
p: mockProductId,
|
|
261
|
+
m: {
|
|
262
|
+
n: "Complete App",
|
|
263
|
+
css: "body { margin: 0; }",
|
|
264
|
+
l: "https://example.com/logo.png",
|
|
265
|
+
h: "https://example.com/home",
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("should handle minimal parameters", () => {
|
|
271
|
+
const params: PrepareSsoParamsType = {};
|
|
272
|
+
const name = "Minimal App";
|
|
273
|
+
|
|
274
|
+
const result = generateSsoUrl(
|
|
275
|
+
walletUrl,
|
|
276
|
+
params,
|
|
277
|
+
mockProductId,
|
|
278
|
+
name
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
expect(result).toBeDefined();
|
|
282
|
+
expect(compressJsonToB64).toHaveBeenCalledWith(
|
|
283
|
+
expect.objectContaining({
|
|
284
|
+
p: mockProductId,
|
|
285
|
+
m: expect.objectContaining({
|
|
286
|
+
n: "Minimal App",
|
|
287
|
+
}),
|
|
288
|
+
})
|
|
289
|
+
);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe("edge cases", () => {
|
|
294
|
+
it("should handle empty name", () => {
|
|
295
|
+
const params: PrepareSsoParamsType = {};
|
|
296
|
+
const name = "";
|
|
297
|
+
|
|
298
|
+
const result = generateSsoUrl(
|
|
299
|
+
walletUrl,
|
|
300
|
+
params,
|
|
301
|
+
mockProductId,
|
|
302
|
+
name
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
expect(result).toBeDefined();
|
|
306
|
+
expect(compressJsonToB64).toHaveBeenCalledWith(
|
|
307
|
+
expect.objectContaining({
|
|
308
|
+
m: expect.objectContaining({
|
|
309
|
+
n: "",
|
|
310
|
+
}),
|
|
311
|
+
})
|
|
312
|
+
);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("should handle undefined optional parameters", () => {
|
|
316
|
+
const params: PrepareSsoParamsType = {};
|
|
317
|
+
const name = "App";
|
|
318
|
+
|
|
319
|
+
generateSsoUrl(walletUrl, params, mockProductId, name, undefined);
|
|
320
|
+
|
|
321
|
+
expect(compressJsonToB64).toHaveBeenCalledWith(
|
|
322
|
+
expect.objectContaining({
|
|
323
|
+
m: expect.objectContaining({
|
|
324
|
+
n: "App",
|
|
325
|
+
css: undefined,
|
|
326
|
+
}),
|
|
327
|
+
})
|
|
328
|
+
);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it("should handle wallet URL with trailing slash", () => {
|
|
332
|
+
const walletUrlWithSlash = "https://wallet.frak.id/";
|
|
333
|
+
const params: PrepareSsoParamsType = {};
|
|
334
|
+
const name = "App";
|
|
335
|
+
|
|
336
|
+
const result = generateSsoUrl(
|
|
337
|
+
walletUrlWithSlash,
|
|
338
|
+
params,
|
|
339
|
+
mockProductId,
|
|
340
|
+
name
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
expect(result).toContain("https://wallet.frak.id/sso");
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("should handle different product IDs", () => {
|
|
347
|
+
const differentProductId =
|
|
348
|
+
"0xabcdefabcdefabcdefabcdefabcdefabcdefabcdabcdefabcdefabcdefabcd" as Hex;
|
|
349
|
+
const params: PrepareSsoParamsType = {};
|
|
350
|
+
const name = "App";
|
|
351
|
+
|
|
352
|
+
generateSsoUrl(walletUrl, params, differentProductId, name);
|
|
353
|
+
|
|
354
|
+
expect(compressJsonToB64).toHaveBeenCalledWith(
|
|
355
|
+
expect.objectContaining({
|
|
356
|
+
p: differentProductId,
|
|
357
|
+
})
|
|
358
|
+
);
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for trackEvent utility function
|
|
3
|
+
* Tests OpenPanel event tracking wrapper
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
afterEach,
|
|
8
|
+
beforeEach,
|
|
9
|
+
describe,
|
|
10
|
+
expect,
|
|
11
|
+
it,
|
|
12
|
+
vi,
|
|
13
|
+
} from "../../tests/vitest-fixtures";
|
|
14
|
+
import type { FrakClient } from "../types";
|
|
15
|
+
import { trackEvent } from "./trackEvent";
|
|
16
|
+
|
|
17
|
+
describe("trackEvent", () => {
|
|
18
|
+
let mockClient: FrakClient;
|
|
19
|
+
let consoleDebugSpy: any;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
// Create mock client
|
|
23
|
+
mockClient = {
|
|
24
|
+
openPanel: {
|
|
25
|
+
track: vi.fn(),
|
|
26
|
+
},
|
|
27
|
+
} as unknown as FrakClient;
|
|
28
|
+
|
|
29
|
+
// Spy on console.debug
|
|
30
|
+
consoleDebugSpy = vi
|
|
31
|
+
.spyOn(console, "debug")
|
|
32
|
+
.mockImplementation(() => {});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
consoleDebugSpy.mockRestore();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("success cases", () => {
|
|
40
|
+
it("should track event with client", () => {
|
|
41
|
+
trackEvent(mockClient, "share_button_clicked");
|
|
42
|
+
|
|
43
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
44
|
+
"share_button_clicked",
|
|
45
|
+
{}
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should track event with props", () => {
|
|
50
|
+
const props = { userId: "123", page: "home" };
|
|
51
|
+
trackEvent(mockClient, "wallet_button_clicked", props);
|
|
52
|
+
|
|
53
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
54
|
+
"wallet_button_clicked",
|
|
55
|
+
props
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should track share_modal_error event", () => {
|
|
60
|
+
const props = { error: "Network error" };
|
|
61
|
+
trackEvent(mockClient, "share_modal_error", props);
|
|
62
|
+
|
|
63
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
64
|
+
"share_modal_error",
|
|
65
|
+
props
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should track user_referred event", () => {
|
|
70
|
+
trackEvent(mockClient, "user_referred");
|
|
71
|
+
|
|
72
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
73
|
+
"user_referred",
|
|
74
|
+
{}
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("without client", () => {
|
|
80
|
+
it("should not throw when client is undefined", () => {
|
|
81
|
+
expect(() => {
|
|
82
|
+
trackEvent(undefined, "share_button_clicked");
|
|
83
|
+
}).not.toThrow();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("should log debug message when client is undefined", () => {
|
|
87
|
+
trackEvent(undefined, "wallet_button_clicked");
|
|
88
|
+
|
|
89
|
+
expect(consoleDebugSpy).toHaveBeenCalledWith(
|
|
90
|
+
"[Frak] No client provided, skipping event tracking"
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should not call track when client is undefined", () => {
|
|
95
|
+
const trackMock = vi.fn();
|
|
96
|
+
const undefinedClient = undefined;
|
|
97
|
+
|
|
98
|
+
trackEvent(undefinedClient, "share_button_clicked");
|
|
99
|
+
|
|
100
|
+
expect(trackMock).not.toHaveBeenCalled();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("error handling", () => {
|
|
105
|
+
it("should catch and log errors from track()", () => {
|
|
106
|
+
const error = new Error("Track failed");
|
|
107
|
+
mockClient.openPanel = {
|
|
108
|
+
track: vi.fn().mockImplementation(() => {
|
|
109
|
+
throw error;
|
|
110
|
+
}),
|
|
111
|
+
} as any;
|
|
112
|
+
|
|
113
|
+
expect(() => {
|
|
114
|
+
trackEvent(mockClient, "share_button_clicked");
|
|
115
|
+
}).not.toThrow();
|
|
116
|
+
|
|
117
|
+
expect(consoleDebugSpy).toHaveBeenCalledWith(
|
|
118
|
+
"[Frak] Failed to track event:",
|
|
119
|
+
"share_button_clicked",
|
|
120
|
+
error
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should not throw when openPanel is undefined", () => {
|
|
125
|
+
const clientWithoutPanel = {} as FrakClient;
|
|
126
|
+
|
|
127
|
+
expect(() => {
|
|
128
|
+
trackEvent(clientWithoutPanel, "wallet_button_clicked");
|
|
129
|
+
}).not.toThrow();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("edge cases", () => {
|
|
134
|
+
it("should handle empty props object", () => {
|
|
135
|
+
trackEvent(mockClient, "share_button_clicked", {});
|
|
136
|
+
|
|
137
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
138
|
+
"share_button_clicked",
|
|
139
|
+
{}
|
|
140
|
+
);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("should handle complex props object", () => {
|
|
144
|
+
const complexProps = {
|
|
145
|
+
userId: "123",
|
|
146
|
+
metadata: {
|
|
147
|
+
page: "home",
|
|
148
|
+
section: "header",
|
|
149
|
+
},
|
|
150
|
+
tags: ["tag1", "tag2"],
|
|
151
|
+
timestamp: Date.now(),
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
trackEvent(mockClient, "user_referred", complexProps);
|
|
155
|
+
|
|
156
|
+
expect(mockClient.openPanel?.track).toHaveBeenCalledWith(
|
|
157
|
+
"user_referred",
|
|
158
|
+
complexProps
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|