@rebilly/instruments 4.4.0 → 4.6.0
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/.babelrc +24 -26
- package/CHANGELOG.md +14 -0
- package/dist/index.js +14 -40
- package/dist/index.min.js +14 -40
- package/package.json +16 -5
- package/project.json +9 -0
- package/rollup.config.mjs +21 -26
- package/src/data/options-schema/index.js +94 -78
- package/src/data/options-schema/schemas/options-schema.js +420 -408
- package/src/events/base-event.js +34 -34
- package/src/events/events.spec.js +6 -6
- package/src/events/index.js +5 -5
- package/src/functions/destroy.js +19 -19
- package/src/functions/destroy.spec.js +41 -41
- package/src/functions/mount/fetch-data.js +200 -193
- package/src/functions/mount/fetch-data.spec.js +287 -285
- package/src/functions/mount/get-lead-source-data.js +31 -31
- package/src/functions/mount/get-lead-source-data.spec.js +19 -19
- package/src/functions/mount/index.js +73 -65
- package/src/functions/mount/mount.spec.js +77 -66
- package/src/functions/mount/setup-element.js +23 -23
- package/src/functions/mount/setup-framepay-theme.js +86 -68
- package/src/functions/mount/setup-framepay.js +9 -5
- package/src/functions/mount/setup-i18n.js +15 -15
- package/src/functions/mount/setup-options.js +74 -74
- package/src/functions/mount/setup-options.spec.js +325 -289
- package/src/functions/mount/setup-storefront.js +15 -20
- package/src/functions/mount/setup-styles-vars.js +19 -22
- package/src/functions/mount/setup-user-flow.js +51 -47
- package/src/functions/on.js +5 -5
- package/src/functions/on.spec.js +60 -51
- package/src/functions/purchase.js +149 -134
- package/src/functions/purchase.spec.js +59 -56
- package/src/functions/setup.js +53 -49
- package/src/functions/setup.spec.js +88 -75
- package/src/functions/show.js +13 -14
- package/src/functions/show.spec.js +53 -53
- package/src/functions/update.js +30 -28
- package/src/functions/update.spec.js +94 -93
- package/src/i18n/en.json +32 -32
- package/src/i18n/es.json +29 -29
- package/src/i18n/i18n.spec.js +18 -18
- package/src/i18n/index.js +48 -48
- package/src/instance.js +36 -36
- package/src/instance.spec.js +29 -27
- package/src/loader/index.js +95 -70
- package/src/loader/loader.spec.js +63 -63
- package/src/state/iframes.js +21 -21
- package/src/state/index.js +56 -54
- package/src/storefront/account-and-website.js +10 -8
- package/src/storefront/account-and-website.spec.js +55 -55
- package/src/storefront/deposit-requests.js +6 -6
- package/src/storefront/fetch-plans-from-addons-bumpOffer.js +21 -19
- package/src/storefront/fetch-products-from-plans.js +52 -51
- package/src/storefront/fetch-products-from-plans.spec.js +90 -87
- package/src/storefront/index.js +56 -49
- package/src/storefront/invoices.js +15 -15
- package/src/storefront/invoices.spec.js +69 -65
- package/src/storefront/models/account-model.js +29 -32
- package/src/storefront/models/base-model.js +6 -9
- package/src/storefront/models/deposit-request-model.js +22 -13
- package/src/storefront/models/invoice-model.js +16 -16
- package/src/storefront/models/payment-metadata.js +4 -4
- package/src/storefront/models/plan-model.js +73 -64
- package/src/storefront/models/ready-to-pay-model.js +59 -59
- package/src/storefront/models/summary-model.js +43 -46
- package/src/storefront/models/transaction-model.js +11 -14
- package/src/storefront/payment-instruments.js +38 -35
- package/src/storefront/payment-instruments.spec.js +81 -62
- package/src/storefront/purchase.js +50 -44
- package/src/storefront/purchase.spec.js +40 -40
- package/src/storefront/ready-to-pay.js +75 -77
- package/src/storefront/ready-to-pay.spec.js +59 -54
- package/src/storefront/storefront.spec.js +9 -9
- package/src/storefront/summary.js +93 -67
- package/src/storefront/summary.spec.js +108 -106
- package/src/storefront/transactions.js +6 -6
- package/src/style/base/default-theme.js +928 -923
- package/src/style/base/theme.js +21 -21
- package/src/style/base/theme.spec.js +13 -13
- package/src/style/index.js +3 -3
- package/src/style/utils/border.js +40 -27
- package/src/style/utils/color-values.js +18 -18
- package/src/style/utils/minifyCss.js +6 -6
- package/src/utils/add-dom-element.js +14 -14
- package/src/utils/format-currency.js +6 -5
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/index.js +6 -6
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +22 -22
- package/src/utils/quantity.js +26 -28
- package/src/utils/sleep.js +3 -1
- package/src/views/amount-selector.js +37 -36
- package/src/views/common/iframe/base-iframe.js +53 -52
- package/src/views/common/iframe/events/change-iframe-src-handler.js +5 -5
- package/src/views/common/iframe/events/dispatch-event-handler.js +4 -4
- package/src/views/common/iframe/events/resize-component-handler.js +8 -8
- package/src/views/common/iframe/events/show-error-handler.js +2 -2
- package/src/views/common/iframe/events/stop-loader-handler.js +8 -8
- package/src/views/common/iframe/events/update-addons-handler.js +20 -13
- package/src/views/common/iframe/events/update-coupons-handler.js +9 -9
- package/src/views/common/iframe/events/update-items-handler.js +26 -22
- package/src/views/common/iframe/modal-iframe.js +67 -56
- package/src/views/common/iframe/view-iframe.js +11 -11
- package/src/views/common/render-utilities.js +2 -2
- package/src/views/confirmation.js +33 -30
- package/src/views/errors.js +89 -79
- package/src/views/form.js +41 -37
- package/src/views/method-selector/express-methods.js +46 -46
- package/src/views/method-selector/generate-digital-wallet.js +46 -45
- package/src/views/method-selector/generate-digital-wallet.spec.js +104 -102
- package/src/views/method-selector/generate-framepay-config.js +53 -51
- package/src/views/method-selector/generate-framepay-config.spec.js +197 -173
- package/src/views/method-selector/get-method-data.js +5 -6
- package/src/views/method-selector/get-payment-methods.js +18 -16
- package/src/views/method-selector/get-payment-methods.spec.js +29 -27
- package/src/views/method-selector/index.js +154 -139
- package/src/views/method-selector/method-selector.spec.js +13 -13
- package/src/views/method-selector/mount-bump-offer.js +65 -49
- package/src/views/method-selector/mount-express-methods.js +89 -85
- package/src/views/modal.js +74 -67
- package/src/views/result.js +14 -14
- package/src/views/summary.js +25 -26
- package/tests/async-utilities.js +13 -13
- package/tests/mocks/framepay-mock.js +9 -8
- package/tests/mocks/rebilly-api-mock.js +5 -3
- package/tests/mocks/rebilly-instruments-mock.js +121 -117
- package/tests/mocks/storefront-api-mock.js +55 -48
- package/tests/mocks/storefront-mock.js +10 -14
- package/tests/msw/server.js +6 -6
- package/tests/setup-test.js +14 -16
- package/vitest.config.js +14 -14
- package/.eslintrc.js +0 -34
- package/.prettierrc.js +0 -11
|
@@ -3,313 +3,315 @@ import { fetchData, DataInstance } from './fetch-data';
|
|
|
3
3
|
import TransactionModel from '@/storefront/models/transaction-model';
|
|
4
4
|
|
|
5
5
|
describe('fetchData function', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
it('Should use correct invoice id for invoiceId', async () => {
|
|
7
|
+
const mockFetchInvoiceAndProducts = vi.fn();
|
|
8
|
+
const invoiceId = 'test-invoice-id';
|
|
9
|
+
StorefontTestingInstance({
|
|
10
|
+
options: {
|
|
11
|
+
invoiceId,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
await fetchData({
|
|
16
|
+
fetchInvoiceAndProducts: mockFetchInvoiceAndProducts,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(mockFetchInvoiceAndProducts).toBeCalledTimes(1);
|
|
20
|
+
expect(mockFetchInvoiceAndProducts).toBeCalledWith(
|
|
21
|
+
expect.objectContaining({
|
|
22
|
+
data: {
|
|
23
|
+
id: invoiceId,
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
13
27
|
});
|
|
14
28
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
it('Should use correct invoice id for transaction with invoiceIds', async () => {
|
|
30
|
+
const mockFetchInvoiceAndProducts = vi.fn();
|
|
31
|
+
const invoiceId = 'test-invoice-id';
|
|
32
|
+
StorefontTestingInstance({
|
|
33
|
+
data: {
|
|
34
|
+
transaction: new TransactionModel({
|
|
35
|
+
invoiceIds: [invoiceId],
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
await fetchData({
|
|
41
|
+
fetchInvoiceAndProducts: mockFetchInvoiceAndProducts,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(mockFetchInvoiceAndProducts).toBeCalledTimes(1);
|
|
45
|
+
expect(mockFetchInvoiceAndProducts).toBeCalledWith(
|
|
46
|
+
expect.objectContaining({
|
|
47
|
+
data: {
|
|
48
|
+
id: invoiceId,
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
38
52
|
});
|
|
39
53
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
StorefontTestingInstance({
|
|
57
|
-
options: {},
|
|
58
|
-
data: {
|
|
59
|
-
transaction: new TransactionModel({
|
|
60
|
-
invoiceIds: []
|
|
61
|
-
}),
|
|
62
|
-
}
|
|
54
|
+
it('Should not fetch invoice for transaction with no invoice Ids', async () => {
|
|
55
|
+
const mockFetchInvoiceAndProducts = vi.fn();
|
|
56
|
+
StorefontTestingInstance({
|
|
57
|
+
options: {},
|
|
58
|
+
data: {
|
|
59
|
+
transaction: new TransactionModel({
|
|
60
|
+
invoiceIds: [],
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
fetchData({
|
|
66
|
+
fetchInvoiceAndProducts: mockFetchInvoiceAndProducts,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(mockFetchInvoiceAndProducts).toBeCalledTimes(0);
|
|
63
70
|
});
|
|
64
71
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
it ('Should fetch account when JWT is supplied', async () => {
|
|
74
|
-
const mockFetchAccountAndWebsite = vi.fn();
|
|
75
|
-
StorefontTestingInstance({
|
|
76
|
-
options: {
|
|
77
|
-
jwt: 'TEST_JWT'
|
|
78
|
-
}
|
|
79
|
-
});
|
|
72
|
+
it('Should fetch account when JWT is supplied', async () => {
|
|
73
|
+
const mockFetchAccountAndWebsite = vi.fn();
|
|
74
|
+
StorefontTestingInstance({
|
|
75
|
+
options: {
|
|
76
|
+
jwt: 'TEST_JWT',
|
|
77
|
+
},
|
|
78
|
+
});
|
|
80
79
|
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
await fetchData({
|
|
81
|
+
fetchAccountAndWebsite: mockFetchAccountAndWebsite,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(mockFetchAccountAndWebsite).toBeCalledTimes(1);
|
|
83
85
|
});
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
it('Should not fetch account when there JWT is not supplied', async () => {
|
|
88
|
+
const mockFetchAccountAndWebsite = vi.fn();
|
|
89
|
+
StorefontTestingInstance({
|
|
90
|
+
options: {},
|
|
91
|
+
});
|
|
87
92
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
options: {}
|
|
92
|
-
});
|
|
93
|
+
await fetchData({
|
|
94
|
+
fetchAccountAndWebsite: mockFetchAccountAndWebsite,
|
|
95
|
+
});
|
|
93
96
|
|
|
94
|
-
|
|
95
|
-
fetchAccountAndWebsite: mockFetchAccountAndWebsite,
|
|
97
|
+
expect(mockFetchAccountAndWebsite).toBeCalledTimes(0);
|
|
96
98
|
});
|
|
97
|
-
|
|
98
|
-
expect(mockFetchAccountAndWebsite).toBeCalledTimes(0);
|
|
99
|
-
});
|
|
100
99
|
});
|
|
101
100
|
|
|
102
101
|
describe('DataInstance', () => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
describe('isPayment', () => {
|
|
185
|
-
it ('money is truthy', () => {
|
|
186
|
-
StorefontTestingInstance({
|
|
187
|
-
options: {
|
|
188
|
-
money: true
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
const fetchedData = new DataInstance();
|
|
192
|
-
expect(fetchedData.isPayment).toBeTruthy();
|
|
102
|
+
describe('Determining amountAndCurrency', () => {
|
|
103
|
+
it('should use money option', () => {
|
|
104
|
+
const expectedAmountAndCurrency = {
|
|
105
|
+
amount: 10,
|
|
106
|
+
currency: 'USD',
|
|
107
|
+
};
|
|
108
|
+
StorefontTestingInstance({
|
|
109
|
+
options: {
|
|
110
|
+
money: expectedAmountAndCurrency,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
const fetchedData = new DataInstance();
|
|
114
|
+
|
|
115
|
+
expect(fetchedData.amountAndCurrency).toEqual(
|
|
116
|
+
expectedAmountAndCurrency,
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should use preview Purchase', () => {
|
|
121
|
+
const expectedAmountAndCurrency = {
|
|
122
|
+
amount: 10,
|
|
123
|
+
currency: 'USD',
|
|
124
|
+
};
|
|
125
|
+
StorefontTestingInstance();
|
|
126
|
+
|
|
127
|
+
const fetchedData = new DataInstance({
|
|
128
|
+
previewPurchase: {
|
|
129
|
+
total: expectedAmountAndCurrency.amount,
|
|
130
|
+
currency: expectedAmountAndCurrency.currency,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
expect(fetchedData.amountAndCurrency).toEqual(
|
|
134
|
+
expect.objectContaining(expectedAmountAndCurrency),
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should use invoice', () => {
|
|
139
|
+
const expectedAmountAndCurrency = {
|
|
140
|
+
amount: 10,
|
|
141
|
+
currency: 'USD',
|
|
142
|
+
};
|
|
143
|
+
StorefontTestingInstance();
|
|
144
|
+
|
|
145
|
+
const fetchedData = new DataInstance({
|
|
146
|
+
invoice: {
|
|
147
|
+
...expectedAmountAndCurrency,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
expect(fetchedData.amountAndCurrency).toEqual(
|
|
151
|
+
expect.objectContaining(expectedAmountAndCurrency),
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should use transaction', () => {
|
|
156
|
+
const expectedAmountAndCurrency = {
|
|
157
|
+
amount: 10,
|
|
158
|
+
currency: 'USD',
|
|
159
|
+
};
|
|
160
|
+
StorefontTestingInstance();
|
|
161
|
+
|
|
162
|
+
const fetchedData = new DataInstance({
|
|
163
|
+
transaction: {
|
|
164
|
+
...expectedAmountAndCurrency,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
expect(fetchedData.amountAndCurrency).toEqual(
|
|
168
|
+
expect.objectContaining(expectedAmountAndCurrency),
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('should handle empty value', () => {
|
|
173
|
+
StorefontTestingInstance();
|
|
174
|
+
|
|
175
|
+
const fetchedData = new DataInstance();
|
|
176
|
+
expect(fetchedData.amountAndCurrency).toEqual(
|
|
177
|
+
expect.objectContaining({
|
|
178
|
+
amount: undefined,
|
|
179
|
+
currency: undefined,
|
|
180
|
+
}),
|
|
181
|
+
);
|
|
182
|
+
});
|
|
193
183
|
});
|
|
194
184
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
185
|
+
describe('isPayment', () => {
|
|
186
|
+
it('money is truthy', () => {
|
|
187
|
+
StorefontTestingInstance({
|
|
188
|
+
options: {
|
|
189
|
+
money: true,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
const fetchedData = new DataInstance();
|
|
193
|
+
expect(fetchedData.isPayment).toBeTruthy();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('invoice is truthy', () => {
|
|
197
|
+
StorefontTestingInstance();
|
|
198
|
+
const fetchedData = new DataInstance({
|
|
199
|
+
invoice: true,
|
|
200
|
+
});
|
|
201
|
+
expect(fetchedData.isPayment).toBeTruthy();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('transaction is truthy', () => {
|
|
205
|
+
StorefontTestingInstance();
|
|
206
|
+
const fetchedData = new DataInstance({
|
|
207
|
+
transaction: true,
|
|
208
|
+
});
|
|
209
|
+
expect(fetchedData.isPayment).toBeTruthy();
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('previewPurchase is falsy', () => {
|
|
213
|
+
StorefontTestingInstance();
|
|
214
|
+
const fetchedData = new DataInstance({
|
|
215
|
+
previewPurchase: true,
|
|
216
|
+
});
|
|
217
|
+
expect(fetchedData.isPayment).toBeFalsy();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('empty is falsy', () => {
|
|
221
|
+
StorefontTestingInstance();
|
|
222
|
+
const fetchedData = new DataInstance({});
|
|
223
|
+
expect(fetchedData.isPayment).toBeFalsy();
|
|
224
|
+
});
|
|
201
225
|
});
|
|
202
226
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
227
|
+
describe('isPurchase', () => {
|
|
228
|
+
it('previewPurchase is truthy', () => {
|
|
229
|
+
StorefontTestingInstance();
|
|
230
|
+
const fetchedData = new DataInstance({
|
|
231
|
+
previewPurchase: true,
|
|
232
|
+
});
|
|
233
|
+
expect(fetchedData.isPurchase).toBeTruthy();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('money is falsy', () => {
|
|
237
|
+
StorefontTestingInstance({
|
|
238
|
+
options: {
|
|
239
|
+
money: true,
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
const fetchedData = new DataInstance();
|
|
243
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('invoice is falsy', () => {
|
|
247
|
+
StorefontTestingInstance();
|
|
248
|
+
const fetchedData = new DataInstance({
|
|
249
|
+
invoice: true,
|
|
250
|
+
});
|
|
251
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('transaction is falsy', () => {
|
|
255
|
+
StorefontTestingInstance();
|
|
256
|
+
const fetchedData = new DataInstance({
|
|
257
|
+
transaction: true,
|
|
258
|
+
});
|
|
259
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('empty is falsy', () => {
|
|
263
|
+
StorefontTestingInstance();
|
|
264
|
+
const fetchedData = new DataInstance({});
|
|
265
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
266
|
+
});
|
|
209
267
|
});
|
|
210
268
|
|
|
211
|
-
it
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
269
|
+
it('Should get summaryItems', () => {
|
|
270
|
+
const expectedSummaryItems = {
|
|
271
|
+
discountsAmount: 1,
|
|
272
|
+
shippingAmount: 2,
|
|
273
|
+
subtotalAmount: 3,
|
|
274
|
+
taxAmount: 4,
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
let fetchedData = new DataInstance({
|
|
278
|
+
previewPurchase: {
|
|
279
|
+
...expectedSummaryItems,
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
expect(fetchedData.summaryItems).toEqual(
|
|
283
|
+
expect.objectContaining(expectedSummaryItems),
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
fetchedData = new DataInstance({
|
|
287
|
+
invoice: {
|
|
288
|
+
...expectedSummaryItems,
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
expect(fetchedData.summaryItems).toEqual(
|
|
292
|
+
expect.objectContaining(expectedSummaryItems),
|
|
293
|
+
);
|
|
217
294
|
});
|
|
218
295
|
|
|
219
|
-
it
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
296
|
+
it('Should get summaryLineItems', () => {
|
|
297
|
+
const expectedSummaryLineItems = [
|
|
298
|
+
{
|
|
299
|
+
line: 'item',
|
|
300
|
+
},
|
|
301
|
+
];
|
|
302
|
+
|
|
303
|
+
let fetchedData = new DataInstance({
|
|
304
|
+
previewPurchase: {
|
|
305
|
+
lineItems: expectedSummaryLineItems,
|
|
306
|
+
},
|
|
307
|
+
});
|
|
308
|
+
expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
|
|
309
|
+
|
|
310
|
+
fetchedData = new DataInstance({
|
|
311
|
+
invoice: {
|
|
312
|
+
items: expectedSummaryLineItems,
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
|
|
223
316
|
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
describe('isPurchase', () => {
|
|
227
|
-
it ('previewPurchase is truthy', () => {
|
|
228
|
-
StorefontTestingInstance();
|
|
229
|
-
const fetchedData = new DataInstance({
|
|
230
|
-
previewPurchase: true
|
|
231
|
-
});
|
|
232
|
-
expect(fetchedData.isPurchase).toBeTruthy();
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it ('money is falsy', () => {
|
|
236
|
-
StorefontTestingInstance({
|
|
237
|
-
options: {
|
|
238
|
-
money: true
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
const fetchedData = new DataInstance();
|
|
242
|
-
expect(fetchedData.isPurchase).toBeFalsy();
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it ('invoice is falsy', () => {
|
|
246
|
-
StorefontTestingInstance();
|
|
247
|
-
const fetchedData = new DataInstance({
|
|
248
|
-
invoice: true
|
|
249
|
-
});
|
|
250
|
-
expect(fetchedData.isPurchase).toBeFalsy();
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it ('transaction is falsy', () => {
|
|
254
|
-
StorefontTestingInstance();
|
|
255
|
-
const fetchedData = new DataInstance({
|
|
256
|
-
transaction: true
|
|
257
|
-
});
|
|
258
|
-
expect(fetchedData.isPurchase).toBeFalsy();
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it ('empty is falsy', () => {
|
|
262
|
-
StorefontTestingInstance();
|
|
263
|
-
const fetchedData = new DataInstance({});
|
|
264
|
-
expect(fetchedData.isPurchase).toBeFalsy();
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it ('Should get summaryItems', () => {
|
|
269
|
-
const expectedSummaryItems = {
|
|
270
|
-
discountsAmount: 1,
|
|
271
|
-
shippingAmount: 2,
|
|
272
|
-
subtotalAmount: 3,
|
|
273
|
-
taxAmount: 4
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
let fetchedData = new DataInstance({
|
|
277
|
-
previewPurchase: {
|
|
278
|
-
...expectedSummaryItems
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
expect(fetchedData.summaryItems).toEqual(
|
|
282
|
-
expect.objectContaining(expectedSummaryItems)
|
|
283
|
-
);
|
|
284
|
-
|
|
285
|
-
fetchedData = new DataInstance({
|
|
286
|
-
invoice: {
|
|
287
|
-
...expectedSummaryItems
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
expect(fetchedData.summaryItems).toEqual(
|
|
291
|
-
expect.objectContaining(expectedSummaryItems)
|
|
292
|
-
);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
it ('Should get summaryLineItems', () => {
|
|
296
|
-
const expectedSummaryLineItems = [{
|
|
297
|
-
line: 'item'
|
|
298
|
-
}];
|
|
299
|
-
|
|
300
|
-
let fetchedData = new DataInstance({
|
|
301
|
-
previewPurchase: {
|
|
302
|
-
lineItems: expectedSummaryLineItems
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
|
|
306
|
-
|
|
307
|
-
fetchedData = new DataInstance({
|
|
308
|
-
invoice: {
|
|
309
|
-
items: expectedSummaryLineItems
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
|
|
313
|
-
});
|
|
314
317
|
});
|
|
315
|
-
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const collectedProperties = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
// Google UTM fields
|
|
3
|
+
'utm_source',
|
|
4
|
+
'utm_medium',
|
|
5
|
+
'utm_campaign',
|
|
6
|
+
'utm_term',
|
|
7
|
+
'utm_content',
|
|
8
|
+
// FramePay specific fields
|
|
9
|
+
'affiliate',
|
|
10
|
+
'subAffiliate',
|
|
11
|
+
'clickId',
|
|
12
|
+
'salesAgent',
|
|
13
13
|
];
|
|
14
14
|
const prefix = /utm_/g;
|
|
15
15
|
|
|
@@ -20,27 +20,27 @@ const prefix = /utm_/g;
|
|
|
20
20
|
* @returns {Object} The lead source data object
|
|
21
21
|
*/
|
|
22
22
|
export const getLeadSourceData = () => {
|
|
23
|
-
|
|
23
|
+
const { href, origin, pathname, search } = window.location;
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
const leadSource = {
|
|
26
|
+
// Large query parameters including JWTs will cause issues, so make sure we dont
|
|
27
|
+
// use anything longer than 255 characters.
|
|
28
|
+
path: href.length <= 255 ? href : `${origin}${pathname}`,
|
|
29
|
+
};
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
const query = search.replace('?', '');
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
// Process query parameters and add them to the leadSource object
|
|
34
|
+
return query
|
|
35
|
+
.split('&')
|
|
36
|
+
.map((field) => field.split('='))
|
|
37
|
+
.filter((field) => {
|
|
38
|
+
const [name] = field;
|
|
39
|
+
return collectedProperties.indexOf(name) > -1;
|
|
40
|
+
})
|
|
41
|
+
.reduce((data, field) => {
|
|
42
|
+
const [name, value = null] = field;
|
|
43
|
+
data[name.replace(prefix, '')] = value;
|
|
44
|
+
return data;
|
|
45
|
+
}, leadSource);
|
|
46
46
|
};
|