@rebilly/instruments 3.1.0-beta.0 → 3.1.4-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.
Files changed (165) hide show
  1. package/dist/index.js +88 -107
  2. package/dist/index.min.js +88 -0
  3. package/package.json +17 -6
  4. package/rollup.config.js +84 -0
  5. package/src/functions/mount/fetch-data.js +13 -1
  6. package/src/functions/mount/index.js +6 -42
  7. package/src/functions/mount/setup-framepay-theme.js +2 -2
  8. package/src/functions/mount/setup-options.js +3 -0
  9. package/src/functions/mount/setup-user-flow.js +49 -0
  10. package/src/functions/purchase.js +1 -1
  11. package/src/functions/setup.js +1 -1
  12. package/src/functions/show.spec.js +1 -1
  13. package/src/i18n/en.json +3 -0
  14. package/src/index.js +1 -61
  15. package/src/instance.js +65 -0
  16. package/src/{index.spec.js → instance.spec.js} +2 -1
  17. package/src/loader/index.js +21 -1
  18. package/src/storefront/models/ready-to-pay-model.js +13 -2
  19. package/src/storefront/plans.js +8 -4
  20. package/src/storefront/plans.spec.js +8 -2
  21. package/src/storefront/products.js +8 -4
  22. package/src/storefront/products.spec.js +8 -2
  23. package/src/storefront/ready-to-pay.js +5 -4
  24. package/src/style/components/button.js +1 -0
  25. package/src/style/components/loader.js +2 -1
  26. package/src/style/payment-instruments/payment-card.js +2 -1
  27. package/src/style/utils/remove-empty-null.js +9 -9
  28. package/src/style/vendor/postmate.js +13 -0
  29. package/src/style/views/confirmation.js +2 -1
  30. package/src/views/common/iframe/base-iframe.js +2 -0
  31. package/src/views/common/iframe/event-listeners.js +10 -0
  32. package/src/views/common/iframe/method-iframe.js +3 -1
  33. package/src/views/confirmation.js +1 -0
  34. package/src/views/method-selector/express-methods/{google-pay.js → index.js} +3 -2
  35. package/src/views/method-selector/mount-express-methods.js +6 -18
  36. package/src/views/result.js +1 -0
  37. package/tests/mocks/rebilly-instruments-mock.js +2 -2
  38. package/dist/events/base-event.js +0 -66
  39. package/dist/events/events.spec.js +0 -18
  40. package/dist/events/index.js +0 -22
  41. package/dist/functions/destroy.js +0 -34
  42. package/dist/functions/destroy.spec.js +0 -69
  43. package/dist/functions/mount/fetch-data.js +0 -187
  44. package/dist/functions/mount/fetch-data.spec.js +0 -189
  45. package/dist/functions/mount/index.js +0 -218
  46. package/dist/functions/mount/mount.spec.js +0 -64
  47. package/dist/functions/mount/setup-element.js +0 -40
  48. package/dist/functions/mount/setup-framepay-theme.js +0 -95
  49. package/dist/functions/mount/setup-framepay.js +0 -46
  50. package/dist/functions/mount/setup-i18n.js +0 -33
  51. package/dist/functions/mount/setup-options.js +0 -99
  52. package/dist/functions/mount/setup-options.spec.js +0 -66
  53. package/dist/functions/mount/setup-storefront.js +0 -34
  54. package/dist/functions/mount/setup-styles.js +0 -43
  55. package/dist/functions/on.js +0 -40
  56. package/dist/functions/on.spec.js +0 -55
  57. package/dist/functions/purchase.js +0 -158
  58. package/dist/functions/purchase.spec.js +0 -74
  59. package/dist/functions/setup.js +0 -85
  60. package/dist/functions/setup.spec.js +0 -87
  61. package/dist/functions/show.js +0 -55
  62. package/dist/functions/show.spec.js +0 -61
  63. package/dist/functions/update.js +0 -74
  64. package/dist/functions/update.spec.js +0 -86
  65. package/dist/i18n/en.json +0 -22
  66. package/dist/i18n/es.json +0 -22
  67. package/dist/i18n/i18n.spec.js +0 -22
  68. package/dist/i18n/index.js +0 -72
  69. package/dist/index.spec.js +0 -35
  70. package/dist/loader/index.js +0 -94
  71. package/dist/loader/loader.spec.js +0 -69
  72. package/dist/storefront/index.js +0 -73
  73. package/dist/storefront/invoices.js +0 -27
  74. package/dist/storefront/models/base-model.js +0 -18
  75. package/dist/storefront/models/invoice-model.js +0 -14
  76. package/dist/storefront/models/plan-model.js +0 -14
  77. package/dist/storefront/models/product-model.js +0 -14
  78. package/dist/storefront/models/ready-to-pay-model.js +0 -46
  79. package/dist/storefront/models/summary-model.js +0 -79
  80. package/dist/storefront/models/transaction-model.js +0 -31
  81. package/dist/storefront/payment-instruments.js +0 -47
  82. package/dist/storefront/payment-instruments.spec.js +0 -55
  83. package/dist/storefront/plans.js +0 -37
  84. package/dist/storefront/plans.spec.js +0 -64
  85. package/dist/storefront/products.js +0 -40
  86. package/dist/storefront/products.spec.js +0 -65
  87. package/dist/storefront/purchase.js +0 -43
  88. package/dist/storefront/purchase.spec.js +0 -48
  89. package/dist/storefront/ready-to-pay.js +0 -58
  90. package/dist/storefront/ready-to-pay.spec.js +0 -69
  91. package/dist/storefront/storefront.spec.js +0 -15
  92. package/dist/storefront/summary.js +0 -55
  93. package/dist/storefront/summary.spec.js +0 -124
  94. package/dist/storefront/transactions.js +0 -27
  95. package/dist/style/base/__snapshots__/theme.spec.js.snap +0 -227
  96. package/dist/style/base/default-theme.js +0 -804
  97. package/dist/style/base/index.js +0 -104
  98. package/dist/style/base/theme.js +0 -41
  99. package/dist/style/base/theme.spec.js +0 -19
  100. package/dist/style/browserslist.js +0 -8
  101. package/dist/style/components/address.js +0 -64
  102. package/dist/style/components/button.js +0 -87
  103. package/dist/style/components/divider.js +0 -48
  104. package/dist/style/components/forms/checkbox.js +0 -86
  105. package/dist/style/components/forms/field.js +0 -65
  106. package/dist/style/components/forms/form.js +0 -28
  107. package/dist/style/components/forms/input.js +0 -86
  108. package/dist/style/components/forms/label.js +0 -64
  109. package/dist/style/components/forms/select.js +0 -95
  110. package/dist/style/components/forms/validation.js +0 -81
  111. package/dist/style/components/icons.js +0 -22
  112. package/dist/style/components/index.js +0 -57
  113. package/dist/style/components/loader.js +0 -50
  114. package/dist/style/components/methods.js +0 -108
  115. package/dist/style/components/overlay.js +0 -33
  116. package/dist/style/helpers/index.js +0 -59
  117. package/dist/style/index.js +0 -50
  118. package/dist/style/payment-instruments/content.js +0 -17
  119. package/dist/style/payment-instruments/index.js +0 -20
  120. package/dist/style/payment-instruments/payment-card.js +0 -35
  121. package/dist/style/utils/border.js +0 -47
  122. package/dist/style/utils/color-values.js +0 -58
  123. package/dist/style/utils/remove-empty-null.js +0 -20
  124. package/dist/style/vendor/framepay.js +0 -37
  125. package/dist/style/vendor/postmate.js +0 -17
  126. package/dist/style/views/confirmation.js +0 -85
  127. package/dist/style/views/index.js +0 -29
  128. package/dist/style/views/method-selector.js +0 -20
  129. package/dist/style/views/modal.js +0 -93
  130. package/dist/style/views/result.js +0 -61
  131. package/dist/style/views/summary.js +0 -127
  132. package/dist/utils/add-dom-element.js +0 -26
  133. package/dist/utils/format-currency.js +0 -15
  134. package/dist/utils/has-valid-css-selector.js +0 -11
  135. package/dist/utils/index.js +0 -55
  136. package/dist/utils/is-dom-element.js +0 -10
  137. package/dist/utils/process-property-as-dom-element.js +0 -38
  138. package/dist/utils/sleep.js +0 -10
  139. package/dist/views/__snapshots__/summary.spec.js.snap +0 -246
  140. package/dist/views/common/iframe/base-iframe.js +0 -59
  141. package/dist/views/common/iframe/event-listeners.js +0 -50
  142. package/dist/views/common/iframe/index.js +0 -19
  143. package/dist/views/common/iframe/method-iframe.js +0 -33
  144. package/dist/views/common/iframe/modal-iframe.js +0 -84
  145. package/dist/views/common/iframe/view-iframe.js +0 -31
  146. package/dist/views/common/render-utilities.js +0 -11
  147. package/dist/views/confirmation.js +0 -92
  148. package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +0 -3
  149. package/dist/views/method-selector/express-methods/apple-pay.js +0 -92
  150. package/dist/views/method-selector/express-methods/google-pay.js +0 -31
  151. package/dist/views/method-selector/express-methods/paypal.js +0 -19
  152. package/dist/views/method-selector/generate-digital-wallet.js +0 -68
  153. package/dist/views/method-selector/generate-digital-wallet.spec.js +0 -135
  154. package/dist/views/method-selector/get-method-data.js +0 -25
  155. package/dist/views/method-selector/get-payment-methods.js +0 -66
  156. package/dist/views/method-selector/get-payment-methods.spec.js +0 -46
  157. package/dist/views/method-selector/index.js +0 -122
  158. package/dist/views/method-selector/method-selector.spec.js +0 -124
  159. package/dist/views/method-selector/mount-express-methods.js +0 -69
  160. package/dist/views/method-selector/mount-methods.js +0 -74
  161. package/dist/views/modal.js +0 -88
  162. package/dist/views/result.js +0 -40
  163. package/dist/views/summary.js +0 -215
  164. package/dist/views/summary.spec.js +0 -134
  165. package/src/views/method-selector/express-methods/paypal.js +0 -7
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- var _storefrontMock = require("../../tests/mocks/storefront-mock");
4
-
5
- var _mswWhenThen = require("msw-when-then");
6
-
7
- var _server = require("../../tests/msw/server");
8
-
9
- var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
10
-
11
- var _products = require("./products");
12
-
13
- var _productModel = _interopRequireDefault(require("./models/product-model"));
14
-
15
- var _asyncUtilities = require("../../tests/async-utilities");
16
-
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
-
19
- describe('Storefront API Plan', () => {
20
- it('can fetch products', async () => {
21
- const testProduct = {
22
- name: 'Test Product',
23
- id: 'test-product-id-1'
24
- };
25
- (0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/products`)).thenReturn((0, _mswWhenThen.ok)([testProduct]));
26
- const instance = new _storefrontMock.StorefontTestingInstance();
27
- jest.spyOn(instance.storefront.products, 'getAll');
28
- const response = await (0, _products.fetchProducts)({
29
- state: instance
30
- });
31
- expect(instance.storefront.products.getAll).toBeCalledTimes(1);
32
- expect(instance.storefront.products.getAll).toBeCalledWith({
33
- filter: ''
34
- });
35
- expect(response).toBeInstanceOf(Array);
36
- expect(response[0]).toBeInstanceOf(_productModel.default);
37
- expect(response).toEqual([new _productModel.default(testProduct)]);
38
- });
39
- it('can fetch products with filter', async () => {
40
- const instance = new _storefrontMock.StorefontTestingInstance({
41
- data: {
42
- plans: [{
43
- productId: 'test-product-1'
44
- }, {
45
- productId: 'test-product-2'
46
- }]
47
- }
48
- });
49
- jest.spyOn(instance.storefront.products, 'getAll');
50
- await (0, _products.fetchProducts)({
51
- state: instance
52
- });
53
- expect(instance.storefront.products.getAll).toBeCalledWith({
54
- filter: 'id:test-product-1,test-product-2'
55
- });
56
- });
57
- it('should throw errors with no options', async () => {
58
- const noConfigOrOptionsInstance = new _storefrontMock.StorefontTestingInstance({
59
- options: null
60
- });
61
- await (0, _asyncUtilities.expectConfigurationError)((0, _products.fetchProducts)({
62
- state: noConfigOrOptionsInstance
63
- }));
64
- });
65
- });
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.postPurchase = postPurchase;
7
- exports.postPayment = postPayment;
8
-
9
- var _index = require("./index");
10
-
11
- async function postPurchase({
12
- data,
13
- state
14
- }) {
15
- return (0, _index.Endpoint)({
16
- state
17
- }, async () => {
18
- if (data._raw) {
19
- delete data._raw;
20
- }
21
-
22
- return state.storefront.purchase.purchase({
23
- data
24
- });
25
- });
26
- }
27
-
28
- async function postPayment({
29
- data,
30
- state
31
- }) {
32
- return (0, _index.Endpoint)({
33
- state
34
- }, async () => {
35
- if (data._raw) {
36
- delete data._raw;
37
- }
38
-
39
- return state.storefront.purchase.payment({
40
- data
41
- });
42
- });
43
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- var _storefrontMock = require("../../tests/mocks/storefront-mock");
4
-
5
- var _mswWhenThen = require("msw-when-then");
6
-
7
- var _server = require("../../tests/msw/server");
8
-
9
- var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
10
-
11
- describe('Storefront API Purchase', () => {
12
- it('can make purchase', async () => {
13
- const instance = (0, _storefrontMock.StorefontTestingInstance)();
14
- const payload = {
15
- websiteId: 'test-website-id',
16
- items: [{
17
- planId: 'test-plan-id-1',
18
- quantity: 1
19
- }],
20
- billingAddress: {
21
- firstName: 'Test',
22
- lastName: 'Customer'
23
- },
24
- paymentInstruction: {
25
- token: 'test-token'
26
- }
27
- };
28
- const fields = {
29
- orderId: 'test-order-id',
30
- invoice: {
31
- id: 'test-invoice-id'
32
- },
33
- transaction: {
34
- id: 'test-transaction-id'
35
- }
36
- };
37
- (0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/purchase`)).thenReturn((0, _mswWhenThen.ok)(fields));
38
- jest.spyOn(instance.storefront.purchase, 'purchase');
39
- const requestResponse = await instance.storefront.purchase.purchase(payload);
40
- expect(instance.storefront.purchase.purchase).toBeCalledTimes(1);
41
- expect(instance.storefront.purchase.purchase).toBeCalledWith(payload);
42
- expect(requestResponse.config).toBeInstanceOf(Object);
43
- expect(requestResponse.fields).toBeInstanceOf(Object);
44
- expect(requestResponse.response).toBeInstanceOf(Object);
45
- expect(requestResponse.fields).toEqual(fields);
46
- expect(requestResponse.fields).toMatchObject(fields);
47
- });
48
- });
@@ -1,58 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fetchReadyToPay = fetchReadyToPay;
7
-
8
- var _riskDataCollector = require("@rebilly/risk-data-collector");
9
-
10
- var _readyToPayModel = _interopRequireDefault(require("./models/ready-to-pay-model"));
11
-
12
- var _index = require("./index");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- async function fetchReadyToPay({
17
- state,
18
- riskMetadata = null
19
- }) {
20
- return (0, _index.Endpoint)({
21
- state
22
- }, async () => {
23
- var _state$options, _state$options2, _state$data;
24
-
25
- if (!riskMetadata) {
26
- const {
27
- riskMetadata: data
28
- } = await (0, _riskDataCollector.collectData)();
29
- riskMetadata = data;
30
- }
31
-
32
- const websiteId = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.websiteId) || null;
33
- const data = {
34
- websiteId,
35
- riskMetadata
36
- };
37
-
38
- if ((_state$options2 = state.options) !== null && _state$options2 !== void 0 && _state$options2.items) {
39
- data.items = state.options.items;
40
- }
41
-
42
- if ((_state$data = state.data) !== null && _state$data !== void 0 && _state$data.amountAndCurrency) {
43
- const money = state.data.amountAndCurrency;
44
- data.amount = money.amount;
45
- data.currency = money.currency;
46
- }
47
-
48
- const {
49
- fields: readyToPayFields
50
- } = await state.storefront.purchase.readyToPay({
51
- data
52
- });
53
- return Object.values(readyToPayFields).map((fields, index) => new _readyToPayModel.default({
54
- index,
55
- ...fields
56
- }));
57
- });
58
- }
@@ -1,69 +0,0 @@
1
- "use strict";
2
-
3
- var _storefrontMock = require("../../tests/mocks/storefront-mock");
4
-
5
- var _mswWhenThen = require("msw-when-then");
6
-
7
- var _server = require("../../tests/msw/server");
8
-
9
- var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
10
-
11
- var _readyToPay = require("./ready-to-pay");
12
-
13
- var _readyToPayModel = _interopRequireDefault(require("./models/ready-to-pay-model"));
14
-
15
- var _asyncUtilities = require("../../tests/async-utilities");
16
-
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
-
19
- describe('Storefront API Ready to Pay', () => {
20
- it('can fetch ready to pay', async () => {
21
- const readyToPayPayload = [{
22
- method: 'payment-card',
23
- feature: null,
24
- brands: ['Visa'],
25
- filters: []
26
- }];
27
- const options = {
28
- websiteId: 'test-website-id',
29
- items: [{
30
- planId: 'test-plan-id',
31
- quantity: 1
32
- }]
33
- };
34
- (0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/ready-to-pay`)).thenReturn((0, _mswWhenThen.ok)(readyToPayPayload));
35
- const instance = (0, _storefrontMock.StorefontTestingInstance)({
36
- options
37
- });
38
- jest.spyOn(instance.storefront.purchase, 'readyToPay');
39
- const riskMetadata = null;
40
- const response = await (0, _readyToPay.fetchReadyToPay)({
41
- state: instance,
42
- riskMetadata
43
- });
44
- expect(instance.storefront.purchase.readyToPay).toBeCalledTimes(1);
45
- expect(instance.storefront.purchase.readyToPay).toBeCalledWith({
46
- data: {
47
- items: options.items,
48
- websiteId: options.websiteId,
49
- riskMetadata: {}
50
- }
51
- });
52
- expect(response).toBeInstanceOf(Array);
53
- expect(response[0]).toBeInstanceOf(_readyToPayModel.default);
54
- expect(response).toEqual([new _readyToPayModel.default({
55
- index: 0,
56
- ...readyToPayPayload[0]
57
- })]);
58
- });
59
- it('should throw errors with no options', async () => {
60
- const riskMetadata = null;
61
- const noConfigOrOptionsInstance = new _storefrontMock.StorefontTestingInstance({
62
- options: null
63
- });
64
- await (0, _asyncUtilities.expectConfigurationError)((0, _readyToPay.fetchReadyToPay)({
65
- riskMetadata,
66
- state: noConfigOrOptionsInstance
67
- }));
68
- });
69
- });
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- var _storefrontMock = require("../../tests/mocks/storefront-mock");
4
-
5
- describe('Storefront application programming interface', () => {
6
- it('can create rebilly-js-sdk instance', () => {
7
- const storefront = (0, _storefrontMock.MockStorefront)();
8
- expect(storefront).toHaveProperty('setPublishableKey');
9
- });
10
- it('has required endpoints', () => {
11
- const storefront = (0, _storefrontMock.MockStorefront)();
12
- expect(storefront).toHaveProperty('purchase');
13
- expect(storefront.purchase).toHaveProperty('readyToPay');
14
- });
15
- });
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fetchSummary = fetchSummary;
7
-
8
- var _summaryModel = _interopRequireDefault(require("./models/summary-model"));
9
-
10
- var _index = require("./index");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- async function fetchSummary({
15
- data = null,
16
- state = null
17
- } = {}) {
18
- return (0, _index.Endpoint)({
19
- state
20
- }, async () => {
21
- var _state$options, _state$options2, _state$data;
22
-
23
- const websiteId = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.websiteId) || null;
24
- const payload = {
25
- data: {
26
- websiteId
27
- }
28
- };
29
-
30
- if ((_state$options2 = state.options) !== null && _state$options2 !== void 0 && _state$options2.items) {
31
- payload.data.items = state.options.items;
32
- }
33
-
34
- if ((_state$data = state.data) !== null && _state$data !== void 0 && _state$data.amountAndCurrency) {
35
- payload.data = { ...payload.data,
36
- ...state.data.amountAndCurrency
37
- };
38
- }
39
-
40
- if (data !== null && data !== void 0 && data.billingAddress) {
41
- payload.data.billingAddress = data.billingAddress;
42
- }
43
-
44
- if (data !== null && data !== void 0 && data.deliveryAddress) {
45
- payload.data.deliveryAddress = data.deliveryAddress;
46
- }
47
-
48
- const {
49
- fields: summaryFields
50
- } = await state.storefront.purchase.preview(payload); // In case of preview purchase gets call again for updating the values
51
-
52
- state.data.previewPurchase = summaryFields;
53
- return new _summaryModel.default(summaryFields);
54
- });
55
- }
@@ -1,124 +0,0 @@
1
- "use strict";
2
-
3
- var _storefrontMock = require("../../tests/mocks/storefront-mock");
4
-
5
- var _mswWhenThen = require("msw-when-then");
6
-
7
- var _server = require("../../tests/msw/server");
8
-
9
- var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
10
-
11
- var _summary = require("./summary");
12
-
13
- var _summaryModel = _interopRequireDefault(require("./models/summary-model"));
14
-
15
- var _asyncUtilities = require("../../tests/async-utilities");
16
-
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
-
19
- describe('Storefront API Summary', () => {
20
- it('can fetch preview', async () => {
21
- const options = {
22
- websiteId: 'test-website-id',
23
- items: [{
24
- planId: 'test-plan-id',
25
- quantity: 1
26
- }]
27
- };
28
- const testSummary = {
29
- currency: 'USD',
30
- lineItems: [{
31
- description: 'test-plan-id-1',
32
- planId: 'test-plan-id-1',
33
- quantity: 1
34
- }]
35
- };
36
- (0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/preview-purchase`)).thenReturn((0, _mswWhenThen.ok)(testSummary));
37
- const instance = (0, _storefrontMock.StorefontTestingInstance)({
38
- options
39
- });
40
- jest.spyOn(instance.storefront.purchase, 'preview');
41
- const response = await (0, _summary.fetchSummary)({
42
- state: instance
43
- });
44
- expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
45
- expect(instance.storefront.purchase.preview).toBeCalledWith({
46
- data: {
47
- items: options.items,
48
- websiteId: options.websiteId
49
- }
50
- });
51
- expect(response).toBeInstanceOf(_summaryModel.default);
52
- expect(response).toEqual(new _summaryModel.default(testSummary));
53
- });
54
- it('Adds billing address to preview payload', async () => {
55
- const options = {
56
- websiteId: 'test-website-id',
57
- items: [{
58
- planId: 'test-plan-id',
59
- quantity: 1
60
- }]
61
- };
62
- const billingAddress = {
63
- firstName: 'Test',
64
- lastName: 'Customer'
65
- };
66
- const instance = (0, _storefrontMock.StorefontTestingInstance)({
67
- options
68
- });
69
- jest.spyOn(instance.storefront.purchase, 'preview');
70
- await (0, _summary.fetchSummary)({
71
- data: {
72
- billingAddress
73
- },
74
- state: instance
75
- });
76
- expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
77
- expect(instance.storefront.purchase.preview).toBeCalledWith({
78
- data: {
79
- items: options.items,
80
- websiteId: options.websiteId,
81
- billingAddress
82
- }
83
- });
84
- });
85
- it('Adds delivery address to preview payload', async () => {
86
- const options = {
87
- websiteId: 'test-website-id',
88
- items: [{
89
- planId: 'test-plan-id',
90
- quantity: 1
91
- }]
92
- };
93
- const deliveryAddress = {
94
- firstName: 'Test',
95
- lastName: 'Customer'
96
- };
97
- const instance = (0, _storefrontMock.StorefontTestingInstance)({
98
- options
99
- });
100
- jest.spyOn(instance.storefront.purchase, 'preview');
101
- await (0, _summary.fetchSummary)({
102
- data: {
103
- deliveryAddress
104
- },
105
- state: instance
106
- });
107
- expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
108
- expect(instance.storefront.purchase.preview).toBeCalledWith({
109
- data: {
110
- items: options.items,
111
- websiteId: options.websiteId,
112
- deliveryAddress
113
- }
114
- });
115
- });
116
- it('should throw errors with no options', async () => {
117
- const noConfigOrOptionsInstance = (0, _storefrontMock.StorefontTestingInstance)({
118
- options: null
119
- });
120
- await (0, _asyncUtilities.expectConfigurationError)((0, _summary.fetchSummary)({
121
- state: noConfigOrOptionsInstance
122
- }));
123
- });
124
- });
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fetchTransaction = fetchTransaction;
7
-
8
- var _transactionModel = _interopRequireDefault(require("./models/transaction-model"));
9
-
10
- var _index = require("./index");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- async function fetchTransaction({
15
- data = null,
16
- state = null
17
- }) {
18
- return (0, _index.Endpoint)({
19
- state
20
- }, async () => {
21
- state.storefront.setSessionToken(state.options.customerJwt);
22
- const {
23
- fields
24
- } = await state.storefront.transactions.get(data);
25
- return new _transactionModel.default(fields);
26
- });
27
- }