@rebilly/instruments 4.5.0 → 4.7.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.
Files changed (134) hide show
  1. package/.babelrc +24 -26
  2. package/CHANGELOG.md +14 -0
  3. package/dist/index.js +8 -8
  4. package/dist/index.min.js +8 -8
  5. package/package.json +14 -3
  6. package/project.json +9 -0
  7. package/rollup.config.mjs +21 -26
  8. package/src/data/options-schema/index.js +94 -78
  9. package/src/data/options-schema/schemas/options-schema.js +419 -411
  10. package/src/events/base-event.js +34 -34
  11. package/src/events/events.spec.js +6 -6
  12. package/src/events/index.js +5 -5
  13. package/src/functions/destroy.js +19 -19
  14. package/src/functions/destroy.spec.js +41 -41
  15. package/src/functions/mount/fetch-data.js +200 -193
  16. package/src/functions/mount/fetch-data.spec.js +287 -285
  17. package/src/functions/mount/get-lead-source-data.js +31 -31
  18. package/src/functions/mount/get-lead-source-data.spec.js +19 -19
  19. package/src/functions/mount/index.js +73 -65
  20. package/src/functions/mount/mount.spec.js +77 -66
  21. package/src/functions/mount/setup-element.js +23 -23
  22. package/src/functions/mount/setup-framepay-theme.js +86 -68
  23. package/src/functions/mount/setup-framepay.js +9 -5
  24. package/src/functions/mount/setup-i18n.js +15 -15
  25. package/src/functions/mount/setup-options.js +74 -74
  26. package/src/functions/mount/setup-options.spec.js +323 -287
  27. package/src/functions/mount/setup-storefront.js +15 -20
  28. package/src/functions/mount/setup-styles-vars.js +19 -22
  29. package/src/functions/mount/setup-user-flow.js +51 -47
  30. package/src/functions/on.js +5 -5
  31. package/src/functions/on.spec.js +60 -51
  32. package/src/functions/purchase.js +151 -146
  33. package/src/functions/purchase.spec.js +59 -56
  34. package/src/functions/setup.js +53 -53
  35. package/src/functions/setup.spec.js +88 -75
  36. package/src/functions/show.js +13 -14
  37. package/src/functions/show.spec.js +53 -53
  38. package/src/functions/update.js +30 -28
  39. package/src/functions/update.spec.js +94 -93
  40. package/src/i18n/en.json +32 -32
  41. package/src/i18n/es.json +29 -29
  42. package/src/i18n/i18n.spec.js +18 -18
  43. package/src/i18n/index.js +48 -48
  44. package/src/instance.js +36 -36
  45. package/src/instance.spec.js +29 -27
  46. package/src/loader/index.js +95 -70
  47. package/src/loader/loader.spec.js +63 -63
  48. package/src/state/iframes.js +21 -21
  49. package/src/state/index.js +56 -54
  50. package/src/storefront/account-and-website.js +10 -8
  51. package/src/storefront/account-and-website.spec.js +55 -55
  52. package/src/storefront/deposit-requests.js +6 -6
  53. package/src/storefront/fetch-plans-from-addons-bumpOffer.js +21 -19
  54. package/src/storefront/fetch-products-from-plans.js +52 -51
  55. package/src/storefront/fetch-products-from-plans.spec.js +90 -87
  56. package/src/storefront/index.js +56 -49
  57. package/src/storefront/invoices.js +15 -15
  58. package/src/storefront/invoices.spec.js +69 -65
  59. package/src/storefront/models/account-model.js +29 -32
  60. package/src/storefront/models/base-model.js +6 -9
  61. package/src/storefront/models/deposit-request-model.js +22 -13
  62. package/src/storefront/models/invoice-model.js +16 -16
  63. package/src/storefront/models/payment-metadata.js +4 -4
  64. package/src/storefront/models/plan-model.js +73 -64
  65. package/src/storefront/models/ready-to-pay-model.js +59 -59
  66. package/src/storefront/models/summary-model.js +43 -46
  67. package/src/storefront/models/transaction-model.js +11 -14
  68. package/src/storefront/payment-instruments.js +38 -35
  69. package/src/storefront/payment-instruments.spec.js +81 -62
  70. package/src/storefront/purchase.js +50 -44
  71. package/src/storefront/purchase.spec.js +40 -40
  72. package/src/storefront/ready-to-pay.js +75 -77
  73. package/src/storefront/ready-to-pay.spec.js +59 -54
  74. package/src/storefront/storefront.spec.js +9 -9
  75. package/src/storefront/summary.js +93 -67
  76. package/src/storefront/summary.spec.js +108 -106
  77. package/src/storefront/transactions.js +6 -6
  78. package/src/style/base/default-theme.js +928 -923
  79. package/src/style/base/theme.js +21 -21
  80. package/src/style/base/theme.spec.js +13 -13
  81. package/src/style/index.js +3 -3
  82. package/src/style/utils/border.js +40 -27
  83. package/src/style/utils/color-values.js +18 -18
  84. package/src/style/utils/minifyCss.js +6 -6
  85. package/src/utils/add-dom-element.js +14 -14
  86. package/src/utils/format-currency.js +6 -5
  87. package/src/utils/has-valid-css-selector.js +2 -2
  88. package/src/utils/index.js +6 -6
  89. package/src/utils/is-dom-element.js +1 -1
  90. package/src/utils/process-property-as-dom-element.js +22 -22
  91. package/src/utils/quantity.js +26 -28
  92. package/src/utils/sleep.js +3 -1
  93. package/src/views/amount-selector.js +37 -36
  94. package/src/views/common/iframe/base-iframe.js +53 -52
  95. package/src/views/common/iframe/events/change-iframe-src-handler.js +5 -5
  96. package/src/views/common/iframe/events/dispatch-event-handler.js +4 -4
  97. package/src/views/common/iframe/events/resize-component-handler.js +8 -8
  98. package/src/views/common/iframe/events/show-error-handler.js +2 -2
  99. package/src/views/common/iframe/events/stop-loader-handler.js +8 -8
  100. package/src/views/common/iframe/events/update-addons-handler.js +20 -13
  101. package/src/views/common/iframe/events/update-coupons-handler.js +9 -9
  102. package/src/views/common/iframe/events/update-items-handler.js +26 -22
  103. package/src/views/common/iframe/modal-iframe.js +67 -56
  104. package/src/views/common/iframe/view-iframe.js +11 -11
  105. package/src/views/common/render-utilities.js +2 -2
  106. package/src/views/confirmation.js +33 -30
  107. package/src/views/errors.js +89 -79
  108. package/src/views/form.js +41 -37
  109. package/src/views/method-selector/express-methods.js +46 -46
  110. package/src/views/method-selector/generate-digital-wallet.js +46 -45
  111. package/src/views/method-selector/generate-digital-wallet.spec.js +104 -102
  112. package/src/views/method-selector/generate-framepay-config.js +53 -51
  113. package/src/views/method-selector/generate-framepay-config.spec.js +197 -173
  114. package/src/views/method-selector/get-method-data.js +5 -6
  115. package/src/views/method-selector/get-payment-methods.js +18 -16
  116. package/src/views/method-selector/get-payment-methods.spec.js +29 -27
  117. package/src/views/method-selector/index.js +154 -139
  118. package/src/views/method-selector/method-selector.spec.js +13 -13
  119. package/src/views/method-selector/mount-bump-offer.js +65 -49
  120. package/src/views/method-selector/mount-express-methods.js +89 -85
  121. package/src/views/modal.js +74 -67
  122. package/src/views/result.js +14 -14
  123. package/src/views/summary.js +25 -26
  124. package/tests/async-utilities.js +13 -13
  125. package/tests/mocks/framepay-mock.js +9 -8
  126. package/tests/mocks/rebilly-api-mock.js +5 -3
  127. package/tests/mocks/rebilly-instruments-mock.js +121 -117
  128. package/tests/mocks/storefront-api-mock.js +55 -48
  129. package/tests/mocks/storefront-mock.js +10 -14
  130. package/tests/msw/server.js +6 -6
  131. package/tests/setup-test.js +14 -16
  132. package/vitest.config.js +14 -14
  133. package/.eslintrc.js +0 -34
  134. 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
