@tonder.io/ionic-lite-sdk 1.0.1 → 1.0.2-beta.TEC-1207.53fb846

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.
Files changed (43) hide show
  1. package/README.md +38 -3
  2. package/dist/classes/3dsHandler.d.ts +26 -2
  3. package/dist/classes/BaseInlineCheckout.d.ts +12 -9
  4. package/dist/classes/liteCheckout.d.ts +1 -1
  5. package/dist/data/businessApi.d.ts +1 -1
  6. package/dist/data/coreApi.d.ts +15 -0
  7. package/dist/helpers/corePayment.d.ts +60 -0
  8. package/dist/helpers/safeUrl.d.ts +15 -0
  9. package/dist/helpers/sanitize3dsMarkup.d.ts +18 -0
  10. package/dist/helpers/utils.d.ts +1 -0
  11. package/dist/helpers/validations.d.ts +1 -0
  12. package/dist/index.js +1 -1
  13. package/dist/shared/constants/apiEndpoints.d.ts +2 -0
  14. package/dist/shared/utils/appError.d.ts +9 -0
  15. package/dist/types/commons.d.ts +5 -0
  16. package/dist/types/core.d.ts +28 -0
  17. package/jest.config.ts +11 -1
  18. package/package.json +1 -1
  19. package/src/classes/3dsHandler.ts +134 -30
  20. package/src/classes/BaseInlineCheckout.ts +128 -16
  21. package/src/classes/liteCheckout.ts +9 -2
  22. package/src/data/businessApi.ts +13 -6
  23. package/src/data/coreApi.ts +47 -0
  24. package/src/helpers/corePayment.ts +211 -0
  25. package/src/helpers/safeUrl.ts +26 -0
  26. package/src/helpers/sanitize3dsMarkup.ts +133 -0
  27. package/src/helpers/utils.ts +4 -0
  28. package/src/helpers/validations.ts +9 -0
  29. package/src/shared/constants/apiEndpoints.ts +2 -0
  30. package/src/shared/constants/messages.ts +4 -4
  31. package/src/shared/utils/appError.ts +28 -11
  32. package/src/types/commons.ts +5 -0
  33. package/src/types/core.ts +30 -0
  34. package/tests/coreBusinessConfig.test.ts +100 -0
  35. package/tests/corePayment.test.ts +393 -0
  36. package/tests/corePaymentCheckout.test.ts +668 -0
  37. package/tests/coreStartupFailure.test.ts +70 -0
  38. package/tests/redirectToChallenge.test.ts +149 -0
  39. package/tests/sanitize3dsMarkup.test.ts +248 -0
  40. package/tests/secureTokenBoundary.test.ts +81 -0
  41. package/tests/threeDsApiKey.test.ts +41 -0
  42. package/tests/threeDsCore.test.ts +444 -0
  43. package/tests/threeDsPolling.test.ts +45 -0
