|
| 1 | +import { describe, expect, test } from "vitest"; |
| 2 | + |
| 3 | +import { buildWalletActionDeepLink } from "./deeplinks.js"; |
| 4 | + |
| 5 | +describe("buildWalletActionDeepLink", () => { |
| 6 | + describe("without partner", () => { |
| 7 | + test("returns base URL when no context", () => { |
| 8 | + expect(buildWalletActionDeepLink("swap")).toBe("ledgerwallet://swap"); |
| 9 | + expect(buildWalletActionDeepLink("send")).toBe("ledgerwallet://send"); |
| 10 | + expect(buildWalletActionDeepLink("buy")).toBe("ledgerwallet://buy"); |
| 11 | + }); |
| 12 | + |
| 13 | + test("appends currency params when context has currency", () => { |
| 14 | + expect(buildWalletActionDeepLink("send", { currency: "eth" })).toBe( |
| 15 | + "ledgerwallet://send?currency=eth", |
| 16 | + ); |
| 17 | + expect(buildWalletActionDeepLink("swap", { currency: "usdc" })).toBe( |
| 18 | + "ledgerwallet://swap?fromToken=usdc", |
| 19 | + ); |
| 20 | + expect(buildWalletActionDeepLink("earn", { currency: "btc" })).toBe( |
| 21 | + "ledgerwallet://earn?cryptoAssetId=btc", |
| 22 | + ); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + describe("with partner", () => { |
| 27 | + test("appends tracking query params with fixed deeplinkType and deeplinkChannel", () => { |
| 28 | + const url = buildWalletActionDeepLink("swap", undefined, "MyPartner"); |
| 29 | + expect(url).toContain("deeplinkType=Internal"); |
| 30 | + expect(url).toContain("deeplinkChannel=Button"); |
| 31 | + expect(url).toContain("deeplinkDestination=swap"); |
| 32 | + expect(url).toContain("deeplinkButtonPartner=MyPartner"); |
| 33 | + }); |
| 34 | + |
| 35 | + test("maps each action to correct deeplinkDestination (same as route)", () => { |
| 36 | + const partner = "Partner"; |
| 37 | + expect(buildWalletActionDeepLink("send", undefined, partner)).toContain( |
| 38 | + "deeplinkDestination=send", |
| 39 | + ); |
| 40 | + expect(buildWalletActionDeepLink("receive", undefined, partner)).toContain( |
| 41 | + "deeplinkDestination=receive", |
| 42 | + ); |
| 43 | + expect(buildWalletActionDeepLink("swap", undefined, partner)).toContain( |
| 44 | + "deeplinkDestination=swap", |
| 45 | + ); |
| 46 | + expect(buildWalletActionDeepLink("buy", undefined, partner)).toContain( |
| 47 | + "deeplinkDestination=buy", |
| 48 | + ); |
| 49 | + expect(buildWalletActionDeepLink("earn", undefined, partner)).toContain( |
| 50 | + "deeplinkDestination=earn", |
| 51 | + ); |
| 52 | + expect(buildWalletActionDeepLink("sell", undefined, partner)).toContain( |
| 53 | + "deeplinkDestination=buy", |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + test("preserves existing currency params when partner is provided", () => { |
| 58 | + const url = buildWalletActionDeepLink( |
| 59 | + "swap", |
| 60 | + { currency: "eth" }, |
| 61 | + "MyPartner", |
| 62 | + ); |
| 63 | + expect(url).toContain("fromToken=eth"); |
| 64 | + expect(url).toContain("deeplinkType=Internal"); |
| 65 | + expect(url).toContain("deeplinkButtonPartner=MyPartner"); |
| 66 | + }); |
| 67 | + |
| 68 | + test("URL-encodes partner with special characters", () => { |
| 69 | + const url = buildWalletActionDeepLink("buy", undefined, "Partner & Co"); |
| 70 | + expect(url).toContain("deeplinkButtonPartner=Partner+%26+Co"); |
| 71 | + }); |
| 72 | + }); |
| 73 | +}); |
0 commit comments