@rebilly/instruments 1.0.1-beta → 1.0.2-beta.10
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 +23 -5
- package/.eslintrc.js +27 -0
- package/.prettierrc.js +11 -0
- package/CONTRIBUTING.md +4 -0
- package/README.md +361 -2
- package/dist/events/base-event.js +51 -37
- package/dist/events/events.spec.js +18 -0
- package/dist/events/index.js +11 -8
- package/dist/functions/destroy.js +27 -5
- package/dist/functions/destroy.spec.js +69 -0
- package/dist/functions/initialize.js +60 -41
- package/dist/functions/initialize.spec.js +13 -13
- package/dist/functions/mount/fetch-summary-data.js +46 -0
- package/dist/functions/mount/fetch-summary-data.spec.js +44 -0
- package/dist/functions/mount/index.js +346 -0
- package/dist/functions/mount/mount.spec.js +135 -0
- package/dist/functions/on.js +26 -18
- package/dist/functions/on.spec.js +45 -63
- package/dist/functions/purchase.js +41 -154
- package/dist/functions/purchase.spec.js +60 -76
- package/dist/functions/show.js +39 -43
- package/dist/functions/show.spec.js +57 -0
- package/dist/functions/update.js +60 -5
- package/dist/functions/update.spec.js +100 -0
- package/dist/i18n/en.json +19 -0
- package/dist/i18n/es.json +19 -0
- package/dist/i18n/i18n.spec.js +6 -23
- package/dist/i18n/index.js +44 -67
- package/dist/index.js +70 -71
- package/dist/index.spec.js +24 -44
- package/dist/loader/index.js +63 -62
- package/dist/loader/loader.spec.js +14 -11
- package/dist/storefront/index.js +28 -39
- package/dist/storefront/models/plan-model.js +37 -54
- package/dist/storefront/models/product-model.js +25 -36
- package/dist/storefront/models/ready-to-pay-model.js +38 -42
- package/dist/storefront/models/summary-model.js +72 -99
- package/dist/storefront/plans.js +37 -84
- package/dist/storefront/plans.spec.js +61 -151
- package/dist/storefront/products.js +35 -83
- package/dist/storefront/products.spec.js +60 -150
- package/dist/storefront/purchase.js +27 -64
- package/dist/storefront/purchase.spec.js +51 -87
- package/dist/storefront/ready-to-pay.js +45 -107
- package/dist/storefront/ready-to-pay.spec.js +72 -147
- package/dist/storefront/storefront.spec.js +6 -6
- package/dist/storefront/summary.js +37 -84
- package/dist/storefront/summary.spec.js +135 -240
- package/dist/style/base/__snapshots__/theme.spec.js.snap +52 -0
- package/dist/style/base/index.js +72 -0
- package/dist/style/base/theme.js +73 -0
- package/dist/style/base/theme.spec.js +30 -0
- package/dist/style/browserslist.js +8 -0
- package/dist/style/components/address.js +64 -0
- package/dist/style/components/button.js +61 -0
- package/dist/style/components/divider.js +48 -0
- package/dist/style/components/forms/checkbox.js +83 -0
- package/dist/style/components/forms/field.js +53 -0
- package/dist/style/components/forms/form.js +28 -0
- package/dist/style/components/forms/input.js +45 -0
- package/dist/style/components/forms/label.js +43 -0
- package/dist/style/components/forms/select.js +63 -0
- package/dist/style/components/forms/validation.js +34 -0
- package/dist/style/components/icons.js +22 -0
- package/dist/style/components/index.js +57 -0
- package/dist/style/components/loader.js +48 -0
- package/dist/style/components/methods.js +104 -0
- package/dist/style/components/overlay.js +33 -0
- package/dist/style/helpers/index.js +59 -0
- package/dist/style/index.js +48 -0
- package/dist/style/payment-instruments/content.js +17 -0
- package/dist/style/payment-instruments/index.js +20 -0
- package/dist/style/payment-instruments/payment-card.js +35 -0
- package/dist/style/utils/color-values.js +22 -0
- package/dist/style/vendor/framepay.js +34 -0
- package/dist/style/vendor/postmate.js +17 -0
- package/dist/style/views/confirmation.js +85 -0
- package/dist/style/views/index.js +29 -0
- package/dist/style/views/method-selector.js +20 -0
- package/dist/style/views/modal.js +93 -0
- package/dist/style/views/result.js +61 -0
- package/dist/style/views/summary.js +123 -0
- package/dist/utils/add-dom-element.js +12 -34
- package/dist/utils/format-currency.js +4 -4
- package/dist/utils/has-valid-css-selector.js +2 -2
- package/dist/utils/index.js +15 -31
- package/dist/utils/is-dom-element.js +1 -1
- package/dist/utils/process-property-as-dom-element.js +12 -17
- package/dist/utils/sleep.js +10 -0
- package/{src/components → dist/views}/__snapshots__/summary.spec.js.snap +7 -3
- package/dist/views/common/iframe/base-iframe.js +57 -0
- package/dist/views/common/iframe/event-listeners.js +50 -0
- package/dist/views/common/iframe/index.js +19 -0
- package/dist/views/common/iframe/method-iframe.js +33 -0
- package/dist/views/common/iframe/modal-iframe.js +38 -0
- package/dist/views/common/iframe/view-iframe.js +31 -0
- package/dist/views/common/render-utilities.js +11 -0
- package/dist/views/confirmation.js +82 -0
- package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
- package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
- package/dist/views/method-selector/express-methods/google-pay.js +32 -0
- package/dist/views/method-selector/express-methods/paypal.js +19 -0
- package/dist/views/method-selector/generate-digital-wallet.js +59 -0
- package/dist/views/method-selector/generate-digital-wallet.spec.js +132 -0
- package/dist/views/method-selector/get-method-data.js +25 -0
- package/dist/views/method-selector/get-payment-methods.js +55 -0
- package/dist/views/method-selector/get-payment-methods.spec.js +44 -0
- package/dist/views/method-selector/index.js +133 -0
- package/dist/views/method-selector/method-selector.spec.js +139 -0
- package/dist/views/method-selector/mount-express-methods.js +69 -0
- package/dist/views/method-selector/mount-methods.js +78 -0
- package/dist/views/modal.js +83 -0
- package/dist/views/result.js +42 -0
- package/dist/views/summary.js +162 -0
- package/dist/views/summary.spec.js +148 -0
- package/package.json +12 -6
- package/src/events/base-event.js +35 -12
- package/src/events/events.spec.js +11 -0
- package/src/events/index.js +12 -6
- package/src/functions/destroy.js +22 -3
- package/src/functions/destroy.spec.js +63 -0
- package/src/functions/initialize.js +43 -20
- package/src/functions/initialize.spec.js +9 -7
- package/src/functions/mount/fetch-summary-data.js +29 -0
- package/src/functions/mount/fetch-summary-data.spec.js +41 -0
- package/src/functions/mount/index.js +312 -0
- package/src/functions/mount/mount.spec.js +171 -0
- package/src/functions/on.js +17 -14
- package/src/functions/on.spec.js +39 -29
- package/src/functions/purchase.js +24 -64
- package/src/functions/purchase.spec.js +19 -17
- package/src/functions/show.js +27 -7
- package/src/functions/show.spec.js +61 -0
- package/src/functions/update.js +50 -3
- package/src/functions/update.spec.js +107 -0
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +20 -12
- package/src/index.js +43 -49
- package/src/index.spec.js +11 -42
- package/src/loader/index.js +55 -39
- package/src/loader/loader.spec.js +30 -23
- package/src/storefront/index.js +9 -7
- package/src/storefront/models/plan-model.js +1 -1
- package/src/storefront/models/product-model.js +1 -1
- package/src/storefront/models/ready-to-pay-model.js +10 -4
- package/src/storefront/models/summary-model.js +8 -15
- package/src/storefront/plans.js +16 -12
- package/src/storefront/plans.spec.js +29 -37
- package/src/storefront/products.js +16 -12
- package/src/storefront/products.spec.js +28 -39
- package/src/storefront/purchase.js +8 -6
- package/src/storefront/purchase.spec.js +18 -17
- package/src/storefront/ready-to-pay.js +19 -13
- package/src/storefront/ready-to-pay.spec.js +41 -41
- package/src/storefront/storefront.spec.js +1 -1
- package/src/storefront/summary.js +14 -12
- package/src/storefront/summary.spec.js +37 -50
- package/src/style/base/__snapshots__/theme.spec.js.snap +52 -0
- package/src/style/base/index.js +63 -0
- package/src/style/base/theme.js +61 -0
- package/src/style/base/theme.spec.js +32 -0
- package/src/style/browserslist.js +1 -0
- package/src/style/components/address.js +55 -0
- package/src/style/components/button.js +54 -0
- package/src/style/components/divider.js +39 -0
- package/src/style/components/forms/checkbox.js +76 -0
- package/src/style/components/forms/field.js +44 -0
- package/src/style/components/forms/form.js +19 -0
- package/src/style/components/forms/input.js +36 -0
- package/src/style/components/forms/label.js +34 -0
- package/src/style/components/forms/select.js +54 -0
- package/src/style/components/forms/validation.js +25 -0
- package/src/style/components/icons.js +13 -0
- package/src/style/components/index.js +35 -0
- package/src/style/components/loader.js +41 -0
- package/src/style/components/methods.js +93 -0
- package/src/style/components/overlay.js +24 -0
- package/src/style/helpers/index.js +51 -0
- package/src/style/index.js +30 -0
- package/src/style/payment-instruments/content.js +8 -0
- package/src/style/payment-instruments/index.js +10 -0
- package/src/style/payment-instruments/payment-card.js +26 -0
- package/src/style/utils/color-values.js +9 -0
- package/src/style/vendor/framepay.js +25 -0
- package/src/style/vendor/postmate.js +8 -0
- package/src/style/views/confirmation.js +76 -0
- package/src/style/views/index.js +16 -0
- package/src/style/views/method-selector.js +11 -0
- package/src/style/views/modal.js +84 -0
- package/src/style/views/result.js +52 -0
- package/src/style/views/summary.js +114 -0
- package/src/utils/add-dom-element.js +12 -13
- package/src/utils/format-currency.js +4 -1
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/index.js +2 -6
- 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 +3 -0
- package/src/views/__snapshots__/summary.spec.js.snap +292 -0
- package/src/views/common/iframe/base-iframe.js +46 -0
- package/src/views/common/iframe/event-listeners.js +27 -0
- package/src/views/common/iframe/index.js +7 -0
- package/src/views/common/iframe/method-iframe.js +21 -0
- package/src/views/common/iframe/modal-iframe.js +27 -0
- package/src/views/common/iframe/view-iframe.js +18 -0
- package/src/views/common/render-utilities.js +4 -0
- package/src/views/confirmation.js +57 -0
- package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
- package/src/views/method-selector/express-methods/apple-pay.js +78 -0
- package/src/views/method-selector/express-methods/google-pay.js +25 -0
- package/src/views/method-selector/express-methods/paypal.js +7 -0
- package/src/views/method-selector/generate-digital-wallet.js +44 -0
- package/src/views/method-selector/generate-digital-wallet.spec.js +131 -0
- package/src/{components/form → views/method-selector}/get-method-data.js +9 -5
- package/src/views/method-selector/get-payment-methods.js +40 -0
- package/src/views/method-selector/get-payment-methods.spec.js +40 -0
- package/src/views/method-selector/index.js +110 -0
- package/src/views/method-selector/method-selector.spec.js +146 -0
- package/src/views/method-selector/mount-express-methods.js +53 -0
- package/src/views/method-selector/mount-methods.js +71 -0
- package/src/views/modal.js +84 -0
- package/src/views/result.js +30 -0
- package/src/{components → views}/summary.js +90 -21
- package/src/views/summary.spec.js +170 -0
- package/tests/async-utilities.js +22 -0
- package/tests/mocks/rebilly-instruments-mock.js +105 -7
- package/dist/components/confirmation.js +0 -103
- package/dist/components/form/form.js +0 -110
- package/dist/components/form/form.spec.js +0 -135
- package/dist/components/form/get-method-data.js +0 -21
- package/dist/components/form/get-payment-methods.js +0 -42
- package/dist/components/form/method-selector.js +0 -61
- package/dist/components/form/mount-express-payment-methods.js +0 -102
- package/dist/components/form/process-digital-wallet-options.js +0 -20
- package/dist/components/form/zoid-helpers.js +0 -130
- package/dist/components/result.js +0 -66
- package/dist/components/summary.js +0 -60
- package/dist/components/summary.spec.js +0 -144
- package/dist/events/instrument-ready.js +0 -51
- package/dist/events/purchase-complete.js +0 -51
- package/dist/functions/mount.js +0 -311
- package/dist/functions/mount.spec.js +0 -203
- package/dist/styles/base-styles.js +0 -12
- package/dist/styles/flat-theme-object.js +0 -42
- package/dist/styles/framepay.js +0 -15
- package/dist/styles/main.js +0 -25
- package/dist/styles/payment-card.js +0 -12
- package/dist/styles/shade-tint-values-helper.js +0 -28
- package/dist/styles/style-variables.js +0 -43
- package/dist/utils/camel-case.js +0 -12
- package/dist/utils/kebab-case.js +0 -10
- package/dist/utils/un-kebab-case.js +0 -10
- package/src/components/confirmation.js +0 -77
- package/src/components/form/__snapshots__/form.spec.js.snap +0 -43
- package/src/components/form/form.js +0 -88
- package/src/components/form/form.spec.js +0 -109
- package/src/components/form/get-payment-methods.js +0 -32
- package/src/components/form/method-selector.js +0 -47
- package/src/components/form/mount-express-payment-methods.js +0 -84
- package/src/components/form/process-digital-wallet-options.js +0 -11
- package/src/components/form/zoid-helpers.js +0 -114
- package/src/components/result.js +0 -50
- package/src/components/summary.spec.js +0 -106
- package/src/events/instrument-ready.js +0 -11
- package/src/events/purchase-complete.js +0 -11
- package/src/functions/mount.js +0 -204
- package/src/functions/mount.spec.js +0 -172
- package/src/styles/base-styles.js +0 -741
- package/src/styles/flat-theme-object.js +0 -12
- package/src/styles/framepay.js +0 -30
- package/src/styles/main.js +0 -17
- package/src/styles/payment-card.js +0 -18
- package/src/styles/shade-tint-values-helper.js +0 -13
- package/src/styles/style-variables.js +0 -34
- package/src/utils/camel-case.js +0 -3
- package/src/utils/kebab-case.js +0 -3
- package/src/utils/un-kebab-case.js +0 -3
|
@@ -1,181 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _storefrontMock = require("tests/mocks/storefront-mock");
|
|
3
|
+
var _storefrontMock = require("../../tests/mocks/storefront-mock");
|
|
4
4
|
|
|
5
5
|
var _mswWhenThen = require("msw-when-then");
|
|
6
6
|
|
|
7
|
-
var _server = require("tests/msw/server");
|
|
7
|
+
var _server = require("../../tests/msw/server");
|
|
8
8
|
|
|
9
|
-
var _storefrontApiMock = require("tests/mocks/storefront-api-mock");
|
|
9
|
+
var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
|
|
10
10
|
|
|
11
11
|
var _plans = require("./plans");
|
|
12
12
|
|
|
13
13
|
var _planModel = _interopRequireDefault(require("./models/plan-model"));
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
var _asyncUtilities = require("../../tests/async-utilities");
|
|
16
16
|
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
20
|
-
|
|
21
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
22
|
-
|
|
23
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
24
|
-
|
|
25
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
26
|
-
|
|
27
|
-
describe('Storefront API Plan', function () {
|
|
28
|
-
var TestPlansInstance = /*#__PURE__*/function () {
|
|
29
|
-
function TestPlansInstance() {
|
|
30
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
31
|
-
_ref$configs = _ref.configs,
|
|
32
|
-
configs = _ref$configs === void 0 ? {} : _ref$configs,
|
|
33
|
-
_ref$options = _ref.options,
|
|
34
|
-
options = _ref$options === void 0 ? {} : _ref$options;
|
|
35
|
-
|
|
36
|
-
_classCallCheck(this, TestPlansInstance);
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
18
|
|
|
19
|
+
describe('Storefront API Plan', () => {
|
|
20
|
+
class TestPlansInstance {
|
|
21
|
+
constructor({
|
|
22
|
+
configs = {},
|
|
23
|
+
options = {}
|
|
24
|
+
} = {}) {
|
|
38
25
|
this.configs = configs;
|
|
39
26
|
this.options = options;
|
|
40
27
|
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
41
28
|
}
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
expect(instance.storefront.plans.getAll).toBeCalledTimes(1);
|
|
76
|
-
expect(instance.storefront.plans.getAll).toBeCalledWith({
|
|
77
|
-
filter: ''
|
|
78
|
-
});
|
|
79
|
-
expect(response).toBeInstanceOf(Array);
|
|
80
|
-
expect(response[0]).toBeInstanceOf(_planModel["default"]);
|
|
81
|
-
expect(response).toEqual([new _planModel["default"](testPlan)]);
|
|
82
|
-
|
|
83
|
-
case 12:
|
|
84
|
-
case "end":
|
|
85
|
-
return _context.stop();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}, _callee);
|
|
89
|
-
})));
|
|
90
|
-
it('can fetch plans with filter', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
91
|
-
var instance;
|
|
92
|
-
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
93
|
-
while (1) {
|
|
94
|
-
switch (_context2.prev = _context2.next) {
|
|
95
|
-
case 0:
|
|
96
|
-
instance = new TestPlansInstance();
|
|
97
|
-
jest.spyOn(instance.storefront.plans, 'getAll');
|
|
98
|
-
_context2.next = 4;
|
|
99
|
-
return instance.fetchPlans({
|
|
100
|
-
data: {
|
|
101
|
-
lineItems: [{
|
|
102
|
-
planId: 'test-plan-id-1'
|
|
103
|
-
}, {
|
|
104
|
-
planId: 'test-plan-id-2'
|
|
105
|
-
}]
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
case 4:
|
|
110
|
-
expect(instance.storefront.plans.getAll).toBeCalledWith({
|
|
111
|
-
filter: 'id:test-plan-id-1,test-plan-id-2'
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
case 5:
|
|
115
|
-
case "end":
|
|
116
|
-
return _context2.stop();
|
|
117
|
-
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
it('can fetch plans', async () => {
|
|
33
|
+
const testPlan = {
|
|
34
|
+
name: 'Test Plan',
|
|
35
|
+
id: 'test-plan-id-1'
|
|
36
|
+
};
|
|
37
|
+
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/plans`)).thenReturn((0, _mswWhenThen.ok)([testPlan]));
|
|
38
|
+
const instance = new TestPlansInstance();
|
|
39
|
+
jest.spyOn(instance.storefront.plans, 'getAll');
|
|
40
|
+
const response = await (0, _plans.fetchPlans)({
|
|
41
|
+
state: instance
|
|
42
|
+
});
|
|
43
|
+
expect(instance.storefront.plans.getAll).toBeCalledTimes(1);
|
|
44
|
+
expect(instance.storefront.plans.getAll).toBeCalledWith({
|
|
45
|
+
filter: ''
|
|
46
|
+
});
|
|
47
|
+
expect(response).toBeInstanceOf(Array);
|
|
48
|
+
expect(response[0]).toBeInstanceOf(_planModel.default);
|
|
49
|
+
expect(response).toEqual([new _planModel.default(testPlan)]);
|
|
50
|
+
});
|
|
51
|
+
it('can fetch plans with filter', async () => {
|
|
52
|
+
const instance = new TestPlansInstance();
|
|
53
|
+
jest.spyOn(instance.storefront.plans, 'getAll');
|
|
54
|
+
await (0, _plans.fetchPlans)({
|
|
55
|
+
state: instance,
|
|
56
|
+
data: {
|
|
57
|
+
lineItems: [{
|
|
58
|
+
planId: 'test-plan-id-1'
|
|
59
|
+
}, {
|
|
60
|
+
planId: 'test-plan-id-2'
|
|
61
|
+
}]
|
|
118
62
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
63
|
+
});
|
|
64
|
+
expect(instance.storefront.plans.getAll).toBeCalledWith({
|
|
65
|
+
filter: 'id:test-plan-id-1,test-plan-id-2'
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
it('should throw errors with no configs or options', async () => {
|
|
69
|
+
const noConfigOrOptionsInstance = new TestPlansInstance({
|
|
124
70
|
configs: null,
|
|
125
71
|
options: null
|
|
126
72
|
});
|
|
127
|
-
|
|
73
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _plans.fetchPlans)({
|
|
74
|
+
state: noConfigOrOptionsInstance
|
|
75
|
+
}));
|
|
76
|
+
const noConfigInstance = new TestPlansInstance({
|
|
128
77
|
configs: null,
|
|
129
78
|
options: {}
|
|
130
79
|
});
|
|
131
|
-
|
|
80
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _plans.fetchPlans)({
|
|
81
|
+
state: noConfigInstance
|
|
82
|
+
}));
|
|
83
|
+
const noOptionsInstance = new TestPlansInstance({
|
|
132
84
|
configs: {},
|
|
133
85
|
options: null
|
|
134
86
|
});
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
switch (_context3.prev = _context3.next) {
|
|
139
|
-
case 0:
|
|
140
|
-
_context3.next = 2;
|
|
141
|
-
return noConfigOrOptionsInstance.fetchPlans();
|
|
142
|
-
|
|
143
|
-
case 2:
|
|
144
|
-
case "end":
|
|
145
|
-
return _context3.stop();
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}, _callee3);
|
|
149
|
-
}))).rejects.toEqual(NoConfigOrOptionsError);
|
|
150
|
-
expect( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
151
|
-
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
152
|
-
while (1) {
|
|
153
|
-
switch (_context4.prev = _context4.next) {
|
|
154
|
-
case 0:
|
|
155
|
-
_context4.next = 2;
|
|
156
|
-
return noConfigInstance.fetchPlans();
|
|
157
|
-
|
|
158
|
-
case 2:
|
|
159
|
-
case "end":
|
|
160
|
-
return _context4.stop();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}, _callee4);
|
|
164
|
-
}))).rejects.toEqual(NoConfigOrOptionsError);
|
|
165
|
-
expect( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
166
|
-
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
167
|
-
while (1) {
|
|
168
|
-
switch (_context5.prev = _context5.next) {
|
|
169
|
-
case 0:
|
|
170
|
-
_context5.next = 2;
|
|
171
|
-
return noOptionsInstance.fetchPlans();
|
|
172
|
-
|
|
173
|
-
case 2:
|
|
174
|
-
case "end":
|
|
175
|
-
return _context5.stop();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}, _callee5);
|
|
179
|
-
}))).rejects.toEqual(NoConfigOrOptionsError);
|
|
87
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _plans.fetchPlans)({
|
|
88
|
+
state: noOptionsInstance
|
|
89
|
+
}));
|
|
180
90
|
});
|
|
181
91
|
});
|
|
@@ -3,89 +3,41 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.fetchProducts = fetchProducts;
|
|
7
7
|
|
|
8
8
|
var _productModel = _interopRequireDefault(require("./models/product-model"));
|
|
9
9
|
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : {
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
case 3:
|
|
45
|
-
if (!(!this.configs || !this.options)) {
|
|
46
|
-
_context.next = 5;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
51
|
-
|
|
52
|
-
case 5:
|
|
53
|
-
_context.prev = 5;
|
|
54
|
-
plansData = data || [];
|
|
55
|
-
filterByProductId = {
|
|
56
|
-
filter: ''
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
if (plansData.length) {
|
|
60
|
-
filterByProductId.filter = "id:".concat(plansData.map(function (item) {
|
|
61
|
-
return item.productId;
|
|
62
|
-
}).join(','));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
_context.next = 11;
|
|
66
|
-
return this.storefront.products.getAll(filterByProductId);
|
|
67
|
-
|
|
68
|
-
case 11:
|
|
69
|
-
_yield$this$storefron = _context.sent;
|
|
70
|
-
productItems = _yield$this$storefron.items;
|
|
71
|
-
return _context.abrupt("return", productItems.map(function (_ref2) {
|
|
72
|
-
var fields = _ref2.fields;
|
|
73
|
-
return new _productModel["default"](fields);
|
|
74
|
-
}));
|
|
75
|
-
|
|
76
|
-
case 16:
|
|
77
|
-
_context.prev = 16;
|
|
78
|
-
_context.t0 = _context["catch"](5);
|
|
79
|
-
throw _context.t0;
|
|
80
|
-
|
|
81
|
-
case 19:
|
|
82
|
-
case "end":
|
|
83
|
-
return _context.stop();
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}, _callee, this, [[5, 16]]);
|
|
87
|
-
}));
|
|
88
|
-
return _FetchProducts.apply(this, arguments);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
;
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
async function fetchProducts({
|
|
13
|
+
data = null,
|
|
14
|
+
state
|
|
15
|
+
}) {
|
|
16
|
+
if (!state.storefront) {
|
|
17
|
+
throw new Error('Could not access rebilly-js-sdk instance');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!state.configs || !state.options) {
|
|
21
|
+
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const plansData = data || [];
|
|
26
|
+
const filterByProductId = {
|
|
27
|
+
filter: ''
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
if (plansData.length) {
|
|
31
|
+
filterByProductId.filter = `id:${plansData.map(item => item.productId).join(',')}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
items: productItems
|
|
36
|
+
} = await state.storefront.products.getAll(filterByProductId);
|
|
37
|
+
return productItems.map(({
|
|
38
|
+
fields
|
|
39
|
+
}) => new _productModel.default(fields));
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,179 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _storefrontMock = require("tests/mocks/storefront-mock");
|
|
3
|
+
var _storefrontMock = require("../../tests/mocks/storefront-mock");
|
|
4
4
|
|
|
5
5
|
var _mswWhenThen = require("msw-when-then");
|
|
6
6
|
|
|
7
|
-
var _server = require("tests/msw/server");
|
|
7
|
+
var _server = require("../../tests/msw/server");
|
|
8
8
|
|
|
9
|
-
var _storefrontApiMock = require("tests/mocks/storefront-api-mock");
|
|
9
|
+
var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
|
|
10
10
|
|
|
11
11
|
var _products = require("./products");
|
|
12
12
|
|
|
13
13
|
var _productModel = _interopRequireDefault(require("./models/product-model"));
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
var _asyncUtilities = require("../../tests/async-utilities");
|
|
16
16
|
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
20
|
-
|
|
21
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
22
|
-
|
|
23
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
24
|
-
|
|
25
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
26
|
-
|
|
27
|
-
describe('Storefront API Plan', function () {
|
|
28
|
-
var TestProductsInstance = /*#__PURE__*/function () {
|
|
29
|
-
function TestProductsInstance() {
|
|
30
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
31
|
-
_ref$configs = _ref.configs,
|
|
32
|
-
configs = _ref$configs === void 0 ? {} : _ref$configs,
|
|
33
|
-
_ref$options = _ref.options,
|
|
34
|
-
options = _ref$options === void 0 ? {} : _ref$options;
|
|
35
|
-
|
|
36
|
-
_classCallCheck(this, TestProductsInstance);
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
18
|
|
|
19
|
+
describe('Storefront API Plan', () => {
|
|
20
|
+
class TestProductsInstance {
|
|
21
|
+
constructor({
|
|
22
|
+
configs = {},
|
|
23
|
+
options = {}
|
|
24
|
+
} = {}) {
|
|
38
25
|
this.configs = configs;
|
|
39
26
|
this.options = options;
|
|
40
27
|
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
41
28
|
}
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
expect(response).toEqual([new _productModel["default"](testProduct)]);
|
|
82
|
-
|
|
83
|
-
case 12:
|
|
84
|
-
case "end":
|
|
85
|
-
return _context.stop();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}, _callee);
|
|
89
|
-
})));
|
|
90
|
-
it('can fetch products with filter', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
91
|
-
var instance;
|
|
92
|
-
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
93
|
-
while (1) {
|
|
94
|
-
switch (_context2.prev = _context2.next) {
|
|
95
|
-
case 0:
|
|
96
|
-
instance = new TestProductsInstance();
|
|
97
|
-
jest.spyOn(instance.storefront.products, 'getAll');
|
|
98
|
-
_context2.next = 4;
|
|
99
|
-
return instance.FetchProducts({
|
|
100
|
-
data: [{
|
|
101
|
-
productId: 'test-product-1'
|
|
102
|
-
}, {
|
|
103
|
-
productId: 'test-product-2'
|
|
104
|
-
}]
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
case 4:
|
|
108
|
-
expect(instance.storefront.products.getAll).toBeCalledWith({
|
|
109
|
-
filter: 'id:test-product-1,test-product-2'
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
case 5:
|
|
113
|
-
case "end":
|
|
114
|
-
return _context2.stop();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}, _callee2);
|
|
118
|
-
})));
|
|
119
|
-
it('should throw errors with no configs or options', function () {
|
|
120
|
-
var NoConfigOrOptionsError = new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
121
|
-
var noConfigOrOptionsInstance = new TestProductsInstance({
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
it('can fetch products', async () => {
|
|
33
|
+
const testProduct = {
|
|
34
|
+
name: 'Test Product',
|
|
35
|
+
id: 'test-product-id-1'
|
|
36
|
+
};
|
|
37
|
+
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/products`)).thenReturn((0, _mswWhenThen.ok)([testProduct]));
|
|
38
|
+
const instance = new TestProductsInstance();
|
|
39
|
+
jest.spyOn(instance.storefront.products, 'getAll');
|
|
40
|
+
const response = await (0, _products.fetchProducts)({
|
|
41
|
+
state: instance
|
|
42
|
+
});
|
|
43
|
+
expect(instance.storefront.products.getAll).toBeCalledTimes(1);
|
|
44
|
+
expect(instance.storefront.products.getAll).toBeCalledWith({
|
|
45
|
+
filter: ''
|
|
46
|
+
});
|
|
47
|
+
expect(response).toBeInstanceOf(Array);
|
|
48
|
+
expect(response[0]).toBeInstanceOf(_productModel.default);
|
|
49
|
+
expect(response).toEqual([new _productModel.default(testProduct)]);
|
|
50
|
+
});
|
|
51
|
+
it('can fetch products with filter', async () => {
|
|
52
|
+
const instance = new TestProductsInstance();
|
|
53
|
+
jest.spyOn(instance.storefront.products, 'getAll');
|
|
54
|
+
await (0, _products.fetchProducts)({
|
|
55
|
+
state: instance,
|
|
56
|
+
data: [{
|
|
57
|
+
productId: 'test-product-1'
|
|
58
|
+
}, {
|
|
59
|
+
productId: 'test-product-2'
|
|
60
|
+
}]
|
|
61
|
+
});
|
|
62
|
+
expect(instance.storefront.products.getAll).toBeCalledWith({
|
|
63
|
+
filter: 'id:test-product-1,test-product-2'
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
it('should throw errors with no configs or options', async () => {
|
|
67
|
+
const noConfigOrOptionsInstance = new TestProductsInstance({
|
|
122
68
|
configs: null,
|
|
123
69
|
options: null
|
|
124
70
|
});
|
|
125
|
-
|
|
71
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _products.fetchProducts)({
|
|
72
|
+
state: noConfigOrOptionsInstance
|
|
73
|
+
}));
|
|
74
|
+
const noConfigInstance = new TestProductsInstance({
|
|
126
75
|
configs: null,
|
|
127
76
|
options: {}
|
|
128
77
|
});
|
|
129
|
-
|
|
78
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _products.fetchProducts)({
|
|
79
|
+
state: noConfigInstance
|
|
80
|
+
}));
|
|
81
|
+
const noOptionsInstance = new TestProductsInstance({
|
|
130
82
|
configs: {},
|
|
131
83
|
options: null
|
|
132
84
|
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
switch (_context3.prev = _context3.next) {
|
|
137
|
-
case 0:
|
|
138
|
-
_context3.next = 2;
|
|
139
|
-
return noConfigOrOptionsInstance.FetchProducts();
|
|
140
|
-
|
|
141
|
-
case 2:
|
|
142
|
-
case "end":
|
|
143
|
-
return _context3.stop();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}, _callee3);
|
|
147
|
-
}))).rejects.toEqual(NoConfigOrOptionsError);
|
|
148
|
-
expect( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
149
|
-
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
150
|
-
while (1) {
|
|
151
|
-
switch (_context4.prev = _context4.next) {
|
|
152
|
-
case 0:
|
|
153
|
-
_context4.next = 2;
|
|
154
|
-
return noConfigInstance.FetchProducts();
|
|
155
|
-
|
|
156
|
-
case 2:
|
|
157
|
-
case "end":
|
|
158
|
-
return _context4.stop();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}, _callee4);
|
|
162
|
-
}))).rejects.toEqual(NoConfigOrOptionsError);
|
|
163
|
-
expect( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
164
|
-
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
165
|
-
while (1) {
|
|
166
|
-
switch (_context5.prev = _context5.next) {
|
|
167
|
-
case 0:
|
|
168
|
-
_context5.next = 2;
|
|
169
|
-
return noOptionsInstance.FetchProducts();
|
|
170
|
-
|
|
171
|
-
case 2:
|
|
172
|
-
case "end":
|
|
173
|
-
return _context5.stop();
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}, _callee5);
|
|
177
|
-
}))).rejects.toEqual(NoConfigOrOptionsError);
|
|
85
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _products.fetchProducts)({
|
|
86
|
+
state: noOptionsInstance
|
|
87
|
+
}));
|
|
178
88
|
});
|
|
179
89
|
});
|