@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.
- package/.babelrc +24 -26
- package/CHANGELOG.md +14 -0
- package/dist/index.js +8 -8
- package/dist/index.min.js +8 -8
- package/package.json +14 -3
- 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 +419 -411
- 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 +323 -287
- 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 +151 -146
- package/src/functions/purchase.spec.js +59 -56
- package/src/functions/setup.js +53 -53
- 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
|
@@ -13,125 +13,129 @@ import { sleep } from '@/utils';
|
|
|
13
13
|
import setupFramepay from '@/functions/mount/setup-framepay';
|
|
14
14
|
|
|
15
15
|
export const setupFramepayMock = async () => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
16
|
+
/*
|
|
17
|
+
* onload() is never called in JSDOM context but we want to test the rest of the setupFramepay code,
|
|
18
|
+
* so we run it asynchonously and wait for 10 ms
|
|
19
|
+
*/
|
|
20
|
+
setupFramepay();
|
|
21
|
+
await sleep(10);
|
|
22
|
+
};
|
|
23
23
|
|
|
24
24
|
export async function RenderMockRebillyInstruments(options = {}) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
when(get(`${storefrontURL}/invoices/*`)).thenReturn(
|
|
47
|
-
(() => ok(testInvoice))()
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
when(post(`${storefrontURL}/ready-to-pay`)).thenReturn(
|
|
51
|
-
(() => ok([
|
|
52
|
-
{
|
|
53
|
-
method: 'payment-card',
|
|
54
|
-
feature: {
|
|
55
|
-
name: 'Google Pay',
|
|
56
|
-
merchantName: 'google-pay-merchant-name',
|
|
57
|
-
merchantOrigin: 'google-pay-merchant-origin'
|
|
58
|
-
},
|
|
59
|
-
brands: ['Visa', 'MasterCard', 'American Express', 'Discover'],
|
|
60
|
-
filters: []
|
|
61
|
-
}
|
|
62
|
-
]))()
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
when(post(`${storefrontURL}/preview-purchase`)).thenReturn(
|
|
66
|
-
(() => ok(testSummary))()
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
when(get(`${storefrontURL}/plans`)).thenReturn(
|
|
70
|
-
(() => ok([testPlan]))()
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
when(get(`${storefrontURL}/products`)).thenReturn(
|
|
74
|
-
(() => ok([testProduct]))()
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
const defaultOptions = {
|
|
78
|
-
form: '.form-selector',
|
|
79
|
-
summary: '.summary-selector',
|
|
80
|
-
locale: 'auto',
|
|
81
|
-
apiMode: 'sandbox',
|
|
82
|
-
_dev: {
|
|
83
|
-
paymentMethodsUrl: 'https://forms.test.rebilly.dev',
|
|
84
|
-
framePayStyleLink: 'https://dev.framepay.rebilly.com/rebilly.css'
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const hasPurchaseData = [
|
|
89
|
-
'items',
|
|
90
|
-
'invoiceId',
|
|
91
|
-
'transactionId',
|
|
92
|
-
'money',
|
|
93
|
-
'jwt'
|
|
94
|
-
].some(key => Object.keys(options).includes(key))
|
|
95
|
-
if(!hasPurchaseData) {
|
|
96
|
-
defaultOptions.items = [
|
|
97
|
-
{
|
|
98
|
-
planId: 'test-plan-id-1',
|
|
99
|
-
quantity: 1
|
|
100
|
-
}
|
|
101
|
-
];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if ((options.invoiceId || options.transactionid) && !options.jwt) {
|
|
105
|
-
defaultOptions.jwt = 'test-jwt';
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const mergedOptions = merge({...defaultOptions}, options);
|
|
109
|
-
|
|
110
|
-
const framepayMock = createFramepayMock();
|
|
111
|
-
global.Rebilly = framepayMock;
|
|
112
|
-
|
|
113
|
-
const form = document.createElement('div');
|
|
114
|
-
form.classList.add(`${mergedOptions.form.replace('.', '')}`);
|
|
115
|
-
document.body.appendChild(form);
|
|
116
|
-
|
|
117
|
-
const summary = document.createElement('div');
|
|
118
|
-
summary.classList.add(`${mergedOptions.summary.replace('.', '')}`);
|
|
119
|
-
document.body.appendChild(summary);
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
await RebillyInstruments.mount({
|
|
123
|
-
setupFramepay: setupFramepayMock,
|
|
124
|
-
...mergedOptions,
|
|
25
|
+
const testInvoice = new InvoiceModel({
|
|
26
|
+
id: 'test-invoice-id',
|
|
27
|
+
});
|
|
28
|
+
const testPlan = new PlanModel({ name: 'Test Plan', id: 'test-plan-id-1' });
|
|
29
|
+
const testProduct = new ProductModel({
|
|
30
|
+
description: 'My Awesome Product',
|
|
31
|
+
id: 'test-product-1',
|
|
32
|
+
name: 'My Product',
|
|
33
|
+
});
|
|
34
|
+
const testSummary = new SummaryModel({
|
|
35
|
+
currency: 'USD',
|
|
36
|
+
lineItems: [
|
|
37
|
+
{
|
|
38
|
+
description: 'test-plan-id-1',
|
|
39
|
+
planId: 'test-plan-id-1',
|
|
40
|
+
productId: 'test-product-1',
|
|
41
|
+
quantity: 1,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
125
44
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
45
|
+
|
|
46
|
+
when(get(`${storefrontURL}/invoices/*`)).thenReturn(
|
|
47
|
+
(() => ok(testInvoice))(),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
when(post(`${storefrontURL}/ready-to-pay`)).thenReturn(
|
|
51
|
+
(() =>
|
|
52
|
+
ok([
|
|
53
|
+
{
|
|
54
|
+
method: 'payment-card',
|
|
55
|
+
feature: {
|
|
56
|
+
name: 'Google Pay',
|
|
57
|
+
merchantName: 'google-pay-merchant-name',
|
|
58
|
+
merchantOrigin: 'google-pay-merchant-origin',
|
|
59
|
+
},
|
|
60
|
+
brands: [
|
|
61
|
+
'Visa',
|
|
62
|
+
'MasterCard',
|
|
63
|
+
'American Express',
|
|
64
|
+
'Discover',
|
|
65
|
+
],
|
|
66
|
+
filters: [],
|
|
67
|
+
},
|
|
68
|
+
]))(),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
when(post(`${storefrontURL}/preview-purchase`)).thenReturn(
|
|
72
|
+
(() => ok(testSummary))(),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
when(get(`${storefrontURL}/plans`)).thenReturn((() => ok([testPlan]))());
|
|
76
|
+
|
|
77
|
+
when(get(`${storefrontURL}/products`)).thenReturn(
|
|
78
|
+
(() => ok([testProduct]))(),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const defaultOptions = {
|
|
82
|
+
form: '.form-selector',
|
|
83
|
+
summary: '.summary-selector',
|
|
84
|
+
locale: 'auto',
|
|
85
|
+
apiMode: 'sandbox',
|
|
86
|
+
_dev: {
|
|
87
|
+
paymentMethodsUrl: 'https://forms.test.rebilly.dev',
|
|
88
|
+
framePayStyleLink: 'https://dev.framepay.rebilly.com/rebilly.css',
|
|
89
|
+
},
|
|
131
90
|
};
|
|
132
|
-
} catch(e) {
|
|
133
|
-
console.log(e);
|
|
134
|
-
}
|
|
135
91
|
|
|
136
|
-
|
|
137
|
-
|
|
92
|
+
const hasPurchaseData = [
|
|
93
|
+
'items',
|
|
94
|
+
'invoiceId',
|
|
95
|
+
'transactionId',
|
|
96
|
+
'money',
|
|
97
|
+
'jwt',
|
|
98
|
+
].some((key) => Object.keys(options).includes(key));
|
|
99
|
+
if (!hasPurchaseData) {
|
|
100
|
+
defaultOptions.items = [
|
|
101
|
+
{
|
|
102
|
+
planId: 'test-plan-id-1',
|
|
103
|
+
quantity: 1,
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if ((options.invoiceId || options.transactionid) && !options.jwt) {
|
|
109
|
+
defaultOptions.jwt = 'test-jwt';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const mergedOptions = merge({ ...defaultOptions }, options);
|
|
113
|
+
|
|
114
|
+
const framepayMock = createFramepayMock();
|
|
115
|
+
global.Rebilly = framepayMock;
|
|
116
|
+
|
|
117
|
+
const form = document.createElement('div');
|
|
118
|
+
form.classList.add(`${mergedOptions.form.replace('.', '')}`);
|
|
119
|
+
document.body.appendChild(form);
|
|
120
|
+
|
|
121
|
+
const summary = document.createElement('div');
|
|
122
|
+
summary.classList.add(`${mergedOptions.summary.replace('.', '')}`);
|
|
123
|
+
document.body.appendChild(summary);
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
await RebillyInstruments.mount({
|
|
127
|
+
setupFramepay: setupFramepayMock,
|
|
128
|
+
...mergedOptions,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
RebillyInstruments.mock = {
|
|
132
|
+
data: (data) => {
|
|
133
|
+
RebillyInstruments.state.data = new DataInstance(data);
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
} catch (e) {
|
|
137
|
+
console.log(e);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return RebillyInstruments;
|
|
141
|
+
}
|
|
@@ -1,55 +1,62 @@
|
|
|
1
|
-
import {ok, get, post} from 'msw-when-then';
|
|
1
|
+
import { ok, get, post } from 'msw-when-then';
|
|
2
2
|
|
|
3
3
|
export const storefrontURL = '*/storefront';
|
|
4
4
|
|
|
5
5
|
export const initStoreFrontApiMocks = (when) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
const mocks = [
|
|
7
|
+
/* GET */
|
|
8
|
+
{
|
|
9
|
+
url: '*/account',
|
|
10
|
+
method: get,
|
|
11
|
+
response: () => ok({}),
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
url: '*/plans',
|
|
15
|
+
method: get,
|
|
16
|
+
response: () => ok([]),
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
url: '*/payment-instruments',
|
|
20
|
+
method: get,
|
|
21
|
+
response: () => ok([]),
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
url: '*/transactions/test-transaction-id',
|
|
25
|
+
method: get,
|
|
26
|
+
response: () => ok({}),
|
|
27
|
+
},
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
29
|
+
/* POST */
|
|
30
|
+
{
|
|
31
|
+
url: '*/ready-to-pay',
|
|
32
|
+
method: post,
|
|
33
|
+
response: () =>
|
|
34
|
+
ok([
|
|
35
|
+
{
|
|
36
|
+
filters: [],
|
|
37
|
+
method: 'method',
|
|
38
|
+
},
|
|
39
|
+
]),
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
url: '*/preview-purchase',
|
|
43
|
+
method: post,
|
|
44
|
+
response: () => ok({}),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
url: '*/payment-instruments',
|
|
48
|
+
method: post,
|
|
49
|
+
response: () => ok([]),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
url: '*/payment-instruments/*/setup',
|
|
53
|
+
method: post,
|
|
54
|
+
response: () => ok([]),
|
|
55
|
+
},
|
|
56
|
+
];
|
|
50
57
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
mocks.forEach((api) => {
|
|
59
|
+
const http = api.method(`${storefrontURL}${api.url}`);
|
|
60
|
+
when(http).thenReturn(api.response());
|
|
61
|
+
});
|
|
55
62
|
};
|
|
@@ -3,22 +3,18 @@ import { DataInstance } from '@/functions/mount/fetch-data';
|
|
|
3
3
|
import state from '@/state';
|
|
4
4
|
|
|
5
5
|
export function MockStorefront(config = {}) {
|
|
6
|
-
|
|
6
|
+
return Storefront(config);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export function StorefontTestingInstance({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} = {}) {
|
|
13
|
-
|
|
14
|
-
state.storefront = null;
|
|
15
|
-
state.storefront = MockStorefront();
|
|
9
|
+
export function StorefontTestingInstance({ options = {}, data = {} } = {}) {
|
|
10
|
+
state.storefront = null;
|
|
11
|
+
state.storefront = MockStorefront();
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
state.options = null;
|
|
14
|
+
state.options = options;
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
state.data = null;
|
|
17
|
+
state.data = new DataInstance(data);
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
}
|
|
19
|
+
return state;
|
|
20
|
+
}
|
package/tests/msw/server.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {setupServer} from 'msw/node';
|
|
2
|
-
import {rest} from 'msw';
|
|
3
|
-
import {whenThen} from 'msw-when-then';
|
|
4
|
-
import {initStoreFrontApiMocks} from '../mocks/storefront-api-mock';
|
|
5
|
-
import {initRebillyApiMocks} from '../mocks/rebilly-api-mock';
|
|
1
|
+
import { setupServer } from 'msw/node';
|
|
2
|
+
import { rest } from 'msw';
|
|
3
|
+
import { whenThen } from 'msw-when-then';
|
|
4
|
+
import { initStoreFrontApiMocks } from '../mocks/storefront-api-mock';
|
|
5
|
+
import { initRebillyApiMocks } from '../mocks/rebilly-api-mock';
|
|
6
6
|
|
|
7
7
|
export const server = setupServer();
|
|
8
8
|
|
|
9
|
-
export const {when} = whenThen(server, rest);
|
|
9
|
+
export const { when } = whenThen(server, rest);
|
|
10
10
|
|
|
11
11
|
export const initGlobalHandlers = () => {
|
|
12
12
|
initStoreFrontApiMocks(when);
|
package/tests/setup-test.js
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
import { initGlobalHandlers, server } from './msw/server';
|
|
2
2
|
import state from '../src/state';
|
|
3
|
-
import 'vitest-canvas-mock'
|
|
3
|
+
import 'vitest-canvas-mock';
|
|
4
4
|
|
|
5
|
-
vi.mock(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
5
|
+
vi.mock('@rebilly/risk-data-collector', async () => {
|
|
6
|
+
const actual = await vi.importActual('@rebilly/risk-data-collector');
|
|
7
|
+
return {
|
|
8
|
+
default: {
|
|
9
|
+
collectData: vi.fn().mockReturnValue({ riskMetadata: {} }),
|
|
10
|
+
},
|
|
11
|
+
...actual,
|
|
12
|
+
};
|
|
14
13
|
});
|
|
15
14
|
|
|
16
|
-
|
|
17
15
|
beforeAll(() => {
|
|
18
|
-
|
|
16
|
+
server.listen();
|
|
19
17
|
});
|
|
20
18
|
|
|
21
19
|
beforeEach(() => {
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
initGlobalHandlers();
|
|
21
|
+
state.reset();
|
|
24
22
|
});
|
|
25
23
|
|
|
26
24
|
afterEach(() => {
|
|
27
|
-
|
|
25
|
+
server.resetHandlers();
|
|
28
26
|
});
|
|
29
27
|
|
|
30
28
|
afterAll(() => {
|
|
31
|
-
|
|
29
|
+
server.close();
|
|
32
30
|
});
|
package/vitest.config.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config'
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
|
|
4
4
|
export default defineConfig({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
test: {
|
|
6
|
+
environment: 'jsdom',
|
|
7
|
+
globals: true,
|
|
8
|
+
watch: true,
|
|
9
|
+
setupFiles: 'tests/setup-test.js',
|
|
10
|
+
deps: {
|
|
11
|
+
inline: ['vitest-canvas-mock'],
|
|
12
|
+
},
|
|
13
|
+
alias: {
|
|
14
|
+
'@': path.resolve(__dirname, 'src'),
|
|
15
|
+
tests: path.resolve(__dirname, 'tests'),
|
|
16
|
+
},
|
|
12
17
|
},
|
|
13
|
-
|
|
14
|
-
'@': path.resolve(__dirname, 'src'),
|
|
15
|
-
'tests': path.resolve(__dirname, 'tests'),
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
})
|
|
18
|
+
});
|
package/.eslintrc.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
root: true,
|
|
3
|
-
env: {
|
|
4
|
-
browser: true,
|
|
5
|
-
es6: true,
|
|
6
|
-
},
|
|
7
|
-
globals: {
|
|
8
|
-
Rebilly: "readonly",
|
|
9
|
-
},
|
|
10
|
-
rules: {
|
|
11
|
-
'class-methods-use-this': 'off',
|
|
12
|
-
'import/no-extraneous-dependencies': 'off',
|
|
13
|
-
'import/prefer-default-export': 'off',
|
|
14
|
-
'import/extensions': [
|
|
15
|
-
2,
|
|
16
|
-
{
|
|
17
|
-
mjs: 'always',
|
|
18
|
-
json: 'always',
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
'max-classes-per-file': 'off',
|
|
22
|
-
'max-len': ['error', {code: 120, ignoreStrings: true, ignoreTemplateLiterals: true, ignoreUrls: true}],
|
|
23
|
-
'no-useless-catch': 'off',
|
|
24
|
-
'no-underscore-dangle': 'off',
|
|
25
|
-
'no-console': 'off',
|
|
26
|
-
'no-param-reassign': 0,
|
|
27
|
-
quotes: ["error", "single"],
|
|
28
|
-
},
|
|
29
|
-
parser: 'babel-eslint',
|
|
30
|
-
extends: [
|
|
31
|
-
'airbnb-base',
|
|
32
|
-
'prettier',
|
|
33
|
-
],
|
|
34
|
-
};
|