@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.
Files changed (277) hide show
  1. package/.babelrc +23 -5
  2. package/.eslintrc.js +27 -0
  3. package/.prettierrc.js +11 -0
  4. package/CONTRIBUTING.md +4 -0
  5. package/README.md +361 -2
  6. package/dist/events/base-event.js +51 -37
  7. package/dist/events/events.spec.js +18 -0
  8. package/dist/events/index.js +11 -8
  9. package/dist/functions/destroy.js +27 -5
  10. package/dist/functions/destroy.spec.js +69 -0
  11. package/dist/functions/initialize.js +60 -41
  12. package/dist/functions/initialize.spec.js +13 -13
  13. package/dist/functions/mount/fetch-summary-data.js +46 -0
  14. package/dist/functions/mount/fetch-summary-data.spec.js +44 -0
  15. package/dist/functions/mount/index.js +346 -0
  16. package/dist/functions/mount/mount.spec.js +135 -0
  17. package/dist/functions/on.js +26 -18
  18. package/dist/functions/on.spec.js +45 -63
  19. package/dist/functions/purchase.js +41 -154
  20. package/dist/functions/purchase.spec.js +60 -76
  21. package/dist/functions/show.js +39 -43
  22. package/dist/functions/show.spec.js +57 -0
  23. package/dist/functions/update.js +60 -5
  24. package/dist/functions/update.spec.js +100 -0
  25. package/dist/i18n/en.json +19 -0
  26. package/dist/i18n/es.json +19 -0
  27. package/dist/i18n/i18n.spec.js +6 -23
  28. package/dist/i18n/index.js +44 -67
  29. package/dist/index.js +70 -71
  30. package/dist/index.spec.js +24 -44
  31. package/dist/loader/index.js +63 -62
  32. package/dist/loader/loader.spec.js +14 -11
  33. package/dist/storefront/index.js +28 -39
  34. package/dist/storefront/models/plan-model.js +37 -54
  35. package/dist/storefront/models/product-model.js +25 -36
  36. package/dist/storefront/models/ready-to-pay-model.js +38 -42
  37. package/dist/storefront/models/summary-model.js +72 -99
  38. package/dist/storefront/plans.js +37 -84
  39. package/dist/storefront/plans.spec.js +61 -151
  40. package/dist/storefront/products.js +35 -83
  41. package/dist/storefront/products.spec.js +60 -150
  42. package/dist/storefront/purchase.js +27 -64
  43. package/dist/storefront/purchase.spec.js +51 -87
  44. package/dist/storefront/ready-to-pay.js +45 -107
  45. package/dist/storefront/ready-to-pay.spec.js +72 -147
  46. package/dist/storefront/storefront.spec.js +6 -6
  47. package/dist/storefront/summary.js +37 -84
  48. package/dist/storefront/summary.spec.js +135 -240
  49. package/dist/style/base/__snapshots__/theme.spec.js.snap +52 -0
  50. package/dist/style/base/index.js +72 -0
  51. package/dist/style/base/theme.js +73 -0
  52. package/dist/style/base/theme.spec.js +30 -0
  53. package/dist/style/browserslist.js +8 -0
  54. package/dist/style/components/address.js +64 -0
  55. package/dist/style/components/button.js +61 -0
  56. package/dist/style/components/divider.js +48 -0
  57. package/dist/style/components/forms/checkbox.js +83 -0
  58. package/dist/style/components/forms/field.js +53 -0
  59. package/dist/style/components/forms/form.js +28 -0
  60. package/dist/style/components/forms/input.js +45 -0
  61. package/dist/style/components/forms/label.js +43 -0
  62. package/dist/style/components/forms/select.js +63 -0
  63. package/dist/style/components/forms/validation.js +34 -0
  64. package/dist/style/components/icons.js +22 -0
  65. package/dist/style/components/index.js +57 -0
  66. package/dist/style/components/loader.js +48 -0
  67. package/dist/style/components/methods.js +104 -0
  68. package/dist/style/components/overlay.js +33 -0
  69. package/dist/style/helpers/index.js +59 -0
  70. package/dist/style/index.js +48 -0
  71. package/dist/style/payment-instruments/content.js +17 -0
  72. package/dist/style/payment-instruments/index.js +20 -0
  73. package/dist/style/payment-instruments/payment-card.js +35 -0
  74. package/dist/style/utils/color-values.js +22 -0
  75. package/dist/style/vendor/framepay.js +34 -0
  76. package/dist/style/vendor/postmate.js +17 -0
  77. package/dist/style/views/confirmation.js +85 -0
  78. package/dist/style/views/index.js +29 -0
  79. package/dist/style/views/method-selector.js +20 -0
  80. package/dist/style/views/modal.js +93 -0
  81. package/dist/style/views/result.js +61 -0
  82. package/dist/style/views/summary.js +123 -0
  83. package/dist/utils/add-dom-element.js +12 -34
  84. package/dist/utils/format-currency.js +4 -4
  85. package/dist/utils/has-valid-css-selector.js +2 -2
  86. package/dist/utils/index.js +15 -31
  87. package/dist/utils/is-dom-element.js +1 -1
  88. package/dist/utils/process-property-as-dom-element.js +12 -17
  89. package/dist/utils/sleep.js +10 -0
  90. package/{src/components → dist/views}/__snapshots__/summary.spec.js.snap +7 -3
  91. package/dist/views/common/iframe/base-iframe.js +57 -0
  92. package/dist/views/common/iframe/event-listeners.js +50 -0
  93. package/dist/views/common/iframe/index.js +19 -0
  94. package/dist/views/common/iframe/method-iframe.js +33 -0
  95. package/dist/views/common/iframe/modal-iframe.js +38 -0
  96. package/dist/views/common/iframe/view-iframe.js +31 -0
  97. package/dist/views/common/render-utilities.js +11 -0
  98. package/dist/views/confirmation.js +82 -0
  99. package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
  100. package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
  101. package/dist/views/method-selector/express-methods/google-pay.js +32 -0
  102. package/dist/views/method-selector/express-methods/paypal.js +19 -0
  103. package/dist/views/method-selector/generate-digital-wallet.js +59 -0
  104. package/dist/views/method-selector/generate-digital-wallet.spec.js +132 -0
  105. package/dist/views/method-selector/get-method-data.js +25 -0
  106. package/dist/views/method-selector/get-payment-methods.js +55 -0
  107. package/dist/views/method-selector/get-payment-methods.spec.js +44 -0
  108. package/dist/views/method-selector/index.js +133 -0
  109. package/dist/views/method-selector/method-selector.spec.js +139 -0
  110. package/dist/views/method-selector/mount-express-methods.js +69 -0
  111. package/dist/views/method-selector/mount-methods.js +78 -0
  112. package/dist/views/modal.js +83 -0
  113. package/dist/views/result.js +42 -0
  114. package/dist/views/summary.js +162 -0
  115. package/dist/views/summary.spec.js +148 -0
  116. package/package.json +12 -6
  117. package/src/events/base-event.js +35 -12
  118. package/src/events/events.spec.js +11 -0
  119. package/src/events/index.js +12 -6
  120. package/src/functions/destroy.js +22 -3
  121. package/src/functions/destroy.spec.js +63 -0
  122. package/src/functions/initialize.js +43 -20
  123. package/src/functions/initialize.spec.js +9 -7
  124. package/src/functions/mount/fetch-summary-data.js +29 -0
  125. package/src/functions/mount/fetch-summary-data.spec.js +41 -0
  126. package/src/functions/mount/index.js +312 -0
  127. package/src/functions/mount/mount.spec.js +171 -0
  128. package/src/functions/on.js +17 -14
  129. package/src/functions/on.spec.js +39 -29
  130. package/src/functions/purchase.js +24 -64
  131. package/src/functions/purchase.spec.js +19 -17
  132. package/src/functions/show.js +27 -7
  133. package/src/functions/show.spec.js +61 -0
  134. package/src/functions/update.js +50 -3
  135. package/src/functions/update.spec.js +107 -0
  136. package/src/i18n/i18n.spec.js +6 -4
  137. package/src/i18n/index.js +20 -12
  138. package/src/index.js +43 -49
  139. package/src/index.spec.js +11 -42
  140. package/src/loader/index.js +55 -39
  141. package/src/loader/loader.spec.js +30 -23
  142. package/src/storefront/index.js +9 -7
  143. package/src/storefront/models/plan-model.js +1 -1
  144. package/src/storefront/models/product-model.js +1 -1
  145. package/src/storefront/models/ready-to-pay-model.js +10 -4
  146. package/src/storefront/models/summary-model.js +8 -15
  147. package/src/storefront/plans.js +16 -12
  148. package/src/storefront/plans.spec.js +29 -37
  149. package/src/storefront/products.js +16 -12
  150. package/src/storefront/products.spec.js +28 -39
  151. package/src/storefront/purchase.js +8 -6
  152. package/src/storefront/purchase.spec.js +18 -17
  153. package/src/storefront/ready-to-pay.js +19 -13
  154. package/src/storefront/ready-to-pay.spec.js +41 -41
  155. package/src/storefront/storefront.spec.js +1 -1
  156. package/src/storefront/summary.js +14 -12
  157. package/src/storefront/summary.spec.js +37 -50
  158. package/src/style/base/__snapshots__/theme.spec.js.snap +52 -0
  159. package/src/style/base/index.js +63 -0
  160. package/src/style/base/theme.js +61 -0
  161. package/src/style/base/theme.spec.js +32 -0
  162. package/src/style/browserslist.js +1 -0
  163. package/src/style/components/address.js +55 -0
  164. package/src/style/components/button.js +54 -0
  165. package/src/style/components/divider.js +39 -0
  166. package/src/style/components/forms/checkbox.js +76 -0
  167. package/src/style/components/forms/field.js +44 -0
  168. package/src/style/components/forms/form.js +19 -0
  169. package/src/style/components/forms/input.js +36 -0
  170. package/src/style/components/forms/label.js +34 -0
  171. package/src/style/components/forms/select.js +54 -0
  172. package/src/style/components/forms/validation.js +25 -0
  173. package/src/style/components/icons.js +13 -0
  174. package/src/style/components/index.js +35 -0
  175. package/src/style/components/loader.js +41 -0
  176. package/src/style/components/methods.js +93 -0
  177. package/src/style/components/overlay.js +24 -0
  178. package/src/style/helpers/index.js +51 -0
  179. package/src/style/index.js +30 -0
  180. package/src/style/payment-instruments/content.js +8 -0
  181. package/src/style/payment-instruments/index.js +10 -0
  182. package/src/style/payment-instruments/payment-card.js +26 -0
  183. package/src/style/utils/color-values.js +9 -0
  184. package/src/style/vendor/framepay.js +25 -0
  185. package/src/style/vendor/postmate.js +8 -0
  186. package/src/style/views/confirmation.js +76 -0
  187. package/src/style/views/index.js +16 -0
  188. package/src/style/views/method-selector.js +11 -0
  189. package/src/style/views/modal.js +84 -0
  190. package/src/style/views/result.js +52 -0
  191. package/src/style/views/summary.js +114 -0
  192. package/src/utils/add-dom-element.js +12 -13
  193. package/src/utils/format-currency.js +4 -1
  194. package/src/utils/has-valid-css-selector.js +2 -2
  195. package/src/utils/index.js +2 -6
  196. package/src/utils/is-dom-element.js +1 -1
  197. package/src/utils/process-property-as-dom-element.js +27 -24
  198. package/src/utils/sleep.js +3 -0
  199. package/src/views/__snapshots__/summary.spec.js.snap +292 -0
  200. package/src/views/common/iframe/base-iframe.js +46 -0
  201. package/src/views/common/iframe/event-listeners.js +27 -0
  202. package/src/views/common/iframe/index.js +7 -0
  203. package/src/views/common/iframe/method-iframe.js +21 -0
  204. package/src/views/common/iframe/modal-iframe.js +27 -0
  205. package/src/views/common/iframe/view-iframe.js +18 -0
  206. package/src/views/common/render-utilities.js +4 -0
  207. package/src/views/confirmation.js +57 -0
  208. package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
  209. package/src/views/method-selector/express-methods/apple-pay.js +78 -0
  210. package/src/views/method-selector/express-methods/google-pay.js +25 -0
  211. package/src/views/method-selector/express-methods/paypal.js +7 -0
  212. package/src/views/method-selector/generate-digital-wallet.js +44 -0
  213. package/src/views/method-selector/generate-digital-wallet.spec.js +131 -0
  214. package/src/{components/form → views/method-selector}/get-method-data.js +9 -5
  215. package/src/views/method-selector/get-payment-methods.js +40 -0
  216. package/src/views/method-selector/get-payment-methods.spec.js +40 -0
  217. package/src/views/method-selector/index.js +110 -0
  218. package/src/views/method-selector/method-selector.spec.js +146 -0
  219. package/src/views/method-selector/mount-express-methods.js +53 -0
  220. package/src/views/method-selector/mount-methods.js +71 -0
  221. package/src/views/modal.js +84 -0
  222. package/src/views/result.js +30 -0
  223. package/src/{components → views}/summary.js +90 -21
  224. package/src/views/summary.spec.js +170 -0
  225. package/tests/async-utilities.js +22 -0
  226. package/tests/mocks/rebilly-instruments-mock.js +105 -7
  227. package/dist/components/confirmation.js +0 -103
  228. package/dist/components/form/form.js +0 -110
  229. package/dist/components/form/form.spec.js +0 -135
  230. package/dist/components/form/get-method-data.js +0 -21
  231. package/dist/components/form/get-payment-methods.js +0 -42
  232. package/dist/components/form/method-selector.js +0 -61
  233. package/dist/components/form/mount-express-payment-methods.js +0 -102
  234. package/dist/components/form/process-digital-wallet-options.js +0 -20
  235. package/dist/components/form/zoid-helpers.js +0 -130
  236. package/dist/components/result.js +0 -66
  237. package/dist/components/summary.js +0 -60
  238. package/dist/components/summary.spec.js +0 -144
  239. package/dist/events/instrument-ready.js +0 -51
  240. package/dist/events/purchase-complete.js +0 -51
  241. package/dist/functions/mount.js +0 -311
  242. package/dist/functions/mount.spec.js +0 -203
  243. package/dist/styles/base-styles.js +0 -12
  244. package/dist/styles/flat-theme-object.js +0 -42
  245. package/dist/styles/framepay.js +0 -15
  246. package/dist/styles/main.js +0 -25
  247. package/dist/styles/payment-card.js +0 -12
  248. package/dist/styles/shade-tint-values-helper.js +0 -28
  249. package/dist/styles/style-variables.js +0 -43
  250. package/dist/utils/camel-case.js +0 -12
  251. package/dist/utils/kebab-case.js +0 -10
  252. package/dist/utils/un-kebab-case.js +0 -10
  253. package/src/components/confirmation.js +0 -77
  254. package/src/components/form/__snapshots__/form.spec.js.snap +0 -43
  255. package/src/components/form/form.js +0 -88
  256. package/src/components/form/form.spec.js +0 -109
  257. package/src/components/form/get-payment-methods.js +0 -32
  258. package/src/components/form/method-selector.js +0 -47
  259. package/src/components/form/mount-express-payment-methods.js +0 -84
  260. package/src/components/form/process-digital-wallet-options.js +0 -11
  261. package/src/components/form/zoid-helpers.js +0 -114
  262. package/src/components/result.js +0 -50
  263. package/src/components/summary.spec.js +0 -106
  264. package/src/events/instrument-ready.js +0 -11
  265. package/src/events/purchase-complete.js +0 -11
  266. package/src/functions/mount.js +0 -204
  267. package/src/functions/mount.spec.js +0 -172
  268. package/src/styles/base-styles.js +0 -741
  269. package/src/styles/flat-theme-object.js +0 -12
  270. package/src/styles/framepay.js +0 -30
  271. package/src/styles/main.js +0 -17
  272. package/src/styles/payment-card.js +0 -18
  273. package/src/styles/shade-tint-values-helper.js +0 -13
  274. package/src/styles/style-variables.js +0 -34
  275. package/src/utils/camel-case.js +0 -3
  276. package/src/utils/kebab-case.js +0 -3
  277. package/src/utils/un-kebab-case.js +0 -3