- 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
- }
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
- 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
- );
27
- });
28
-
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
- },
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
- 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
- );
52
- });
53
-
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
- }
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
- fetchData({
66
- fetchInvoiceAndProducts: mockFetchInvoiceAndProducts
67
- });
68
-
69
- expect(mockFetchInvoiceAndProducts).toBeCalledTimes(0);
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
- await fetchData({
82
- fetchAccountAndWebsite: mockFetchAccountAndWebsite,
80
+ await fetchData({
81
+ fetchAccountAndWebsite: mockFetchAccountAndWebsite,
82
+ });
83
+
84
+ expect(mockFetchAccountAndWebsite).toBeCalledTimes(1);
83
85
  });
84
86
 
85
- expect(mockFetchAccountAndWebsite).toBeCalledTimes(1);
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
- it ('Should not fetch account when there JWT is not supplied', async () => {
89
- const mockFetchAccountAndWebsite = vi.fn();
90
- StorefontTestingInstance({
91
- options: {}
92
- });
93
+ await fetchData({
94
+ fetchAccountAndWebsite: mockFetchAccountAndWebsite,
95
+ });
93
96
 
94
- await fetchData({
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
- describe('Determining amountAndCurrency', () => {
104
- it ('should use money option', () => {
105
- const expectedAmountAndCurrency = {
106
- amount: 10,
107
- currency: 'USD'
108
- }
109
- StorefontTestingInstance({
110
- options: {
111
- money: expectedAmountAndCurrency
112
- }
113
- });
114
- const fetchedData = new DataInstance();
115
-
116
- expect(fetchedData.amountAndCurrency).toEqual(expectedAmountAndCurrency);
117
- });
118
-
119
- it ('should use preview Purchase', () => {
120
- const expectedAmountAndCurrency = {
121
- amount: 10,
122
- currency: 'USD'
123
- }
124
- StorefontTestingInstance();
125
-
126
- const fetchedData = new DataInstance({
127
- previewPurchase: {
128
- total: expectedAmountAndCurrency.amount,
129
- currency: expectedAmountAndCurrency.currency
130
- }
131
- });
132
- expect(fetchedData.amountAndCurrency).toEqual(
133
- expect.objectContaining(expectedAmountAndCurrency)
134
- );
135
- });
136
-
137
- it ('should use invoice', () => {
138
- const expectedAmountAndCurrency = {
139
- amount: 10,
140
- currency: 'USD'
141
- }
142
- StorefontTestingInstance();
143
-
144
- const fetchedData = new DataInstance({
145
- invoice: {
146
- ...expectedAmountAndCurrency
147
- }
148
- });
149
- expect(fetchedData.amountAndCurrency).toEqual(
150
- expect.objectContaining(expectedAmountAndCurrency)
151
- );
152
- });
153
-
154
- it ('should use transaction', () => {
155
- const expectedAmountAndCurrency = {
156
- amount: 10,
157
- currency: 'USD'
158
- }
159
- StorefontTestingInstance();
160
-
161
- const fetchedData = new DataInstance({
162
- transaction: {
163
- ...expectedAmountAndCurrency
164
- }
165
- });
166
- expect(fetchedData.amountAndCurrency).toEqual(
167
- expect.objectContaining(expectedAmountAndCurrency)
168
- );
169
- });
170
-
171
- it ('should handle empty value', () => {
172
- StorefontTestingInstance();
173
-
174
- const fetchedData = new DataInstance();
175
- expect(fetchedData.amountAndCurrency).toEqual(
176
- expect.objectContaining({
177
- amount: undefined,
178
- currency: undefined
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
- it ('invoice is truthy', () => {
196
- StorefontTestingInstance();
197
- const fetchedData = new DataInstance({
198
- invoice: true
199
- });
200
- expect(fetchedData.isPayment).toBeTruthy();
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
- it ('transaction is truthy', () => {
204
- StorefontTestingInstance();
205
- const fetchedData = new DataInstance({
206
- transaction: true
207
- });
208
- expect(fetchedData.isPayment).toBeTruthy();
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 ('previewPurchase is falsy', () => {
212
- StorefontTestingInstance();
213
- const fetchedData = new DataInstance({
214
- previewPurchase: true
215
- });
216
- expect(fetchedData.isPayment).toBeFalsy();
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 ('empty is falsy', () => {
220
- StorefontTestingInstance();
221
- const fetchedData = new DataInstance({});
222
- expect(fetchedData.isPayment).toBeFalsy();
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
- // 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'
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
- const { href, origin, pathname, search } = window.location;
23
+ const { href, origin, pathname, search } = window.location;
24
24
 
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
- };
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
- const query = search.replace('?', '');
31
+ const query = search.replace('?', '');
32
32
 
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);
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
  };