-
Notifications
You must be signed in to change notification settings - Fork 576
/
Copy pathappSwithResume.test.js
126 lines (103 loc) · 3.84 KB
/
appSwithResume.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* @flow */
import { vi, describe, expect } from "vitest";
import {
isAppSwitchResumeFlow,
getAppSwitchResumeParams,
} from "./appSwitchResume";
describe("app switch resume flow", () => {
afterEach(() => {
vi.clearAllMocks();
vi.unstubAllGlobals();
});
const buttonSessionID = "uid_button_session_123444";
const orderID = "EC-1223114";
const fundingSource = "paypal";
test("should test fetching resume params when its non resume flow", () => {
const params = getAppSwitchResumeParams();
expect.assertions(2);
expect(params).toEqual(null);
expect(isAppSwitchResumeFlow()).toEqual(false);
});
test("should test fetching resume params when parameters are correctly passed", () => {
vi.spyOn(window, "location", "get").mockReturnValue({
hash: `#onApprove?buttonSessionID=${buttonSessionID}&token=${orderID}&fundingSource=${fundingSource}`,
});
const params = getAppSwitchResumeParams();
expect.assertions(2);
expect(params).toEqual({
buttonSessionID,
checkoutState: "onApprove",
fundingSource,
orderID,
});
expect(isAppSwitchResumeFlow()).toEqual(true);
});
test("should test fetching resume params with invalid callback passed", () => {
vi.spyOn(window, "location", "get").mockReturnValue({
hash: "#Unknown",
});
const params = getAppSwitchResumeParams();
expect.assertions(2);
expect(params).toEqual(null);
expect(isAppSwitchResumeFlow()).toEqual(false);
});
test("should test null fetching resume params with invalid callback passed", () => {
vi.spyOn(window, "location", "get").mockReturnValue({
hash: `#Unknown?buttonSessionID=${buttonSessionID}&token=${orderID}&fundingSource=${fundingSource}`,
});
const params = getAppSwitchResumeParams();
expect.assertions(2);
expect(params).toEqual(null);
expect(isAppSwitchResumeFlow()).toEqual(false);
});
test("should test fetching multiple resume params when parameters are correctly passed", () => {
vi.spyOn(window, "location", "get").mockReturnValue({
hash: `#onApprove?buttonSessionID=${buttonSessionID}&token=${orderID}&fundingSource=${fundingSource}&billingToken=BA-124&PayerID=PP-payer-122&paymentID=PAY-123&subscriptionID=I-1234&vaultSetupToken=VA-3`,
});
const params = getAppSwitchResumeParams();
expect.assertions(2);
expect(params).toEqual({
billingToken: "BA-124",
buttonSessionID,
checkoutState: "onApprove",
fundingSource,
orderID,
payerID: "PP-payer-122",
paymentID: "PAY-123",
subscriptionID: "I-1234",
vaultSetupToken: "VA-3",
});
expect(isAppSwitchResumeFlow()).toEqual(true);
});
test("should test onApprove resume params when parameters are passed from web fallback", () => {
vi.spyOn(window, "location", "get").mockReturnValue({
search: `?buttonSessionID=${buttonSessionID}&token=${orderID}&fundingSource=${fundingSource}&vaultSetupToken=VA-3&PayerID=PP123456`,
});
const params = getAppSwitchResumeParams();
expect.assertions(2);
expect(params).toEqual({
buttonSessionID,
checkoutState: "onApprove",
fundingSource,
orderID,
payerID: "PP123456",
vaultSetupToken: "VA-3",
});
expect(isAppSwitchResumeFlow()).toEqual(true);
});
test("should test onCancel resume params when parameters are passed from web fallback", () => {
vi.spyOn(window, "location", "get").mockReturnValue({
search: `?buttonSessionID=${buttonSessionID}&token=${orderID}&fundingSource=${fundingSource}&vaultSetupToken=VA-3`,
});
const params = getAppSwitchResumeParams();
expect.assertions(2);
expect(params).toEqual({
buttonSessionID,
checkoutState: "onCancel",
fundingSource,
orderID,
vaultSetupToken: "VA-3",
});
expect(isAppSwitchResumeFlow()).toEqual(true);
});
});