@rebilly/instruments 2.0.0-beta → 3.0.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/dist/events/index.js +2 -1
- package/dist/functions/mount/fetch-data.js +187 -0
- package/dist/functions/mount/fetch-data.spec.js +189 -0
- package/dist/functions/mount/index.js +132 -164
- package/dist/functions/mount/mount.spec.js +2 -4
- package/dist/functions/mount/setup-element.js +40 -0
- package/dist/functions/mount/setup-framepay-theme.js +95 -0
- package/dist/functions/mount/setup-framepay.js +5 -1
- package/dist/functions/mount/setup-i18n.js +33 -0
- package/dist/functions/mount/setup-options.js +68 -47
- package/dist/functions/mount/setup-options.spec.js +66 -0
- package/dist/functions/mount/setup-storefront.js +6 -4
- package/dist/functions/mount/setup-styles.js +4 -2
- package/dist/functions/purchase.js +129 -24
- package/dist/functions/purchase.spec.js +13 -10
- package/dist/functions/setup.js +85 -0
- package/dist/functions/setup.spec.js +87 -0
- package/dist/functions/show.js +8 -4
- package/dist/functions/show.spec.js +9 -5
- package/dist/functions/update.js +39 -24
- package/dist/functions/update.spec.js +0 -4
- package/dist/i18n/en.json +5 -2
- package/dist/i18n/es.json +4 -1
- package/dist/index.js +17 -3
- package/dist/index.spec.js +3 -16
- 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 +10 -18
- package/dist/storefront/plans.spec.js +3 -13
- package/dist/storefront/products.js +10 -13
- package/dist/storefront/products.spec.js +12 -19
- package/dist/storefront/purchase.js +23 -12
- package/dist/storefront/purchase.spec.js +1 -20
- package/dist/storefront/ready-to-pay.js +18 -15
- package/dist/storefront/ready-to-pay.spec.js +2 -12
- package/dist/storefront/summary.js +21 -17
- package/dist/storefront/summary.spec.js +4 -15
- package/dist/storefront/transactions.js +27 -0
- package/dist/style/base/__snapshots__/theme.spec.js.snap +188 -45
- package/dist/style/base/default-theme.js +699 -0
- package/dist/style/base/index.js +48 -16
- package/dist/style/base/theme.js +16 -48
- package/dist/style/base/theme.spec.js +4 -15
- package/dist/style/components/address.js +3 -3
- package/dist/style/components/button.js +32 -22
- package/dist/style/components/divider.js +9 -9
- package/dist/style/components/forms/checkbox.js +12 -9
- package/dist/style/components/forms/field.js +18 -6
- package/dist/style/components/forms/form.js +2 -2
- package/dist/style/components/forms/input.js +54 -13
- package/dist/style/components/forms/label.js +39 -18
- package/dist/style/components/forms/select.js +54 -22
- package/dist/style/components/forms/validation.js +53 -6
- package/dist/style/components/icons.js +4 -4
- package/dist/style/components/loader.js +5 -3
- package/dist/style/components/methods.js +18 -15
- package/dist/style/components/overlay.js +5 -5
- package/dist/style/helpers/index.js +46 -46
- package/dist/style/index.js +3 -1
- package/dist/style/payment-instruments/payment-card.js +4 -4
- package/dist/style/utils/border.js +47 -0
- package/dist/style/utils/color-values.js +39 -3
- package/dist/style/utils/remove-empty-null.js +20 -0
- package/dist/style/vendor/framepay.js +11 -8
- package/dist/style/vendor/postmate.js +2 -2
- package/dist/style/views/confirmation.js +13 -13
- package/dist/style/views/method-selector.js +2 -2
- package/dist/style/views/modal.js +6 -6
- package/dist/style/views/result.js +4 -4
- package/dist/style/views/summary.js +26 -22
- package/dist/views/__snapshots__/summary.spec.js.snap +77 -119
- package/dist/views/common/iframe/base-iframe.js +2 -0
- package/dist/views/common/iframe/modal-iframe.js +50 -4
- package/dist/views/confirmation.js +19 -8
- package/dist/views/method-selector/generate-digital-wallet.js +12 -3
- package/dist/views/method-selector/generate-digital-wallet.spec.js +11 -0
- package/dist/views/method-selector/get-payment-methods.js +13 -2
- package/dist/views/method-selector/get-payment-methods.spec.js +21 -19
- package/dist/views/method-selector/index.js +23 -34
- package/dist/views/method-selector/method-selector.spec.js +50 -55
- package/dist/views/method-selector/mount-methods.js +5 -8
- package/dist/views/modal.js +8 -2
- package/dist/views/result.js +3 -4
- package/dist/views/summary.js +156 -97
- package/dist/views/summary.spec.js +53 -58
- package/package.json +4 -2
- package/src/events/index.js +2 -1
- package/src/functions/mount/fetch-data.js +152 -0
- package/src/functions/mount/fetch-data.spec.js +238 -0
- package/src/functions/mount/index.js +101 -158
- package/src/functions/mount/mount.spec.js +3 -5
- package/src/functions/mount/setup-element.js +26 -0
- package/src/functions/mount/setup-framepay-theme.js +82 -0
- package/src/functions/mount/setup-framepay.js +5 -1
- package/src/functions/mount/setup-i18n.js +19 -0
- package/src/functions/mount/setup-options.js +78 -48
- package/src/functions/mount/setup-options.spec.js +60 -0
- package/src/functions/mount/setup-storefront.js +6 -4
- package/src/functions/mount/setup-styles.js +4 -2
- package/src/functions/on.spec.js +1 -1
- package/src/functions/purchase.js +99 -23
- package/src/functions/purchase.spec.js +10 -10
- package/src/functions/setup.js +48 -0
- package/src/functions/setup.spec.js +98 -0
- package/src/functions/show.js +2 -4
- package/src/functions/show.spec.js +3 -4
- package/src/functions/update.js +40 -25
- package/src/functions/update.spec.js +0 -4
- package/src/i18n/en.json +5 -2
- package/src/i18n/es.json +4 -1
- package/src/index.js +9 -3
- package/src/index.spec.js +3 -21
- package/src/loader/index.js +3 -3
- package/src/storefront/index.js +28 -0
- 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/summary-model.js +12 -19
- 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 +6 -17
- package/src/storefront/plans.spec.js +4 -11
- package/src/storefront/products.js +8 -16
- package/src/storefront/products.spec.js +16 -22
- package/src/storefront/purchase.js +14 -16
- package/src/storefront/purchase.spec.js +2 -14
- package/src/storefront/ready-to-pay.js +13 -16
- package/src/storefront/ready-to-pay.spec.js +3 -10
- package/src/storefront/summary.js +19 -17
- package/src/storefront/summary.spec.js +5 -12
- package/src/storefront/transactions.js +11 -0
- package/src/style/base/__snapshots__/theme.spec.js.snap +188 -45
- package/src/style/base/default-theme.js +674 -0
- package/src/style/base/index.js +48 -16
- package/src/style/base/theme.js +17 -47
- package/src/style/base/theme.spec.js +4 -16
- package/src/style/components/address.js +3 -3
- package/src/style/components/button.js +32 -24
- package/src/style/components/divider.js +9 -9
- package/src/style/components/forms/checkbox.js +11 -11
- package/src/style/components/forms/field.js +18 -6
- package/src/style/components/forms/form.js +2 -2
- package/src/style/components/forms/input.js +54 -13
- package/src/style/components/forms/label.js +39 -18
- package/src/style/components/forms/select.js +54 -22
- package/src/style/components/forms/validation.js +53 -6
- package/src/style/components/icons.js +4 -4
- package/src/style/components/loader.js +4 -5
- package/src/style/components/methods.js +18 -15
- package/src/style/components/overlay.js +5 -5
- package/src/style/helpers/index.js +46 -46
- package/src/style/index.js +2 -1
- package/src/style/payment-instruments/payment-card.js +4 -4
- package/src/style/utils/border.js +34 -0
- package/src/style/utils/color-values.js +27 -1
- package/src/style/utils/remove-empty-null.js +10 -0
- package/src/style/vendor/framepay.js +11 -8
- package/src/style/vendor/postmate.js +2 -2
- package/src/style/views/confirmation.js +13 -13
- package/src/style/views/method-selector.js +2 -2
- package/src/style/views/modal.js +6 -6
- package/src/style/views/result.js +4 -4
- package/src/style/views/summary.js +26 -22
- package/src/views/__snapshots__/summary.spec.js.snap +77 -119
- package/src/views/common/iframe/base-iframe.js +2 -0
- package/src/views/common/iframe/modal-iframe.js +45 -3
- package/src/views/confirmation.js +15 -5
- package/src/views/method-selector/generate-digital-wallet.js +10 -3
- package/src/views/method-selector/generate-digital-wallet.spec.js +10 -0
- package/src/views/method-selector/get-payment-methods.js +7 -2
- package/src/views/method-selector/get-payment-methods.spec.js +26 -23
- package/src/views/method-selector/index.js +21 -28
- package/src/views/method-selector/method-selector.spec.js +49 -64
- package/src/views/method-selector/mount-methods.js +5 -8
- package/src/views/modal.js +6 -2
- package/src/views/result.js +4 -3
- package/src/views/summary.js +161 -117
- package/src/views/summary.spec.js +60 -75
- package/tests/mocks/rebilly-instruments-mock.js +37 -7
- package/tests/mocks/storefront-api-mock.js +8 -0
- package/tests/mocks/storefront-mock.js +17 -0
- package/dist/functions/mount/fetch-summary-data.js +0 -46
- package/dist/functions/mount/fetch-summary-data.spec.js +0 -43
- package/src/functions/mount/fetch-summary-data.js +0 -29
- package/src/functions/mount/fetch-summary-data.spec.js +0 -40
package/dist/events/index.js
CHANGED
|
@@ -13,7 +13,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
13
13
|
|
|
14
14
|
const events = {
|
|
15
15
|
instrumentReady: new _baseEvent.default('instrument-ready'),
|
|
16
|
-
purchaseCompleted: new _baseEvent.default('purchase-completed')
|
|
16
|
+
purchaseCompleted: new _baseEvent.default('purchase-completed'),
|
|
17
|
+
setupCompleted: new _baseEvent.default('setup-completed')
|
|
17
18
|
};
|
|
18
19
|
var _default = events;
|
|
19
20
|
exports.default = _default;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fetchData = fetchData;
|
|
7
|
+
exports.DataInstance = void 0;
|
|
8
|
+
|
|
9
|
+
var _riskDataCollector = require("@rebilly/risk-data-collector");
|
|
10
|
+
|
|
11
|
+
var _plans = require("../../storefront/plans");
|
|
12
|
+
|
|
13
|
+
var _products = require("../../storefront/products");
|
|
14
|
+
|
|
15
|
+
var _readyToPay = require("../../storefront/ready-to-pay");
|
|
16
|
+
|
|
17
|
+
var _summary = require("../../storefront/summary");
|
|
18
|
+
|
|
19
|
+
var _invoices = require("../../storefront/invoices");
|
|
20
|
+
|
|
21
|
+
var _transactions = require("../../storefront/transactions");
|
|
22
|
+
|
|
23
|
+
class DataInstance {
|
|
24
|
+
constructor({
|
|
25
|
+
state = {},
|
|
26
|
+
...fields
|
|
27
|
+
} = {}) {
|
|
28
|
+
var _state$options;
|
|
29
|
+
|
|
30
|
+
Object.entries({ ...(state.data || {}),
|
|
31
|
+
...fields
|
|
32
|
+
}).forEach(([key, value]) => {
|
|
33
|
+
this[key] = value;
|
|
34
|
+
});
|
|
35
|
+
this.money = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.money) || null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get amountAndCurrency() {
|
|
39
|
+
let currency;
|
|
40
|
+
let amount;
|
|
41
|
+
|
|
42
|
+
if (this.previewPurchase) {
|
|
43
|
+
currency = this.previewPurchase.currency;
|
|
44
|
+
amount = this.previewPurchase.total;
|
|
45
|
+
} else if (this.invoice) {
|
|
46
|
+
currency = this.invoice.currency;
|
|
47
|
+
amount = this.invoice.amount;
|
|
48
|
+
} else if (this.transaction) {
|
|
49
|
+
currency = this.transaction.currency;
|
|
50
|
+
amount = this.transaction.amount;
|
|
51
|
+
} else if (this.money) {
|
|
52
|
+
currency = this.money.currency;
|
|
53
|
+
amount = this.money.amount;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
amount,
|
|
58
|
+
currency
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get isPayment() {
|
|
63
|
+
return this.invoice || this.transaction || this.money;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get isPurchase() {
|
|
67
|
+
return this.previewPurchase;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get summaryItems() {
|
|
71
|
+
const {
|
|
72
|
+
discountsAmount = null,
|
|
73
|
+
shippingAmount = null,
|
|
74
|
+
subtotalAmount = null,
|
|
75
|
+
taxAmount = null
|
|
76
|
+
} = this.previewPurchase || this.invoice || {};
|
|
77
|
+
return {
|
|
78
|
+
discountsAmount,
|
|
79
|
+
shippingAmount,
|
|
80
|
+
subtotalAmount,
|
|
81
|
+
taxAmount
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get summaryLineItems() {
|
|
86
|
+
let lineItems = [];
|
|
87
|
+
|
|
88
|
+
if (this.invoice) {
|
|
89
|
+
({
|
|
90
|
+
items: lineItems = []
|
|
91
|
+
} = this.invoice);
|
|
92
|
+
} else {
|
|
93
|
+
({
|
|
94
|
+
lineItems = []
|
|
95
|
+
} = this.previewPurchase || {});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return lineItems;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
get isShippingRequired() {
|
|
102
|
+
return this.products.some(product => product.requiresShipping);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
exports.DataInstance = DataInstance;
|
|
108
|
+
|
|
109
|
+
async function fetchData({
|
|
110
|
+
state = null,
|
|
111
|
+
riskMetadata = null,
|
|
112
|
+
summaryPayload = null,
|
|
113
|
+
// Dependancy injectable functions
|
|
114
|
+
fetchInvoice = _invoices.fetchInvoice,
|
|
115
|
+
fetchTransaction = _transactions.fetchTransaction
|
|
116
|
+
}) {
|
|
117
|
+
try {
|
|
118
|
+
var _state$options2, _state$options3, _state$data, _state$data$transacti, _state$data3;
|
|
119
|
+
|
|
120
|
+
let transaction = null;
|
|
121
|
+
|
|
122
|
+
if ((_state$options2 = state.options) !== null && _state$options2 !== void 0 && _state$options2.transactionId) {
|
|
123
|
+
transaction = await fetchTransaction({
|
|
124
|
+
data: {
|
|
125
|
+
id: state.options.transactionId
|
|
126
|
+
},
|
|
127
|
+
state
|
|
128
|
+
});
|
|
129
|
+
state.data.transaction = transaction;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let invoice = null;
|
|
133
|
+
|
|
134
|
+
if ((_state$options3 = state.options) !== null && _state$options3 !== void 0 && _state$options3.invoiceId || (_state$data = state.data) !== null && _state$data !== void 0 && (_state$data$transacti = _state$data.transaction) !== null && _state$data$transacti !== void 0 && _state$data$transacti.hasInvoice) {
|
|
135
|
+
var _state$options4, _state$data2, _state$data2$transact;
|
|
136
|
+
|
|
137
|
+
invoice = await fetchInvoice({
|
|
138
|
+
data: {
|
|
139
|
+
id: ((_state$options4 = state.options) === null || _state$options4 === void 0 ? void 0 : _state$options4.invoiceId) || ((_state$data2 = state.data) === null || _state$data2 === void 0 ? void 0 : (_state$data2$transact = _state$data2.transaction) === null || _state$data2$transact === void 0 ? void 0 : _state$data2$transact.invoiceId)
|
|
140
|
+
},
|
|
141
|
+
state
|
|
142
|
+
});
|
|
143
|
+
state.data.invoice = invoice;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!riskMetadata) {
|
|
147
|
+
const {
|
|
148
|
+
riskMetadata: data
|
|
149
|
+
} = await (0, _riskDataCollector.collectData)();
|
|
150
|
+
riskMetadata = data;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
state.data = new DataInstance({
|
|
154
|
+
state,
|
|
155
|
+
invoice,
|
|
156
|
+
transaction,
|
|
157
|
+
riskMetadata
|
|
158
|
+
});
|
|
159
|
+
const [readyToPay, previewPurchase] = await Promise.all([((_state$data3 = state.data) === null || _state$data3 === void 0 ? void 0 : _state$data3.readyToPay) || (0, _readyToPay.fetchReadyToPay)({
|
|
160
|
+
riskMetadata,
|
|
161
|
+
state
|
|
162
|
+
}), state.options.items ? (0, _summary.fetchSummary)({
|
|
163
|
+
data: summaryPayload,
|
|
164
|
+
state
|
|
165
|
+
}) : null]);
|
|
166
|
+
const plans = await (0, _plans.fetchPlans)({
|
|
167
|
+
state
|
|
168
|
+
});
|
|
169
|
+
state.data.plans = plans;
|
|
170
|
+
const products = await (0, _products.fetchProducts)({
|
|
171
|
+
state
|
|
172
|
+
});
|
|
173
|
+
return new DataInstance({
|
|
174
|
+
state,
|
|
175
|
+
readyToPay,
|
|
176
|
+
previewPurchase,
|
|
177
|
+
plans,
|
|
178
|
+
products,
|
|
179
|
+
invoice,
|
|
180
|
+
transaction,
|
|
181
|
+
riskMetadata
|
|
182
|
+
});
|
|
183
|
+
} catch (error) {// console.log(error);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return new DataInstance({});
|
|
187
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _fetchData = require("./fetch-data");
|
|
4
|
+
|
|
5
|
+
var _transactionModel = _interopRequireDefault(require("../../storefront/models/transaction-model"));
|
|
6
|
+
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
|
|
9
|
+
describe('fetchData function', () => {
|
|
10
|
+
it('Should use correct invoice id for invoiceId', async () => {
|
|
11
|
+
const mockFetchInvoice = jest.fn();
|
|
12
|
+
const invoiceId = 'test-invoice-id';
|
|
13
|
+
const invoiceState = {
|
|
14
|
+
options: {
|
|
15
|
+
invoiceId
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
(0, _fetchData.fetchData)({
|
|
19
|
+
state: invoiceState,
|
|
20
|
+
fetchInvoice: mockFetchInvoice
|
|
21
|
+
});
|
|
22
|
+
expect(mockFetchInvoice).toBeCalledTimes(1);
|
|
23
|
+
expect(mockFetchInvoice).toBeCalledWith(expect.objectContaining({
|
|
24
|
+
data: {
|
|
25
|
+
id: invoiceId
|
|
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.default({
|
|
36
|
+
invoiceIds: [invoiceId]
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
(0, _fetchData.fetchData)({
|
|
41
|
+
state: invoiceState,
|
|
42
|
+
fetchInvoice: mockFetchInvoice
|
|
43
|
+
});
|
|
44
|
+
expect(mockFetchInvoice).toBeCalledTimes(1);
|
|
45
|
+
expect(mockFetchInvoice).toBeCalledWith(expect.objectContaining({
|
|
46
|
+
data: {
|
|
47
|
+
id: invoiceId
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
});
|
|
51
|
+
it('Should not fetch invoice for transaction with no invoice Ids', async () => {
|
|
52
|
+
const mockFetchInvoice = jest.fn();
|
|
53
|
+
const invoiceState = {
|
|
54
|
+
options: {},
|
|
55
|
+
data: {
|
|
56
|
+
transaction: new _transactionModel.default({
|
|
57
|
+
invoiceIds: []
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
(0, _fetchData.fetchData)({
|
|
62
|
+
state: invoiceState,
|
|
63
|
+
fetchInvoice: mockFetchInvoice
|
|
64
|
+
});
|
|
65
|
+
expect(mockFetchInvoice).toBeCalledTimes(0);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('DataInstance', () => {
|
|
69
|
+
it('Should correctly determine amountAndCurrency', () => {
|
|
70
|
+
const expectedAmountAndCurrency = {
|
|
71
|
+
amount: 10,
|
|
72
|
+
currency: 'USD'
|
|
73
|
+
};
|
|
74
|
+
let fetchedData = new _fetchData.DataInstance({
|
|
75
|
+
state: {
|
|
76
|
+
options: {
|
|
77
|
+
money: { ...expectedAmountAndCurrency
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining(expectedAmountAndCurrency));
|
|
83
|
+
fetchedData = new _fetchData.DataInstance({
|
|
84
|
+
previewPurchase: {
|
|
85
|
+
total: expectedAmountAndCurrency.amount,
|
|
86
|
+
currency: expectedAmountAndCurrency.currency
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining(expectedAmountAndCurrency));
|
|
90
|
+
fetchedData = new _fetchData.DataInstance({
|
|
91
|
+
invoice: { ...expectedAmountAndCurrency
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining(expectedAmountAndCurrency));
|
|
95
|
+
fetchedData = new _fetchData.DataInstance({
|
|
96
|
+
transaction: { ...expectedAmountAndCurrency
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining(expectedAmountAndCurrency));
|
|
100
|
+
fetchedData = new _fetchData.DataInstance();
|
|
101
|
+
expect(fetchedData.amountAndCurrency).toEqual(expect.objectContaining({
|
|
102
|
+
amount: undefined,
|
|
103
|
+
currency: undefined
|
|
104
|
+
}));
|
|
105
|
+
});
|
|
106
|
+
it('Should correctly determine isPayment', () => {
|
|
107
|
+
let fetchedData = new _fetchData.DataInstance({
|
|
108
|
+
state: {
|
|
109
|
+
options: {
|
|
110
|
+
money: true
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
expect(fetchedData.isPayment).toBeTruthy();
|
|
115
|
+
fetchedData = new _fetchData.DataInstance({
|
|
116
|
+
invoice: true
|
|
117
|
+
});
|
|
118
|
+
expect(fetchedData.isPayment).toBeTruthy();
|
|
119
|
+
fetchedData = new _fetchData.DataInstance({
|
|
120
|
+
transaction: true
|
|
121
|
+
});
|
|
122
|
+
expect(fetchedData.isPayment).toBeTruthy();
|
|
123
|
+
fetchedData = new _fetchData.DataInstance({
|
|
124
|
+
previewPurchase: true
|
|
125
|
+
});
|
|
126
|
+
expect(fetchedData.isPayment).toBeFalsy();
|
|
127
|
+
fetchedData = new _fetchData.DataInstance({});
|
|
128
|
+
expect(fetchedData.isPayment).toBeFalsy();
|
|
129
|
+
});
|
|
130
|
+
it('Should correctly determine isPurchase', () => {
|
|
131
|
+
let fetchedData = new _fetchData.DataInstance({
|
|
132
|
+
previewPurchase: true
|
|
133
|
+
});
|
|
134
|
+
expect(fetchedData.isPurchase).toBeTruthy();
|
|
135
|
+
fetchedData = new _fetchData.DataInstance({
|
|
136
|
+
state: {
|
|
137
|
+
options: {
|
|
138
|
+
money: true
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
143
|
+
fetchedData = new _fetchData.DataInstance({
|
|
144
|
+
invoice: true
|
|
145
|
+
});
|
|
146
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
147
|
+
fetchedData = new _fetchData.DataInstance({
|
|
148
|
+
transaction: true
|
|
149
|
+
});
|
|
150
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
151
|
+
fetchedData = new _fetchData.DataInstance({});
|
|
152
|
+
expect(fetchedData.isPurchase).toBeFalsy();
|
|
153
|
+
});
|
|
154
|
+
it('Should get summaryItems', () => {
|
|
155
|
+
const expectedSummaryItems = {
|
|
156
|
+
discountsAmount: 1,
|
|
157
|
+
shippingAmount: 2,
|
|
158
|
+
subtotalAmount: 3,
|
|
159
|
+
taxAmount: 4
|
|
160
|
+
};
|
|
161
|
+
let fetchedData = new _fetchData.DataInstance({
|
|
162
|
+
previewPurchase: { ...expectedSummaryItems
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
expect(fetchedData.summaryItems).toEqual(expect.objectContaining(expectedSummaryItems));
|
|
166
|
+
fetchedData = new _fetchData.DataInstance({
|
|
167
|
+
invoice: { ...expectedSummaryItems
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
expect(fetchedData.summaryItems).toEqual(expect.objectContaining(expectedSummaryItems));
|
|
171
|
+
});
|
|
172
|
+
it('Should get summaryLineItems', () => {
|
|
173
|
+
const expectedSummaryLineItems = [{
|
|
174
|
+
line: 'item'
|
|
175
|
+
}];
|
|
176
|
+
let fetchedData = new _fetchData.DataInstance({
|
|
177
|
+
previewPurchase: {
|
|
178
|
+
lineItems: expectedSummaryLineItems
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
|
|
182
|
+
fetchedData = new _fetchData.DataInstance({
|
|
183
|
+
invoice: {
|
|
184
|
+
items: expectedSummaryLineItems
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
expect(fetchedData.summaryLineItems).toEqual(expectedSummaryLineItems);
|
|
188
|
+
});
|
|
189
|
+
});
|