@rebilly/instruments 1.0.2-beta.8 → 2.1.1-beta.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 +13 -4
- package/.eslintrc.js +3 -0
- package/.prettierrc.js +11 -0
- package/README.md +15 -314
- package/dist/events/base-event.js +6 -9
- package/dist/events/events.spec.js +4 -4
- package/dist/events/index.js +2 -1
- package/dist/functions/destroy.js +12 -14
- package/dist/functions/destroy.spec.js +3 -3
- package/dist/functions/mount/fetch-data.js +183 -0
- package/dist/functions/mount/fetch-data.spec.js +189 -0
- package/dist/functions/mount/index.js +158 -251
- package/dist/functions/mount/mount.spec.js +24 -121
- package/dist/functions/mount/setup-element.js +40 -0
- package/dist/functions/mount/setup-framepay.js +46 -0
- package/dist/functions/mount/setup-i18n.js +33 -0
- package/dist/functions/mount/setup-options.js +96 -0
- package/dist/functions/mount/setup-options.spec.js +66 -0
- package/dist/functions/mount/setup-storefront.js +34 -0
- package/dist/functions/mount/setup-styles.js +43 -0
- package/dist/functions/on.js +13 -4
- package/dist/functions/on.spec.js +19 -5
- package/dist/functions/purchase.js +139 -22
- package/dist/functions/purchase.spec.js +23 -19
- package/dist/functions/setup.js +85 -0
- package/dist/functions/setup.spec.js +87 -0
- package/dist/functions/show.js +31 -14
- package/dist/functions/show.spec.js +47 -18
- package/dist/functions/update.js +53 -27
- package/dist/functions/update.spec.js +40 -21
- package/dist/i18n/en.json +4 -1
- package/dist/i18n/es.json +4 -1
- package/dist/index.js +67 -56
- package/dist/index.spec.js +7 -27
- package/dist/loader/index.js +4 -3
- package/dist/storefront/index.js +33 -0
- package/dist/storefront/invoices.js +27 -0
- package/dist/storefront/models/base-model.js +18 -0
- package/dist/storefront/models/invoice-model.js +14 -0
- package/dist/storefront/models/plan-model.js +4 -35
- package/dist/storefront/models/product-model.js +4 -23
- package/dist/storefront/models/summary-model.js +12 -25
- package/dist/storefront/models/transaction-model.js +31 -0
- package/dist/storefront/payment-instruments.js +47 -0
- package/dist/storefront/payment-instruments.spec.js +55 -0
- package/dist/storefront/plans.js +15 -24
- package/dist/storefront/plans.spec.js +17 -44
- package/dist/storefront/products.js +16 -20
- package/dist/storefront/products.spec.js +25 -49
- package/dist/storefront/purchase.js +28 -16
- package/dist/storefront/purchase.spec.js +4 -22
- package/dist/storefront/ready-to-pay.js +26 -22
- package/dist/storefront/ready-to-pay.spec.js +25 -54
- package/dist/storefront/storefront.spec.js +1 -1
- package/dist/storefront/summary.js +27 -24
- package/dist/storefront/summary.spec.js +44 -86
- package/dist/storefront/transactions.js +27 -0
- package/dist/style/base/theme.js +3 -3
- package/dist/style/components/methods.js +43 -42
- package/dist/style/utils/color-values.js +1 -3
- package/dist/style/views/confirmation.js +0 -4
- package/dist/style/views/method-selector.js +1 -1
- package/dist/style/views/modal.js +3 -1
- package/dist/style/views/summary.js +5 -1
- package/dist/utils/format-currency.js +4 -2
- package/dist/utils/has-valid-css-selector.js +1 -1
- package/dist/utils/process-property-as-dom-element.js +0 -2
- package/dist/views/__snapshots__/summary.spec.js.snap +103 -113
- package/dist/views/common/iframe/base-iframe.js +10 -2
- package/dist/views/common/iframe/modal-iframe.js +44 -3
- package/dist/views/confirmation.js +44 -20
- package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
- package/dist/views/method-selector/express-methods/google-pay.js +31 -0
- package/dist/views/method-selector/express-methods/paypal.js +19 -0
- package/dist/views/method-selector/generate-digital-wallet.js +68 -0
- package/dist/views/method-selector/generate-digital-wallet.spec.js +135 -0
- package/dist/views/method-selector/get-payment-methods.js +28 -8
- package/dist/views/method-selector/get-payment-methods.spec.js +25 -26
- package/dist/views/method-selector/index.js +55 -86
- package/dist/views/method-selector/method-selector.spec.js +80 -69
- package/dist/views/method-selector/mount-express-methods.js +38 -62
- package/dist/views/method-selector/mount-methods.js +18 -18
- package/dist/views/modal.js +21 -15
- package/dist/views/result.js +13 -16
- package/dist/views/summary.js +170 -114
- package/dist/views/summary.spec.js +72 -76
- package/package.json +5 -4
- package/src/events/base-event.js +15 -17
- package/src/events/events.spec.js +6 -4
- package/src/events/index.js +6 -3
- package/src/functions/destroy.js +12 -13
- package/src/functions/destroy.spec.js +30 -31
- package/src/functions/mount/fetch-data.js +148 -0
- package/src/functions/mount/fetch-data.spec.js +238 -0
- package/src/functions/mount/index.js +129 -244
- package/src/functions/mount/mount.spec.js +35 -139
- package/src/functions/mount/setup-element.js +26 -0
- package/src/functions/mount/setup-framepay.js +41 -0
- package/src/functions/mount/setup-i18n.js +19 -0
- package/src/functions/mount/setup-options.js +100 -0
- package/src/functions/mount/setup-options.spec.js +60 -0
- package/src/functions/mount/setup-storefront.js +24 -0
- package/src/functions/mount/setup-styles.js +30 -0
- package/src/functions/on.js +13 -8
- package/src/functions/on.spec.js +30 -17
- package/src/functions/purchase.js +101 -19
- package/src/functions/purchase.spec.js +18 -18
- package/src/functions/setup.js +48 -0
- package/src/functions/setup.spec.js +98 -0
- package/src/functions/show.js +20 -10
- package/src/functions/show.spec.js +43 -22
- package/src/functions/update.js +50 -27
- package/src/functions/update.spec.js +57 -22
- package/src/i18n/en.json +4 -1
- package/src/i18n/es.json +4 -1
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +14 -11
- package/src/index.js +41 -52
- package/src/index.spec.js +8 -37
- package/src/loader/index.js +51 -47
- package/src/loader/loader.spec.js +26 -19
- package/src/storefront/index.js +37 -7
- package/src/storefront/invoices.js +11 -0
- package/src/storefront/models/base-model.js +10 -0
- package/src/storefront/models/invoice-model.js +3 -0
- package/src/storefront/models/plan-model.js +3 -35
- package/src/storefront/models/product-model.js +3 -23
- package/src/storefront/models/ready-to-pay-model.js +3 -3
- package/src/storefront/models/summary-model.js +15 -29
- package/src/storefront/models/transaction-model.js +19 -0
- package/src/storefront/payment-instruments.js +30 -0
- package/src/storefront/payment-instruments.spec.js +69 -0
- package/src/storefront/plans.js +16 -23
- package/src/storefront/plans.spec.js +25 -54
- package/src/storefront/products.js +18 -22
- package/src/storefront/products.spec.js +23 -54
- package/src/storefront/purchase.js +14 -14
- package/src/storefront/purchase.spec.js +17 -29
- package/src/storefront/ready-to-pay.js +26 -23
- package/src/storefront/ready-to-pay.spec.js +41 -71
- package/src/storefront/storefront.spec.js +1 -1
- package/src/storefront/summary.js +26 -22
- package/src/storefront/summary.spec.js +60 -109
- package/src/storefront/transactions.js +11 -0
- package/src/style/base/theme.js +10 -8
- package/src/style/base/theme.spec.js +4 -2
- package/src/style/browserslist.js +1 -3
- package/src/style/components/button.js +3 -1
- package/src/style/components/forms/checkbox.js +3 -1
- package/src/style/components/index.js +1 -1
- package/src/style/components/loader.js +3 -1
- package/src/style/components/methods.js +43 -42
- package/src/style/helpers/index.js +1 -1
- package/src/style/index.js +2 -1
- package/src/style/utils/color-values.js +4 -4
- package/src/style/vendor/framepay.js +1 -1
- package/src/style/vendor/postmate.js +1 -1
- package/src/style/views/confirmation.js +0 -4
- package/src/style/views/index.js +1 -1
- package/src/style/views/method-selector.js +1 -1
- package/src/style/views/modal.js +4 -2
- package/src/style/views/summary.js +5 -1
- package/src/utils/add-dom-element.js +12 -13
- package/src/utils/format-currency.js +6 -2
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +27 -24
- package/src/utils/sleep.js +1 -1
- package/src/views/__snapshots__/summary.spec.js.snap +103 -113
- package/src/views/common/iframe/base-iframe.js +12 -4
- package/src/views/common/iframe/event-listeners.js +6 -6
- package/src/views/common/iframe/index.js +1 -1
- package/src/views/common/iframe/method-iframe.js +3 -6
- package/src/views/common/iframe/modal-iframe.js +42 -6
- package/src/views/common/iframe/view-iframe.js +3 -5
- package/src/views/common/render-utilities.js +3 -3
- package/src/views/confirmation.js +34 -25
- package/src/views/method-selector/express-methods/apple-pay.js +78 -0
- package/src/views/method-selector/express-methods/google-pay.js +24 -0
- package/src/views/method-selector/express-methods/paypal.js +7 -0
- package/src/views/method-selector/generate-digital-wallet.js +51 -0
- package/src/views/method-selector/generate-digital-wallet.spec.js +135 -0
- package/src/views/method-selector/get-method-data.js +7 -4
- package/src/views/method-selector/get-payment-methods.js +38 -29
- package/src/views/method-selector/get-payment-methods.spec.js +26 -33
- package/src/views/method-selector/index.js +70 -99
- package/src/views/method-selector/method-selector.spec.js +88 -78
- package/src/views/method-selector/mount-express-methods.js +36 -60
- package/src/views/method-selector/mount-methods.js +32 -21
- package/src/views/modal.js +37 -23
- package/src/views/result.js +12 -15
- package/src/views/summary.js +169 -101
- package/src/views/summary.spec.js +99 -74
- package/tests/async-utilities.js +22 -0
- package/tests/mocks/rebilly-instruments-mock.js +89 -77
- package/tests/mocks/storefront-api-mock.js +8 -0
- package/tests/mocks/storefront-mock.js +17 -0
- package/dist/events/purchase-completed.js +0 -24
- package/dist/functions/initialize.js +0 -82
- package/dist/functions/initialize.spec.js +0 -34
- package/dist/functions/mount/fetch-summary-data.js +0 -31
- package/dist/functions/mount/fetch-summary-data.spec.js +0 -45
- package/dist/views/method-selector/process-digital-wallet-options.js +0 -35
- package/dist/views/method-selector/process-digital-wallet-options.spec.js +0 -80
- package/src/events/purchase-completed.js +0 -11
- package/src/functions/initialize.js +0 -74
- package/src/functions/initialize.spec.js +0 -38
- package/src/functions/mount/fetch-summary-data.js +0 -26
- package/src/functions/mount/fetch-summary-data.spec.js +0 -46
- package/src/views/method-selector/process-digital-wallet-options.js +0 -16
- package/src/views/method-selector/process-digital-wallet-options.spec.js +0 -94
|
@@ -11,54 +11,53 @@ describe('RebillyInstruments Destroy', () => {
|
|
|
11
11
|
|
|
12
12
|
expect(formElement.innerHTML).not.toEqual('');
|
|
13
13
|
expect(summaryElement.innerHTML).not.toEqual('');
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
await rebillyInstruments.destroy();
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
expect(formElement.innerHTML).toEqual('');
|
|
18
18
|
expect(summaryElement.innerHTML).toEqual('');
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
+
it('should remove registered listeners', async () => {
|
|
22
|
+
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
23
|
+
|
|
24
|
+
const fakeEventListener = jest.fn();
|
|
25
|
+
Events.fakeEvent = new BaseEvent('fake-event');
|
|
26
|
+
publicEventNames.push('fake-event');
|
|
27
|
+
rebillyInstruments.on('fake-event', fakeEventListener);
|
|
28
|
+
|
|
29
|
+
Events.fakeEvent.dispatch();
|
|
30
|
+
|
|
31
|
+
expect(fakeEventListener).toHaveBeenCalledTimes(1);
|
|
21
32
|
|
|
22
|
-
|
|
33
|
+
fakeEventListener.mockClear();
|
|
34
|
+
await rebillyInstruments.destroy();
|
|
35
|
+
|
|
36
|
+
Events.fakeEvent.dispatch();
|
|
37
|
+
expect(fakeEventListener).not.toHaveBeenCalled();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should remove multiple listeners on the same event', async () => {
|
|
23
41
|
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
24
|
-
|
|
42
|
+
|
|
25
43
|
const fakeEventListener = jest.fn();
|
|
44
|
+
const anotherFakeEventListener = jest.fn();
|
|
26
45
|
Events.fakeEvent = new BaseEvent('fake-event');
|
|
27
46
|
publicEventNames.push('fake-event');
|
|
28
47
|
rebillyInstruments.on('fake-event', fakeEventListener);
|
|
48
|
+
rebillyInstruments.on('fake-event', anotherFakeEventListener);
|
|
29
49
|
|
|
30
50
|
Events.fakeEvent.dispatch();
|
|
31
|
-
|
|
51
|
+
|
|
32
52
|
expect(fakeEventListener).toHaveBeenCalledTimes(1);
|
|
33
|
-
|
|
53
|
+
expect(anotherFakeEventListener).toHaveBeenCalledTimes(1);
|
|
54
|
+
|
|
34
55
|
fakeEventListener.mockClear();
|
|
56
|
+
anotherFakeEventListener.mockClear();
|
|
35
57
|
await rebillyInstruments.destroy();
|
|
36
|
-
|
|
58
|
+
|
|
37
59
|
Events.fakeEvent.dispatch();
|
|
38
60
|
expect(fakeEventListener).not.toHaveBeenCalled();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
it('should remove multiple listeners on the same event', async ()=> {
|
|
42
|
-
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
43
|
-
|
|
44
|
-
const fakeEventListener = jest.fn();
|
|
45
|
-
const anotherFakeEventListener = jest.fn();
|
|
46
|
-
Events.fakeEvent = new BaseEvent('fake-event');
|
|
47
|
-
publicEventNames.push('fake-event');
|
|
48
|
-
rebillyInstruments.on('fake-event', fakeEventListener);
|
|
49
|
-
rebillyInstruments.on('fake-event', anotherFakeEventListener);
|
|
50
|
-
|
|
51
|
-
Events.fakeEvent.dispatch();
|
|
52
|
-
|
|
53
|
-
expect(fakeEventListener).toHaveBeenCalledTimes(1);
|
|
54
|
-
expect(anotherFakeEventListener).toHaveBeenCalledTimes(1);
|
|
55
|
-
|
|
56
|
-
fakeEventListener.mockClear();
|
|
57
|
-
anotherFakeEventListener.mockClear();
|
|
58
|
-
await rebillyInstruments.destroy();
|
|
59
|
-
|
|
60
|
-
Events.fakeEvent.dispatch();
|
|
61
|
-
expect(fakeEventListener).not.toHaveBeenCalled();
|
|
62
|
-
expect(anotherFakeEventListener).not.toHaveBeenCalled();
|
|
61
|
+
expect(anotherFakeEventListener).not.toHaveBeenCalled();
|
|
63
62
|
});
|
|
64
63
|
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { collectData } from '@rebilly/risk-data-collector';
|
|
2
|
+
import { fetchPlans } from '../../storefront/plans';
|
|
3
|
+
import { fetchProducts } from '../../storefront/products';
|
|
4
|
+
import { fetchReadyToPay } from '../../storefront/ready-to-pay';
|
|
5
|
+
import { fetchSummary } from '../../storefront/summary';
|
|
6
|
+
import { fetchInvoice as FetchInvoice } from '../../storefront/invoices';
|
|
7
|
+
import { fetchTransaction as FetchTransaction } from '../../storefront/transactions';
|
|
8
|
+
|
|
9
|
+
export class DataInstance {
|
|
10
|
+
constructor({
|
|
11
|
+
state = {},
|
|
12
|
+
...fields
|
|
13
|
+
} = {}) {
|
|
14
|
+
Object.entries({
|
|
15
|
+
...state.data || {},
|
|
16
|
+
...fields
|
|
17
|
+
}).forEach(([key, value]) => {
|
|
18
|
+
this[key] = value;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
this.money = state.options?.money || null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get amountAndCurrency() {
|
|
25
|
+
let currency;
|
|
26
|
+
let amount;
|
|
27
|
+
if (this.previewPurchase) {
|
|
28
|
+
currency = this.previewPurchase.currency;
|
|
29
|
+
amount = this.previewPurchase.total;
|
|
30
|
+
} else if (this.invoice) {
|
|
31
|
+
currency = this.invoice.currency;
|
|
32
|
+
amount = this.invoice.amount;
|
|
33
|
+
} else if (this.transaction) {
|
|
34
|
+
currency = this.transaction.currency;
|
|
35
|
+
amount = this.transaction.amount;
|
|
36
|
+
} else if (this.money) {
|
|
37
|
+
currency = this.money.currency;
|
|
38
|
+
amount = this.money.amount;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
amount,
|
|
42
|
+
currency
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get isPayment() {
|
|
47
|
+
return (this.invoice || this.transaction || this.money);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get isPurchase() {
|
|
51
|
+
return this.previewPurchase;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get summaryItems() {
|
|
55
|
+
const {
|
|
56
|
+
discountsAmount = null,
|
|
57
|
+
shippingAmount = null,
|
|
58
|
+
subtotalAmount = null,
|
|
59
|
+
taxAmount = null,
|
|
60
|
+
} = (this.previewPurchase || this.invoice || {});
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
discountsAmount,
|
|
64
|
+
shippingAmount,
|
|
65
|
+
subtotalAmount,
|
|
66
|
+
taxAmount
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get summaryLineItems() {
|
|
71
|
+
let lineItems = [];
|
|
72
|
+
if (this.invoice) {
|
|
73
|
+
({
|
|
74
|
+
items: lineItems = [],
|
|
75
|
+
} = this.invoice)
|
|
76
|
+
} else {
|
|
77
|
+
({
|
|
78
|
+
lineItems = [],
|
|
79
|
+
} = this.previewPurchase || {});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return lineItems;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function fetchData({
|
|
87
|
+
state = null,
|
|
88
|
+
riskMetadata = null,
|
|
89
|
+
summaryPayload = null,
|
|
90
|
+
|
|
91
|
+
// Dependancy injectable functions
|
|
92
|
+
fetchInvoice = FetchInvoice,
|
|
93
|
+
fetchTransaction = FetchTransaction
|
|
94
|
+
}) {
|
|
95
|
+
try {
|
|
96
|
+
let transaction = null;
|
|
97
|
+
if (state.options?.transactionId) {
|
|
98
|
+
transaction = await fetchTransaction({data: {
|
|
99
|
+
id: state.options.transactionId
|
|
100
|
+
}, state});
|
|
101
|
+
state.data.transaction = transaction;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let invoice = null;
|
|
105
|
+
if (state.options?.invoiceId || state.data?.transaction?.hasInvoice) {
|
|
106
|
+
invoice = await fetchInvoice({data: {
|
|
107
|
+
id: state.options?.invoiceId || state.data?.transaction?.invoiceId
|
|
108
|
+
}, state});
|
|
109
|
+
state.data.invoice = invoice;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!riskMetadata) {
|
|
113
|
+
const { riskMetadata: data } = await collectData();
|
|
114
|
+
riskMetadata = data;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
state.data = new DataInstance({
|
|
118
|
+
state,
|
|
119
|
+
invoice,
|
|
120
|
+
transaction,
|
|
121
|
+
riskMetadata
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const [readyToPay, previewPurchase] = await Promise.all([
|
|
125
|
+
state.data?.readyToPay || fetchReadyToPay({ riskMetadata, state }),
|
|
126
|
+
state.options.items ? fetchSummary({ data: summaryPayload, state }) : null
|
|
127
|
+
]);
|
|
128
|
+
|
|
129
|
+
const plans = await fetchPlans({ state });
|
|
130
|
+
state.data.plans = plans;
|
|
131
|
+
const products = await fetchProducts({ state });
|
|
132
|
+
|
|
133
|
+
return new DataInstance({
|
|
134
|
+
state,
|
|
135
|
+
readyToPay,
|
|
136
|
+
previewPurchase,
|
|
137
|
+
plans,
|
|
138
|
+
products,
|
|
139
|
+
invoice,
|
|
140
|
+
transaction,
|
|
141
|
+
riskMetadata
|
|
142
|
+
});
|
|
143
|
+
} catch(error) {
|
|
144
|
+
// console.log(error);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return new DataInstance({});
|
|
148
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { fetchData, DataInstance } from './fetch-data';
|
|
2
|
+
import TransactionModel from '../../storefront/models/transaction-model';
|
|
3
|
+
|
|
4
|
+
describe('fetchData function', () => {
|
|
5
|
+
it('Should use correct invoice id for invoiceId', async () => {
|
|
6
|
+
const mockFetchInvoice = jest.fn();
|
|
7
|
+
const invoiceId = 'test-invoice-id';
|
|
8
|
+
const invoiceState = {
|
|
9
|
+
options: {
|
|
10
|
+
invoiceId
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
fetchData({
|
|
15
|
+
state: invoiceState,
|
|
16
|
+
fetchInvoice: mockFetchInvoice
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(mockFetchInvoice).toBeCalledTimes(1);
|
|
20
|
+
expect(mockFetchInvoice).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 mockFetchInvoice = jest.fn();
|
|
31
|
+
const invoiceId = 'test-invoice-id';
|
|
32
|
+
const invoiceState = {
|
|
33
|
+
options: {},
|
|
34
|
+
data: {
|
|
35
|
+
transaction: new TransactionModel({
|
|
36
|
+
invoiceIds: [invoiceId]
|
|
37
|
+
}),
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fetchData({
|
|
42
|
+
state: invoiceState,
|
|
43
|
+
fetchInvoice: mockFetchInvoice
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(mockFetchInvoice).toBeCalledTimes(1);
|
|
47
|
+
expect(mockFetchInvoice).toBeCalledWith(
|
|
48
|
+
expect.objectContaining({
|
|
49
|
+
data:{
|
|
50
|
+
id: invoiceId
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('Should not fetch invoice for transaction with no invoice Ids', async () => {
|
|
57
|
+
const mockFetchInvoice = jest.fn();
|
|
58
|
+
const invoiceState = {
|
|
59
|
+
options: {},
|
|
60
|
+
data: {
|
|
61
|
+
transaction: new TransactionModel({
|
|
62
|
+
invoiceIds: []
|
|
63
|
+
}),
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
fetchData({
|
|
68
|
+
state: invoiceState,
|
|
69
|
+
fetchInvoice: mockFetchInvoice
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(mockFetchInvoice).toBeCalledTimes(0);
|
|
73
|
+
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('DataInstance', () => {
|
|
78
|
+
it ('Should correctly determine amountAndCurrency', () => {
|
|
79
|
+
const expectedAmountAndCurrency = {
|
|
80
|
+
amount: 10,
|
|
81
|
+
currency: 'USD'
|
|
82
|
+
}
|
|
83
|
+
let fetchedData = new DataInstance({
|
|
84
|
+
state: {
|
|
85
|
+
options: {
|
|
86
|
+
money: {
|
|
87
|
+
...expectedAmountAndCurrency
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
expect(fetchedData.amountAndCurrency).toEqual(
|
|
93
|
+
expect.objectContaining(expectedAmountAndCurrency)
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
fetchedData = new DataInstance({
|
|
97
|
+
previewPurchase: {
|
|
98
|
+
total: expectedAmountAndCurrency.amount,
|
|
99
|
+
currency: expectedAmountAndCurrency.currency
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
expect(fetchedData.amountAndCurrency).toEqual(
|
|
103
|
+
expect.objectContaining(expectedAmountAndCurrency)
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
fetchedData = new DataInstance({
|
|
107
|
+
invoice: {
|
|
108
|
+
...expectedAmountAndCurrency
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
expect(fetchedData.amountAndCurrency).toEqual(
|
|
112
|
+
expect.objectContaining(expectedAmountAndCurrency)
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
fetchedData = new DataInstance({
|
|
116
|
+
transaction: {
|
|
117
|
+
...expectedAmountAndCurrency
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
expect(fetchedData.amountAndCurrency).toEqual(
|
|
121
|
+
expect.objectContaining(expectedAmountAndCurrency)
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
fetchedData = new DataInstance();
|
|
125
|
+
expect(fetchedData.amountAndCurrency).toEqual(
|
|
126
|
+
expect.objectContaining({
|
|
127
|
+
amount: undefined,
|
|
128
|
+
currency: undefined
|
|
129
|
+
})
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it ('Should correctly determine isPayment', () => {
|
|
134
|
+
let fetchedData = new DataInstance({
|
|
135
|
+
state: {
|
|
136
|
+
options: {
|
|
137
|
+
money: true
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
expect(fetchedData.isPayment).toBeTruthy();
|
|
142
|
+
|
|
143
|
+
fetchedData = new DataInstance({
|
|
144
|
+
invoice: true
|
|
145
|
+
});
|
|
146
|
+
expect(fetchedData.isPayment).toBeTruthy();
|
|
147
|
+
|
|
148
|
+
fetchedData = new DataInstance({
|
|
149
|
+
transaction: true
|
|
150
|
+
});
|
|
151
|
+
expect(fetchedData.isPayment).toBeTruthy();
|
|
152
|
+
|
|
153
|
+
fetchedData = new DataInstance({
|
|
154
|
+
previewPurchase: true
|
|
155
|
+
});
|
|
156
|
+
expect(fetchedData.isPayment).toBeFalsy();
|
|
157
|
+
|
|
158
|
+
fetchedData = new DataInstance({});
|
|
159
|
+
expect(fetchedData.isPayment).toBeFalsy();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it ('Should correctly determine isPurchase', () => {
|
|
163
|
+
let fetchedData = new DataInstance({
|
|
164
|
+
previewPurchase: true
|
|
165
|
+
});
|
|
166
|
+
expect(fetchedData.isPurchase).toBeTruthy();
|
|
167
|
+
|
|
168
|
+
fetchedData = new DataInstance({
|
|
169
|
+
state: {
|
|
170
|
+
options: {
|
|
171
|
+
money: true
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
176
|
+
|
|
177
|
+
fetchedData = new DataInstance({
|
|
178
|
+
invoice: true
|
|
179
|
+
});
|
|
180
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
181
|
+
|
|
182
|
+
fetchedData = new DataInstance({
|
|
183
|
+
transaction: true
|
|
184
|
+
});
|
|
185
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
186
|
+
|
|
187
|
+
fetchedData = new DataInstance({});
|
|
188
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it ('Should get summaryItems', () => {
|
|
192
|
+
const expectedSummaryItems = {
|
|
193
|
+
discountsAmount: 1,
|
|
194
|
+
shippingAmount: 2,
|
|
195
|
+
subtotalAmount: 3,
|
|
196
|
+
taxAmount: 4
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
let fetchedData = new DataInstance({
|
|
200
|
+
previewPurchase: {
|
|
201
|
+
...expectedSummaryItems
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
expect(fetchedData.summaryItems).toEqual(
|
|
205
|
+
expect.objectContaining(expectedSummaryItems)
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
fetchedData = new DataInstance({
|
|
209
|
+
invoice: {
|
|
210
|
+
...expectedSummaryItems
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
expect(fetchedData.summaryItems).toEqual(
|
|
214
|
+
expect.objectContaining(expectedSummaryItems)
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it ('Should get summaryLineItems', () => {
|
|
219
|
+
const expectedSummaryLineItems = [{
|
|
220
|
+
line: 'item'
|
|
221
|
+
}];
|
|
222
|
+
|
|
223
|
+
let fetchedData = new DataInstance({
|
|
224
|
+
previewPurchase: {
|
|
225
|
+
lineItems: expectedSummaryLineItems
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
|
|
229
|
+
|
|
230
|
+
fetchedData = new DataInstance({
|
|
231
|
+
invoice: {
|
|
232
|
+
items: expectedSummaryLineItems
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|