@@ -1,14 +1,14 @@
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
- describe('Storefront application programming interface', function () {
6
- it('can create rebilly-js-sdk instance', function () {
7
- var storefront = (0, _storefrontMock.MockStorefront)();
5
+ describe('Storefront application programming interface', () => {
6
+ it('can create rebilly-js-sdk instance', () => {
7
+ const storefront = (0, _storefrontMock.MockStorefront)();
8
8
  expect(storefront).toHaveProperty('setPublishableKey');
9
9
  });
10
- it('has required endpoints', function () {
11
- var storefront = (0, _storefrontMock.MockStorefront)();
10
+ it('has required endpoints', () => {
11
+ const storefront = (0, _storefrontMock.MockStorefront)();
12
12
  expect(storefront).toHaveProperty('purchase');
13
13
  expect(storefront.purchase).toHaveProperty('readyToPay');
14
14
  });
@@ -3,96 +3,49 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.FetchSummary = FetchSummary;
6
+ exports.fetchSummary = fetchSummary;
7
7
 
8
8
  var _summaryModel = _interopRequireDefault(require("./models/summary-model"));
9
9
 
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
 
12
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
12
+ async function fetchSummary({
13
+ data = null,
14
+ state = null
15
+ } = {}) {
16
+ if (!state.storefront) {
17
+ throw new Error('Could not access rebilly-js-sdk instance');
18
+ }
13
19
 
14
- 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
+ if (!state.configs || !state.options) {
21
+ throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
22
+ }
15
23
 
16
- function FetchSummary() {
17
- return _FetchSummary.apply(this, arguments);
18
- }
24
+ try {
25
+ var _state$configs, _state$options, _state$options$intent;
19
26
 
20
- function _FetchSummary() {
21
- _FetchSummary = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
22
- var _ref,
23
- _ref$data,
24
- data,
25
- _this$configs,
26
- _this$options,
27
- _this$options$intent,
27
+ const websiteId = ((_state$configs = state.configs) === null || _state$configs === void 0 ? void 0 : _state$configs.websiteId) || null;
28
+ const items = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : (_state$options$intent = _state$options.intent) === null || _state$options$intent === void 0 ? void 0 : _state$options$intent.items) || [];
29
+ const payload = {
30
+ data: {
28
31
  websiteId,
29
- items,
30
- payload,
31
- _yield$this$storefron,
32
- summaryFields,
33
- _args = arguments;
34
-
35
- return regeneratorRuntime.wrap(function _callee$(_context) {
36
- while (1) {
37
- switch (_context.prev = _context.next) {
38
- case 0:
39
- _ref = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, _ref$data = _ref.data, data = _ref$data === void 0 ? null : _ref$data;
40
-
41
- if (this.storefront) {
42
- _context.next = 3;
43
- break;
44
- }
45
-
46
- throw new Error('Could not access rebilly-js-sdk instance');
47
-
48
- case 3:
49
- if (!(!this.configs || !this.options)) {
50
- _context.next = 5;
51
- break;
52
- }
53
-
54
- throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
55
-
56
- case 5:
57
- _context.prev = 5;
58
- websiteId = ((_this$configs = this.configs) === null || _this$configs === void 0 ? void 0 : _this$configs.websiteId) || null;
59
- items = ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : (_this$options$intent = _this$options.intent) === null || _this$options$intent === void 0 ? void 0 : _this$options$intent.items) || [];
60
- payload = {
61
- data: {
62
- websiteId: websiteId,
63
- items: items
64
- }
65
- };
66
-
67
- if (data !== null && data !== void 0 && data.billingAddress) {
68
- payload.data.billingAddress = data.billingAddress;
69
- }
70
-
71
- if (data !== null && data !== void 0 && data.deliveryAddress) {
72
- payload.data.deliveryAddress = data.deliveryAddress;
73
- }
74
-
75
- _context.next = 13;
76
- return this.storefront.purchase.preview(payload);
77
-
78
- case 13:
79
- _yield$this$storefron = _context.sent;
80
- summaryFields = _yield$this$storefron.fields;
81
- return _context.abrupt("return", new _summaryModel["default"](summaryFields));
82
-
83
- case 18:
84
- _context.prev = 18;
85
- _context.t0 = _context["catch"](5);
86
- throw _context.t0;
87
-
88
- case 21:
89
- case "end":
90
- return _context.stop();
91
- }
32
+ items
92
33
  }
93
- }, _callee, this, [[5, 18]]);
94
- }));
95
- return _FetchSummary.apply(this, arguments);
96
- }
97
-
98
- ;
34
+ };
35
+
36
+ if (data !== null && data !== void 0 && data.billingAddress) {
37
+ payload.data.billingAddress = data.billingAddress;
38
+ }
39
+
40
+ if (data !== null && data !== void 0 && data.deliveryAddress) {
41
+ payload.data.deliveryAddress = data.deliveryAddress;
42
+ }
43
+
44
+ const {
45
+ fields: summaryFields
46
+ } = await state.storefront.purchase.preview(payload);
47
+ return new _summaryModel.default(summaryFields);
48
+ } catch (error) {
49
+ throw error;
50
+ }
51
+ }
@@ -1,272 +1,167 @@
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 _summary = require("./summary");
12
12
 
13
- var _summaryModel = _interopRequireDefault(require("@/storefront/models/summary-model"));
13
+ var _summaryModel = _interopRequireDefault(require("./models/summary-model"));
14
14
 
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+ var _asyncUtilities = require("../../tests/async-utilities");
16
16
 
17
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
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 Summary', function () {
28
- var TestSummaryInstance = /*#__PURE__*/function () {
29
- function TestSummaryInstance() {
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
- _ref$storefront = _ref.storefront,
36
- storefront = _ref$storefront === void 0 ? null : _ref$storefront;
37
-
38
- _classCallCheck(this, TestSummaryInstance);
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
18
 
19
+ describe('Storefront API Summary', () => {
20
+ class TestSummaryInstance {
21
+ constructor({
22
+ configs = {},
23
+ options = {},
24
+ storefront = null
25
+ } = {}) {
40
26
  this.configs = configs;
41
27
  this.options = options;
42
28
  this.storefront = storefront === null ? (0, _storefrontMock.MockStorefront)() : storefront;
43
29
  }
44
30
 
45
- _createClass(TestSummaryInstance, [{
46
- key: "fetchSummary",
47
- value: function fetchSummary() {
48
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
49
- args[_key] = arguments[_key];
50
- }
51
-
52
- return _summary.FetchSummary.apply(this, args);
31
+ }
32
+
33
+ it('can fetch preview', async () => {
34
+ const configs = {
35
+ websiteId: 'test-website-id'
36
+ };
37
+ const options = {
38
+ intent: {
39
+ items: [{
40
+ planId: 'test-plan-id',
41
+ quantity: 1
42
+ }]
53
43
  }
54
- }]);
55
-
56
- return TestSummaryInstance;
57
- }();
58
-
59
- it('can fetch preview', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
60
- var configs, options, testSummary, instance, response;
61
- return regeneratorRuntime.wrap(function _callee$(_context) {
62
- while (1) {
63
- switch (_context.prev = _context.next) {
64
- case 0:
65
- configs = {
66
- websiteId: 'test-website-id'
67
- };
68
- options = {
69
- intent: {
70
- items: [{
71
- planId: 'test-plan-id',
72
- quantity: 1
73
- }]
74
- }
75
- };
76
- testSummary = {
77
- currency: 'USD',
78
- lineItems: [{
79
- description: 'test-plan-id-1',
80
- planId: 'test-plan-id-1',
81
- quantity: 1
82
- }]
83
- };
84
- (0, _server.when)((0, _mswWhenThen.post)("".concat(_storefrontApiMock.storefrontURL, "/preview-purchase"))).thenReturn((0, _mswWhenThen.ok)(testSummary));
85
- instance = new TestSummaryInstance({
86
- configs: configs,
87
- options: options
88
- });
89
- jest.spyOn(instance.storefront.purchase, 'preview');
90
- _context.next = 8;
91
- return instance.fetchSummary();
92
-
93
- case 8:
94
- response = _context.sent;
95
- expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
96
- expect(instance.storefront.purchase.preview).toBeCalledWith({
97
- data: {
98
- items: options.intent.items,
99
- websiteId: configs.websiteId
100
- }
101
- });
102
- expect(response).toBeInstanceOf(_summaryModel["default"]);
103
- expect(response).toEqual(new _summaryModel["default"](testSummary));
104
-
105
- case 13:
106
- case "end":
107
- return _context.stop();
108
- }
44
+ };
45
+ const testSummary = {
46
+ currency: 'USD',
47
+ lineItems: [{
48
+ description: 'test-plan-id-1',
49
+ planId: 'test-plan-id-1',
50
+ quantity: 1
51
+ }]
52
+ };
53
+ (0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/preview-purchase`)).thenReturn((0, _mswWhenThen.ok)(testSummary));
54
+ const instance = new TestSummaryInstance({
55
+ configs,
56
+ options
57
+ });
58
+ jest.spyOn(instance.storefront.purchase, 'preview');
59
+ const response = await (0, _summary.fetchSummary)({
60
+ state: instance
61
+ });
62
+ expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
63
+ expect(instance.storefront.purchase.preview).toBeCalledWith({
64
+ data: {
65
+ items: options.intent.items,
66
+ websiteId: configs.websiteId
109
67
  }
110
- }, _callee);
111
- })));
112
- it('Adds billing address to preview payload', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
113
- var configs, options, billingAddress, instance;
114
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
115
- while (1) {
116
- switch (_context2.prev = _context2.next) {
117
- case 0:
118
- configs = {
119
- websiteId: 'test-website-id'
120
- };
121
- options = {
122
- intent: {
123
- items: [{
124
- planId: 'test-plan-id',
125
- quantity: 1
126
- }]
127
- }
128
- };
129
- billingAddress = {
130
- firstName: 'Test',
131
- lastName: 'Customer'
132
- };
133
- instance = new TestSummaryInstance({
134
- configs: configs,
135
- options: options
136
- });
137
- jest.spyOn(instance.storefront.purchase, 'preview');
138
- _context2.next = 7;
139
- return instance.fetchSummary({
140
- data: {
141
- billingAddress: billingAddress
142
- }
143
- });
144
-
145
- case 7:
146
- expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
147
- expect(instance.storefront.purchase.preview).toBeCalledWith({
148
- data: {
149
- items: options.intent.items,
150
- websiteId: configs.websiteId,
151
- billingAddress: billingAddress
152
- }
153
- });
154
-
155
- case 9:
156
- case "end":
157
- return _context2.stop();
158
- }
68
+ });
69
+ expect(response).toBeInstanceOf(_summaryModel.default);
70
+ expect(response).toEqual(new _summaryModel.default(testSummary));
71
+ });
72
+ it('Adds billing address to preview payload', async () => {
73
+ const configs = {
74
+ websiteId: 'test-website-id'
75
+ };
76
+ const options = {
77
+ intent: {
78
+ items: [{
79
+ planId: 'test-plan-id',
80
+ quantity: 1
81
+ }]
159
82
  }
160
- }, _callee2);
161
- })));
162
- it('Adds delivery address to preview payload', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
163
- var configs, options, deliveryAddress, instance;
164
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
165
- while (1) {
166
- switch (_context3.prev = _context3.next) {
167
- case 0:
168
- configs = {
169
- websiteId: 'test-website-id'
170
- };
171
- options = {
172
- intent: {
173
- items: [{
174
- planId: 'test-plan-id',
175
- quantity: 1
176
- }]
177
- }
178
- };
179
- deliveryAddress = {
180
- firstName: 'Test',
181
- lastName: 'Customer'
182
- };
183
- instance = new TestSummaryInstance({
184
- configs: configs,
185
- options: options
186
- });
187
- jest.spyOn(instance.storefront.purchase, 'preview');
188
- _context3.next = 7;
189
- return instance.fetchSummary({
190
- data: {
191
- deliveryAddress: deliveryAddress
192
- }
193
- });
194
-
195
- case 7:
196
- expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
197
- expect(instance.storefront.purchase.preview).toBeCalledWith({
198
- data: {
199
- items: options.intent.items,
200
- websiteId: configs.websiteId,
201
- deliveryAddress: deliveryAddress
202
- }
203
- });
204
-
205
- case 9:
206
- case "end":
207
- return _context3.stop();
208
- }
83
+ };
84
+ const billingAddress = {
85
+ firstName: 'Test',
86
+ lastName: 'Customer'
87
+ };
88
+ const instance = new TestSummaryInstance({
89
+ configs,
90
+ options
91
+ });
92
+ jest.spyOn(instance.storefront.purchase, 'preview');
93
+ await (0, _summary.fetchSummary)({
94
+ data: {
95
+ billingAddress
96
+ },
97
+ state: instance
98
+ });
99
+ expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
100
+ expect(instance.storefront.purchase.preview).toBeCalledWith({
101
+ data: {
102
+ items: options.intent.items,
103
+ websiteId: configs.websiteId,
104
+ billingAddress
105
+ }
106
+ });
107
+ });
108
+ it('Adds delivery address to preview payload', async () => {
109
+ const configs = {
110
+ websiteId: 'test-website-id'
111
+ };
112
+ const options = {
113
+ intent: {
114
+ items: [{
115
+ planId: 'test-plan-id',
116
+ quantity: 1
117
+ }]
209
118
  }
210
- }, _callee3);
211
- })));
212
- it('should throw errors with no configs or options', function () {
213
- var NoConfigOrOptionsError = new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
214
- var noConfigOrOptionsInstance = new TestSummaryInstance({
119
+ };
120
+ const deliveryAddress = {
121
+ firstName: 'Test',
122
+ lastName: 'Customer'
123
+ };
124
+ const instance = new TestSummaryInstance({
125
+ configs,
126
+ options
127
+ });
128
+ jest.spyOn(instance.storefront.purchase, 'preview');
129
+ await (0, _summary.fetchSummary)({
130
+ data: {
131
+ deliveryAddress
132
+ },
133
+ state: instance
134
+ });
135
+ expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
136
+ expect(instance.storefront.purchase.preview).toBeCalledWith({
137
+ data: {
138
+ items: options.intent.items,
139
+ websiteId: configs.websiteId,
140
+ deliveryAddress
141
+ }
142
+ });
143
+ });
144
+ it('should throw errors with no configs or options', async () => {
145
+ const noConfigOrOptionsInstance = new TestSummaryInstance({
215
146
  configs: null,
216
147
  options: null
217
148
  });
218
- var noConfigInstance = new TestSummaryInstance({
149
+ await (0, _asyncUtilities.expectConfigurationError)((0, _summary.fetchSummary)({
150
+ state: noConfigOrOptionsInstance
151
+ }));
152
+ const noConfigInstance = new TestSummaryInstance({
219
153
  configs: null,
220
154
  options: {}
221
155
  });
222
- var noOptionsInstance = new TestSummaryInstance({
156
+ await (0, _asyncUtilities.expectConfigurationError)((0, _summary.fetchSummary)({
157
+ state: noConfigInstance
158
+ }));
159
+ const noOptionsInstance = new TestSummaryInstance({
223
160
  configs: {},
224
161
  options: null
225
162
  });
226
- expect( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
227
- return regeneratorRuntime.wrap(function _callee4$(_context4) {
228
- while (1) {
229
- switch (_context4.prev = _context4.next) {
230
- case 0:
231
- _context4.next = 2;
232
- return noConfigOrOptionsInstance.fetchSummary();
233
-
234
- case 2:
235
- case "end":
236
- return _context4.stop();
237
- }
238
- }
239
- }, _callee4);
240
- }))).rejects.toEqual(NoConfigOrOptionsError);
241
- expect( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
242
- return regeneratorRuntime.wrap(function _callee5$(_context5) {
243
- while (1) {
244
- switch (_context5.prev = _context5.next) {
245
- case 0:
246
- _context5.next = 2;
247
- return noConfigInstance.fetchSummary();
248
-
249
- case 2:
250
- case "end":
251
- return _context5.stop();
252
- }
253
- }
254
- }, _callee5);
255
- }))).rejects.toEqual(NoConfigOrOptionsError);
256
- expect( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
257
- return regeneratorRuntime.wrap(function _callee6$(_context6) {
258
- while (1) {
259
- switch (_context6.prev = _context6.next) {
260
- case 0:
261
- _context6.next = 2;
262
- return noOptionsInstance.fetchSummary();
263
-
264
- case 2:
265
- case "end":
266
- return _context6.stop();
267
- }
268
- }
269
- }, _callee6);
270
- }))).rejects.toEqual(NoConfigOrOptionsError);
163
+ await (0, _asyncUtilities.expectConfigurationError)((0, _summary.fetchSummary)({
164
+ state: noOptionsInstance
165
+ }));
271
166
  });
272
167
  });
@@ -0,0 +1,52 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`RebillyInstruments theme builds the theme object 1`] = `
4
+ Object {
5
+ "borderRadius": "4px",
6
+ "color": Object {
7
+ "background": "#ffffff",
8
+ "buttonText": "#ffffff",
9
+ "errorText": "#cd5c5c",
10
+ "primary": "#0044d4",
11
+ "text": "#0D2B3E",
12
+ },
13
+ "getComputed": Object {
14
+ "color": Object {
15
+ "mutedBorder": "rgba(13, 43, 62, 0.25)",
16
+ "mutedText": "rgba(13, 43, 62, 0.6)",
17
+ "primaryValues": Values {
18
+ "alpha": 1,
19
+ "rgb": Array [
20
+ 0,
21
+ 68,
22
+ 212,
23
+ ],
24
+ "type": "base",
25
+ "weight": 0,
26
+ },
27
+ },
28
+ },
29
+ "space": Object {
30
+ "form": Object {
31
+ "horizontalPadding": "16px",
32
+ "minHeight": "44px",
33
+ "padding": "8px 16px",
34
+ "verticalPadding": "8px",
35
+ },
36
+ "l": "48px",
37
+ "m": "24px",
38
+ "s": "12px",
39
+ "xl": "96px",
40
+ "xs": "6px",
41
+ "xxl": "112px",
42
+ "xxs": "4px",
43
+ },
44
+ "typography": Object {
45
+ "captionFontSize": "12px",
46
+ "captionLineHeight": "12px",
47
+ "fontFamily": "Avenir, Helvetica, Arial, sans-serif",
48
+ "fontSize": "16px",
49
+ "lineHeight": "24px",
50
+ },
51
+ }
52
+ `;