@@ -0,0 +1,444 @@
1
+ import { ThreeDSHandler } from "../src/classes/3dsHandler";
2
+ import { LiteCheckout } from "../src/classes/liteCheckout";
3
+ import { ErrorKeyEnum } from "../src/shared/enum/ErrorKeyEnum";
4
+
5
+ const API_KEY = "merchant-api-key";
6
+ const LEGACY_BASE = "https://stage.tonder.io";
7
+ const CORE_BASE = "https://api-stage.tonder.io";
8
+ const STORAGE_KEY = "verify_transaction_status_url";
9
+
10
+ const CORE_VERIFY_PATH = "/transactions/v1/0192b8a0-0000-7000-8000-000000000001";
11
+ const LEGACY_VERIFY_PATH = "/api/v1/tonder/ksk/business/7/payments/55/transactions/9";
12
+
13
+ // Stands for the rebuilt checkout-router body the SDK hands back for a core payment.
14
+ const buildCoreResult = (transaction: Record<string, any>) => ({
15
+ rebuilt: true,
16
+ transaction_status: transaction.status,
17
+ });
18
+
19
+ function buildHandler(): ThreeDSHandler {
20
+ return new ThreeDSHandler({
21
+ apiKey: API_KEY,
22
+ baseUrl: LEGACY_BASE,
23
+ coreBaseUrl: CORE_BASE,
24
+ redirectOnComplete: true,
25
+ buildCoreResult,
26
+ });
27
+ }
28
+
29
+ function payloadWithVerifyUrl(url: string) {
30
+ return {
31
+ next_action: {
32
+ redirect_to_url: {
33
+ url: "https://payflow.example.com/process?token=t",
34
+ return_url: "https://shop.example.com/done",
35
+ verify_transaction_status_url: url,
36
+ },
37
+ },
38
+ };
39
+ }
40
+
41
+ function stored(): Record<string, any> {
42
+ return JSON.parse(localStorage.getItem(STORAGE_KEY)!);
43
+ }
44
+
45
+ function storeItem(item: Record<string, unknown>) {
46
+ localStorage.setItem(
47
+ STORAGE_KEY,
48
+ JSON.stringify({ expires: Date.now() + 60_000, ...item }),
49
+ );
50
+ }
51
+
52
+ function jsonResponse(body: unknown, status = 200) {
53
+ return { status, ok: status < 400, json: async () => body };
54
+ }
55
+
56
+ const RAIL_SUCCESS = {
57
+ id: 9,
58
+ provider: "tonder",
59
+ status: "Success",
60
+ transaction_status: "Success",
61
+ amount: "100.00",
62
+ };
63
+
64
+ describe("3DS state keeps the engine of its payment", () => {
65
+ let fetchMock: jest.Mock;
66
+
67
+ beforeEach(() => {
68
+ localStorage.clear();
69
+ fetchMock = jest.fn();
70
+ (global as any).fetch = fetchMock;
71
+ });
72
+
73
+ it("stores the engine next to the verify URL", () => {
74
+ const handler = buildHandler();
75
+ handler.setEngine("core");
76
+ handler.setPayload(payloadWithVerifyUrl(CORE_VERIFY_PATH));
77
+
78
+ handler.saveVerifyTransactionUrl();
79
+
80
+ expect(stored()).toMatchObject({ url: CORE_VERIFY_PATH, engine: "core" });
81
+ });
82
+
83
+ it("stores a legacy payment as legacy by default", () => {
84
+ const handler = buildHandler();
85
+ handler.setPayload(payloadWithVerifyUrl(LEGACY_VERIFY_PATH));
86
+
87
+ handler.saveVerifyTransactionUrl();
88
+
89
+ expect(stored()).toMatchObject({ url: LEGACY_VERIFY_PATH, engine: "legacy" });
90
+ });
91
+
92
+ it("reads the engine back on a new instance, after the page reloaded", () => {
93
+ const first = buildHandler();
94
+ first.setEngine("core");
95
+ first.setPayload(payloadWithVerifyUrl(CORE_VERIFY_PATH));
96
+ first.saveVerifyTransactionUrl();
97
+
98
+ expect(buildHandler().getStoredEngine()).toBe("core");
99
+ });
100
+
101
+ it("treats a state stored before the engine existed as legacy", () => {
102
+ storeItem({ url: LEGACY_VERIFY_PATH });
103
+
104
+ expect(buildHandler().getStoredEngine()).toBe("legacy");
105
+ });
106
+
107
+ it("verifies a legacy payment against the monolith, as before", async () => {
108
+ storeItem({ url: LEGACY_VERIFY_PATH });
109
+ fetchMock.mockResolvedValue(jsonResponse(RAIL_SUCCESS));
110
+
111
+ const result = await buildHandler().verifyTransactionStatus();
112
+
113
+ expect(fetchMock.mock.calls[0][0]).toBe(`${LEGACY_BASE}${LEGACY_VERIFY_PATH}`);
114
+ expect(result).toEqual(RAIL_SUCCESS);
115
+ });
116
+
117
+ it("verifies a core payment with one GET to the core and the same credential", async () => {
118
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
119
+ fetchMock.mockResolvedValue(
120
+ jsonResponse({ id: "0192b8a0-0000-7000-8000-000000000001", status: "Success" }),
121
+ );
122
+
123
+ const result = await buildHandler().verifyTransactionStatus();
124
+
125
+ expect(fetchMock).toHaveBeenCalledTimes(1);
126
+ const [url, init] = fetchMock.mock.calls[0];
127
+ expect(url).toBe(`${CORE_BASE}${CORE_VERIFY_PATH}`);
128
+ expect(init.method).toBe("GET");
129
+ expect(init.headers.Authorization).toBe(`Token ${API_KEY}`);
130
+ expect(result).toEqual({ rebuilt: true, transaction_status: "Success" });
131
+ expect(localStorage.getItem(STORAGE_KEY)).toBeNull();
132
+ });
133
+
134
+ it.each(["Declined", "Failed", "Authorized"])(
135
+ "clears the state once a core payment is %s",
136
+ async (status) => {
137
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
138
+ fetchMock.mockResolvedValue(jsonResponse({ id: "x", status }));
139
+
140
+ const result = await buildHandler().verifyTransactionStatus();
141
+
142
+ expect(result).toEqual({ rebuilt: true, transaction_status: status });
143
+ expect(localStorage.getItem(STORAGE_KEY)).toBeNull();
144
+ },
145
+ );
146
+
147
+ it.each(["Pending", "Processing"])(
148
+ "keeps the verification state while a core payment is still %s",
149
+ async (status) => {
150
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
151
+ fetchMock.mockResolvedValue(jsonResponse({ id: "x", status }));
152
+
153
+ const result = await buildHandler().verifyTransactionStatus();
154
+
155
+ expect(result).toEqual({ rebuilt: true, transaction_status: status });
156
+ expect(stored()).toMatchObject({ url: CORE_VERIFY_PATH, engine: "core" });
157
+ },
158
+ );
159
+
160
+ it("decides open or final by the core's status, not by the rail's transaction_status", async () => {
161
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
162
+ fetchMock.mockResolvedValue(
163
+ jsonResponse({ id: "x", status: "Success", transaction_status: "Pending" }),
164
+ );
165
+ await buildHandler().verifyTransactionStatus();
166
+ expect(localStorage.getItem(STORAGE_KEY)).toBeNull();
167
+
168
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
169
+ fetchMock.mockResolvedValue(
170
+ jsonResponse({ id: "x", status: "Processing", transaction_status: "Declined" }),
171
+ );
172
+ await buildHandler().verifyTransactionStatus();
173
+ expect(stored()).toMatchObject({ engine: "core" });
174
+ });
175
+
176
+ it.each([500, 502, 503, 504, 429, 408])(
177
+ "keeps the core verification state after a transient %s and rejects with the status",
178
+ async (status) => {
179
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
180
+ fetchMock.mockResolvedValue(jsonResponse({}, status));
181
+
182
+ await expect(buildHandler().verifyTransactionStatus()).rejects.toMatchObject({
183
+ code: ErrorKeyEnum.FETCH_TRANSACTION_ERROR,
184
+ statusCode: status,
185
+ });
186
+
187
+ expect(stored()).toMatchObject({ url: CORE_VERIFY_PATH, engine: "core" });
188
+ },
189
+ );
190
+
191
+ it.each([400, 401, 403, 404])(
192
+ "clears the core verification state after a %s: the payment cannot be read",
193
+ async (status) => {
194
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
195
+ fetchMock.mockResolvedValue(jsonResponse({}, status));
196
+
197
+ await expect(buildHandler().verifyTransactionStatus()).rejects.toMatchObject({
198
+ code: ErrorKeyEnum.FETCH_TRANSACTION_ERROR,
199
+ statusCode: status,
200
+ });
201
+
202
+ expect(localStorage.getItem(STORAGE_KEY)).toBeNull();
203
+ },
204
+ );
205
+
206
+ it("keeps the core verification state after a network error and rejects", async () => {
207
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
208
+ fetchMock.mockRejectedValue(new TypeError("Failed to fetch"));
209
+
210
+ await expect(buildHandler().verifyTransactionStatus()).rejects.toMatchObject({
211
+ code: ErrorKeyEnum.FETCH_TRANSACTION_ERROR,
212
+ });
213
+
214
+ expect(stored()).toMatchObject({ engine: "core" });
215
+ });
216
+
217
+ it("still answers a legacy payment's refused verify with the raw response and clears the state", async () => {
218
+ storeItem({ url: LEGACY_VERIFY_PATH });
219
+ const refused = jsonResponse({}, 500);
220
+ fetchMock.mockResolvedValue(refused);
221
+
222
+ await expect(buildHandler().verifyTransactionStatus()).resolves.toBe(refused);
223
+
224
+ expect(localStorage.getItem(STORAGE_KEY)).toBeNull();
225
+ });
226
+
227
+ it("still answers undefined and clears the state of a legacy payment after a network error", async () => {
228
+ storeItem({ url: LEGACY_VERIFY_PATH });
229
+ fetchMock.mockRejectedValue(new TypeError("Failed to fetch"));
230
+
231
+ await expect(buildHandler().verifyTransactionStatus()).resolves.toBeUndefined();
232
+
233
+ expect(localStorage.getItem(STORAGE_KEY)).toBeNull();
234
+ });
235
+
236
+ it("stops the iframe poller on the core's final status only", () => {
237
+ const core = buildHandler();
238
+ core.setEngine("core");
239
+ const legacy = buildHandler();
240
+
241
+ expect(core.isVerificationFinal({ status: "Processing", transaction_status: "Declined" })).toBe(false);
242
+ expect(core.isVerificationFinal({ status: "Pending" })).toBe(false);
243
+ expect(core.isVerificationFinal({ status: "Success", transaction_status: "Pending" })).toBe(true);
244
+ expect(legacy.isVerificationFinal({ transaction_status: "Processing" })).toBe(true);
245
+ expect(legacy.isVerificationFinal({ transaction_status: "Pending" })).toBe(false);
246
+ });
247
+
248
+ it.each([502, 429])("keeps the iframe poller of a core payment going after a %s", async (status) => {
249
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
250
+ fetchMock.mockResolvedValue(jsonResponse({}, status));
251
+ const handler = buildHandler();
252
+ handler.setEngine("core");
253
+
254
+ const polled = await handler.requestTransactionStatus();
255
+
256
+ expect(handler.isVerificationFinal(polled)).toBe(false);
257
+ });
258
+
259
+ it("keeps the poller going when a core answer is not JSON", async () => {
260
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
261
+ fetchMock.mockResolvedValue({
262
+ status: 200,
263
+ json: async () => {
264
+ throw new SyntaxError("Unexpected token <");
265
+ },
266
+ });
267
+ const handler = buildHandler();
268
+
269
+ const polled = await handler.requestTransactionStatus();
270
+
271
+ expect(handler.isVerificationFinal(polled)).toBe(false);
272
+ });
273
+
274
+ it("keeps polling under either rule, whatever engine the handler has meanwhile", async () => {
275
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
276
+ fetchMock.mockResolvedValue(jsonResponse({}, 503));
277
+ const handler = buildHandler();
278
+
279
+ const polled = await handler.requestTransactionStatus();
280
+
281
+ handler.setEngine("legacy");
282
+ expect(handler.isVerificationFinal(polled)).toBe(false);
283
+ handler.setEngine("core");
284
+ expect(handler.isVerificationFinal(polled)).toBe(false);
285
+ });
286
+
287
+ it("stops the iframe poller of a core payment after a 404", async () => {
288
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
289
+ fetchMock.mockResolvedValue(jsonResponse({}, 404));
290
+
291
+ await expect(buildHandler().requestTransactionStatus()).resolves.toBeNull();
292
+ });
293
+
294
+ it("authenticates a core verify with the deprecated apiKeyTonder when it is the only key", async () => {
295
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
296
+ fetchMock.mockResolvedValue(jsonResponse({ id: "x", status: "Success" }));
297
+ const checkout = new LiteCheckout({ mode: "stage", apiKeyTonder: "deprecated-key" } as any);
298
+
299
+ await checkout.process3ds.verifyTransactionStatus();
300
+
301
+ expect(fetchMock.mock.calls[0][0]).toBe(`${CORE_BASE}${CORE_VERIFY_PATH}`);
302
+ expect(fetchMock.mock.calls[0][1].headers.Authorization).toBe("Token deprecated-key");
303
+ });
304
+
305
+ it("still clears the state of a legacy payment that answers Pending, as before", async () => {
306
+ storeItem({ url: LEGACY_VERIFY_PATH });
307
+ fetchMock.mockResolvedValue(jsonResponse({ status: "Pending" }));
308
+
309
+ await buildHandler().verifyTransactionStatus();
310
+
311
+ expect(localStorage.getItem(STORAGE_KEY)).toBeNull();
312
+ });
313
+
314
+ it("polls a core payment's status against the core and answers the payment as the core has it", async () => {
315
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
316
+ fetchMock.mockResolvedValue(jsonResponse({ id: "x", status: "Success" }));
317
+
318
+ const polled = await buildHandler().requestTransactionStatus();
319
+
320
+ expect(fetchMock.mock.calls[0][0]).toBe(`${CORE_BASE}${CORE_VERIFY_PATH}`);
321
+ expect(polled).toEqual({ id: "x", status: "Success" });
322
+ });
323
+
324
+ it("keeps an absolute verify URL as it is", async () => {
325
+ storeItem({ url: `https://other.example.com${CORE_VERIFY_PATH}`, engine: "core" });
326
+ fetchMock.mockResolvedValue(jsonResponse({ id: "x", status: "Success" }));
327
+
328
+ await buildHandler().requestTransactionStatus();
329
+
330
+ expect(fetchMock.mock.calls[0][0]).toBe(`https://other.example.com${CORE_VERIFY_PATH}`);
331
+ });
332
+ });
333
+
334
+ describe("verify3dsTransaction after the buyer returns", () => {
335
+ let fetchMock: jest.Mock;
336
+ let checkout: LiteCheckout;
337
+
338
+ beforeEach(() => {
339
+ localStorage.clear();
340
+ fetchMock = jest.fn();
341
+ (global as any).fetch = fetchMock;
342
+ checkout = new LiteCheckout({ mode: "stage", apiKey: API_KEY });
343
+ });
344
+
345
+ it("does not send the buyer back to a challenge already used by a still-open core payment", async () => {
346
+ storeItem({ url: CORE_VERIFY_PATH, engine: "core" });
347
+ const open = {
348
+ id: "x",
349
+ status: "Pending",
350
+ next_action: {
351
+ redirect_to_url: {
352
+ url: "https://payflow.example.com/process?token=t",
353
+ verify_transaction_status_url: CORE_VERIFY_PATH,
354
+ },
355
+ },
356
+ };
357
+ fetchMock.mockResolvedValue(jsonResponse(open));
358
+ const realLocation = Object.getOwnPropertyDescriptor(window, "location")!;
359
+ const location = { href: "https://localhost/" };
360
+ Object.defineProperty(window, "location", { configurable: true, writable: true, value: location });
361
+
362
+ try {
363
+ const result = await checkout.verify3dsTransaction();
364
+
365
+ expect(result).toMatchObject({ next_action: open.next_action });
366
+ expect(window.location).toBe(location);
367
+ expect(location.href).toBe("https://localhost/");
368
+ expect(stored()).toMatchObject({ url: CORE_VERIFY_PATH, engine: "core" });
369
+ } finally {
370
+ Object.defineProperty(window, "location", realLocation);
371
+ }
372
+ });
373
+
374
+ it("stores a challenge found while resuming a legacy payment under the legacy engine", async () => {
375
+ storeItem({ url: LEGACY_VERIFY_PATH });
376
+ checkout.process3ds.setEngine("core");
377
+ fetchMock
378
+ .mockResolvedValueOnce(
379
+ jsonResponse({ status: "Declined", transaction_status: "Declined", checkout_id: "chk-1" }),
380
+ )
381
+ .mockResolvedValueOnce({
382
+ ok: true,
383
+ status: 201,
384
+ json: async () => ({
385
+ transaction_status: "Pending",
386
+ next_action: {
387
+ redirect_to_url: {
388
+ url: "https://acs.example.com/challenge",
389
+ verify_transaction_status_url: LEGACY_VERIFY_PATH,
390
+ },
391
+ },
392
+ }),
393
+ });
394
+ const realLocation = Object.getOwnPropertyDescriptor(window, "location")!;
395
+ Object.defineProperty(window, "location", {
396
+ configurable: true,
397
+ writable: true,
398
+ value: { href: "https://localhost/" },
399
+ });
400
+
401
+ try {
402
+ await checkout.verify3dsTransaction();
403
+
404
+ expect(stored()).toMatchObject({ url: LEGACY_VERIFY_PATH, engine: "legacy" });
405
+ } finally {
406
+ Object.defineProperty(window, "location", realLocation);
407
+ }
408
+ });
409
+
410
+ it("reports a failed verification of the iframe branch instead of leaving it unhandled", async () => {
411
+ const failure = new Error("core unavailable");
412
+ jest.spyOn(checkout.process3ds, "loadIframe").mockResolvedValue(true);
413
+ jest.spyOn(checkout.process3ds, "verifyTransactionStatus").mockRejectedValue(failure);
414
+ const report = jest.spyOn(checkout as any, "reportSdkError").mockImplementation(() => {});
415
+ const payload = { next_action: { iframe_resources: { iframe: "<form></form>" } } };
416
+
417
+ await checkout._handle3dsRedirect(payload as any);
418
+ await new Promise((resolve) => setTimeout(resolve, 0));
419
+
420
+ expect(report).toHaveBeenCalledWith(
421
+ failure,
422
+ expect.objectContaining({ feature: "3ds-verification" }),
423
+ );
424
+ });
425
+
426
+ it("still resumes a declined legacy payment through checkout-router", async () => {
427
+ storeItem({ url: LEGACY_VERIFY_PATH });
428
+ const declined = {
429
+ status: "Declined",
430
+ transaction_status: "Declined",
431
+ checkout_id: "chk-1",
432
+ is_route_finished: false,
433
+ };
434
+ fetchMock
435
+ .mockResolvedValueOnce(jsonResponse(declined))
436
+ .mockResolvedValueOnce({ ok: true, status: 201, json: async () => RAIL_SUCCESS });
437
+
438
+ await checkout.verify3dsTransaction();
439
+
440
+ expect(fetchMock.mock.calls[0][0]).toBe(`${LEGACY_BASE}${LEGACY_VERIFY_PATH}`);
441
+ expect(fetchMock.mock.calls[1][0]).toBe(`${LEGACY_BASE}/api/v1/checkout-router/`);
442
+ expect(JSON.parse(fetchMock.mock.calls[1][1].body)).toEqual({ checkout_id: "chk-1" });
443
+ });
444
+ });
@@ -0,0 +1,45 @@
1
+ import { ThreeDSHandler } from "../src/classes/3dsHandler";
2
+
3
+ const STORAGE_KEY = "verify_transaction_status_url";
4
+
5
+ function buildHandler() {
6
+ return new ThreeDSHandler({ apiKey: "key", baseUrl: "https://stage.tonder.io" });
7
+ }
8
+
9
+ describe("polling the verification status without stored state", () => {
10
+ let fetchMock: jest.Mock;
11
+
12
+ beforeEach(() => {
13
+ localStorage.clear();
14
+ fetchMock = jest.fn();
15
+ (global as any).fetch = fetchMock;
16
+ });
17
+
18
+ it("answers null instead of throwing when nothing is stored", async () => {
19
+ await expect(buildHandler().requestTransactionStatus()).resolves.toBeNull();
20
+ expect(fetchMock).not.toHaveBeenCalled();
21
+ });
22
+
23
+ it("answers null instead of throwing when the stored state expired", async () => {
24
+ localStorage.setItem(
25
+ STORAGE_KEY,
26
+ JSON.stringify({ url: "/api/v1/x", expires: Date.now() - 1000 }),
27
+ );
28
+
29
+ await expect(buildHandler().requestTransactionStatus()).resolves.toBeNull();
30
+ expect(fetchMock).not.toHaveBeenCalled();
31
+ });
32
+
33
+ it("still polls the stored URL", async () => {
34
+ localStorage.setItem(
35
+ STORAGE_KEY,
36
+ JSON.stringify({ url: "/api/v1/x", expires: Date.now() + 60_000 }),
37
+ );
38
+ fetchMock.mockResolvedValue({ status: 200, json: async () => ({ transaction_status: "Success" }) });
39
+
40
+ await expect(buildHandler().requestTransactionStatus()).resolves.toEqual({
41
+ transaction_status: "Success",
42
+ });
43
+ expect(fetchMock.mock.calls[0][0]).toBe("https://stage.tonder.io/api/v1/x");
44
+ });
45
+ });