@rebilly/instruments 4.5.0 → 4.6.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 (134) hide show
  1. package/.babelrc +24 -26
  2. package/CHANGELOG.md +7 -0
  3. package/dist/index.js +8 -8
  4. package/dist/index.min.js +8 -8
  5. package/package.json +14 -3
  6. package/project.json +9 -0
  7. package/rollup.config.mjs +21 -26
  8. package/src/data/options-schema/index.js +94 -78
  9. package/src/data/options-schema/schemas/options-schema.js +419 -411
  10. package/src/events/base-event.js +34 -34
  11. package/src/events/events.spec.js +6 -6
  12. package/src/events/index.js +5 -5
  13. package/src/functions/destroy.js +19 -19
  14. package/src/functions/destroy.spec.js +41 -41
  15. package/src/functions/mount/fetch-data.js +200 -193
  16. package/src/functions/mount/fetch-data.spec.js +287 -285
  17. package/src/functions/mount/get-lead-source-data.js +31 -31
  18. package/src/functions/mount/get-lead-source-data.spec.js +19 -19
  19. package/src/functions/mount/index.js +73 -65
  20. package/src/functions/mount/mount.spec.js +77 -66
  21. package/src/functions/mount/setup-element.js +23 -23
  22. package/src/functions/mount/setup-framepay-theme.js +86 -68
  23. package/src/functions/mount/setup-framepay.js +9 -5
  24. package/src/functions/mount/setup-i18n.js +15 -15
  25. package/src/functions/mount/setup-options.js +74 -74
  26. package/src/functions/mount/setup-options.spec.js +323 -287
  27. package/src/functions/mount/setup-storefront.js +15 -20
  28. package/src/functions/mount/setup-styles-vars.js +19 -22
  29. package/src/functions/mount/setup-user-flow.js +51 -47
  30. package/src/functions/on.js +5 -5
  31. package/src/functions/on.spec.js +60 -51
  32. package/src/functions/purchase.js +151 -146
  33. package/src/functions/purchase.spec.js +59 -56
  34. package/src/functions/setup.js +53 -53
  35. package/src/functions/setup.spec.js +88 -75
  36. package/src/functions/show.js +13 -14
  37. package/src/functions/show.spec.js +53 -53
  38. package/src/functions/update.js +30 -28
  39. package/src/functions/update.spec.js +94 -93
  40. package/src/i18n/en.json +32 -32
  41. package/src/i18n/es.json +29 -29
  42. package/src/i18n/i18n.spec.js +18 -18
  43. package/src/i18n/index.js +48 -48
  44. package/src/instance.js +36 -36
  45. package/src/instance.spec.js +29 -27
  46. package/src/loader/index.js +95 -70
  47. package/src/loader/loader.spec.js +63 -63
  48. package/src/state/iframes.js +21 -21
  49. package/src/state/index.js +56 -54
  50. package/src/storefront/account-and-website.js +10 -8
  51. package/src/storefront/account-and-website.spec.js +55 -55
  52. package/src/storefront/deposit-requests.js +6 -6
  53. package/src/storefront/fetch-plans-from-addons-bumpOffer.js +21 -19
  54. package/src/storefront/fetch-products-from-plans.js +52 -51
  55. package/src/storefront/fetch-products-from-plans.spec.js +90 -87
  56. package/src/storefront/index.js +56 -49
  57. package/src/storefront/invoices.js +15 -15
  58. package/src/storefront/invoices.spec.js +69 -65
  59. package/src/storefront/models/account-model.js +29 -32
  60. package/src/storefront/models/base-model.js +6 -9
  61. package/src/storefront/models/deposit-request-model.js +22 -13
  62. package/src/storefront/models/invoice-model.js +16 -16
  63. package/src/storefront/models/payment-metadata.js +4 -4
  64. package/src/storefront/models/plan-model.js +73 -64
  65. package/src/storefront/models/ready-to-pay-model.js +59 -59
  66. package/src/storefront/models/summary-model.js +43 -46
  67. package/src/storefront/models/transaction-model.js +11 -14
  68. package/src/storefront/payment-instruments.js +38 -35
  69. package/src/storefront/payment-instruments.spec.js +81 -62
  70. package/src/storefront/purchase.js +50 -44
  71. package/src/storefront/purchase.spec.js +40 -40
  72. package/src/storefront/ready-to-pay.js +75 -77
  73. package/src/storefront/ready-to-pay.spec.js +59 -54
  74. package/src/storefront/storefront.spec.js +9 -9
  75. package/src/storefront/summary.js +93 -67
  76. package/src/storefront/summary.spec.js +108 -106
  77. package/src/storefront/transactions.js +6 -6
  78. package/src/style/base/default-theme.js +928 -923
  79. package/src/style/base/theme.js +21 -21
  80. package/src/style/base/theme.spec.js +13 -13
  81. package/src/style/index.js +3 -3
  82. package/src/style/utils/border.js +40 -27
  83. package/src/style/utils/color-values.js +18 -18
  84. package/src/style/utils/minifyCss.js +6 -6
  85. package/src/utils/add-dom-element.js +14 -14
  86. package/src/utils/format-currency.js +6 -5
  87. package/src/utils/has-valid-css-selector.js +2 -2
  88. package/src/utils/index.js +6 -6
  89. package/src/utils/is-dom-element.js +1 -1
  90. package/src/utils/process-property-as-dom-element.js +22 -22
  91. package/src/utils/quantity.js +26 -28
  92. package/src/utils/sleep.js +3 -1
  93. package/src/views/amount-selector.js +37 -36
  94. package/src/views/common/iframe/base-iframe.js +53 -52
  95. package/src/views/common/iframe/events/change-iframe-src-handler.js +5 -5
  96. package/src/views/common/iframe/events/dispatch-event-handler.js +4 -4
  97. package/src/views/common/iframe/events/resize-component-handler.js +8 -8
  98. package/src/views/common/iframe/events/show-error-handler.js +2 -2
  99. package/src/views/common/iframe/events/stop-loader-handler.js +8 -8
  100. package/src/views/common/iframe/events/update-addons-handler.js +20 -13
  101. package/src/views/common/iframe/events/update-coupons-handler.js +9 -9
  102. package/src/views/common/iframe/events/update-items-handler.js +26 -22
  103. package/src/views/common/iframe/modal-iframe.js +67 -56
  104. package/src/views/common/iframe/view-iframe.js +11 -11
  105. package/src/views/common/render-utilities.js +2 -2
  106. package/src/views/confirmation.js +33 -30
  107. package/src/views/errors.js +89 -79
  108. package/src/views/form.js +41 -37
  109. package/src/views/method-selector/express-methods.js +46 -46
  110. package/src/views/method-selector/generate-digital-wallet.js +46 -45
  111. package/src/views/method-selector/generate-digital-wallet.spec.js +104 -102
  112. package/src/views/method-selector/generate-framepay-config.js +53 -51
  113. package/src/views/method-selector/generate-framepay-config.spec.js +197 -173
  114. package/src/views/method-selector/get-method-data.js +5 -6
  115. package/src/views/method-selector/get-payment-methods.js +18 -16
  116. package/src/views/method-selector/get-payment-methods.spec.js +29 -27
  117. package/src/views/method-selector/index.js +154 -139
  118. package/src/views/method-selector/method-selector.spec.js +13 -13
  119. package/src/views/method-selector/mount-bump-offer.js +65 -49
  120. package/src/views/method-selector/mount-express-methods.js +89 -85
  121. package/src/views/modal.js +74 -67
  122. package/src/views/result.js +14 -14
  123. package/src/views/summary.js +25 -26
  124. package/tests/async-utilities.js +13 -13
  125. package/tests/mocks/framepay-mock.js +9 -8
  126. package/tests/mocks/rebilly-api-mock.js +5 -3
  127. package/tests/mocks/rebilly-instruments-mock.js +121 -117
  128. package/tests/mocks/storefront-api-mock.js +55 -48
  129. package/tests/mocks/storefront-mock.js +10 -14
  130. package/tests/msw/server.js +6 -6
  131. package/tests/setup-test.js +14 -16
  132. package/vitest.config.js +14 -14
  133. package/.eslintrc.js +0 -34
  134. package/.prettierrc.js +0 -11
@@ -6,70 +6,75 @@ import { fetchReadyToPay } from './ready-to-pay';
6
6
  import ReadyToPayModel from './models/ready-to-pay-model';
7
7
  import { expectConfigurationError } from 'tests/async-utilities';
8
8
  import PaymentMetadataModel from './models/payment-metadata';
9
- import { paymentMethods } from '@rebilly/api-metadata'
9
+ import { paymentMethods } from '@rebilly/api-metadata';
10
10
 
11
11
  describe('Storefront API Ready to Pay', () => {
12
- it('can fetch ready to pay', async () => {
13
- const readyToPayPayload = [
14
- {
15
- method: 'payment-card',
16
- feature: null,
17
- brands: ['Visa'],
18
- filters: []
19
- }
20
- ];
21
- const options = {
22
- websiteId: 'test-website-id',
23
- items: [
24
- {
25
- planId: 'test-plan-id',
26
- quantity: 1
27
- }
28
- ]
29
- };
12
+ it('can fetch ready to pay', async () => {
13
+ const readyToPayPayload = [
14
+ {
15
+ method: 'payment-card',
16
+ feature: null,
17
+ brands: ['Visa'],
18
+ filters: [],
19
+ },
20
+ ];
21
+ const options = {
22
+ websiteId: 'test-website-id',
23
+ items: [
24
+ {
25
+ planId: 'test-plan-id',
26
+ quantity: 1,
27
+ },
28
+ ],
29
+ };
30
30
 
31
- const paymentCardMetadata = [...paymentMethods].find(method => method.apiName === 'payment-card');
31
+ const paymentCardMetadata = [...paymentMethods].find(
32
+ (method) => method.apiName === 'payment-card',
33
+ );
32
34
 
33
- when(post(`${storefrontURL}/ready-to-pay`)).thenReturn(
34
- ok(readyToPayPayload)
35
- );
35
+ when(post(`${storefrontURL}/ready-to-pay`)).thenReturn(
36
+ ok(readyToPayPayload),
37
+ );
36
38
 
37
- const instance = StorefontTestingInstance({
38
- options
39
- });
39
+ const instance = StorefontTestingInstance({
40
+ options,
41
+ });
40
42
 
41
- vi.spyOn(instance.storefront.purchase, 'readyToPay');
43
+ vi.spyOn(instance.storefront.purchase, 'readyToPay');
42
44
 
43
- const riskMetadata = null;
44
- const response = await fetchReadyToPay({ state: instance, riskMetadata });
45
+ const riskMetadata = null;
46
+ const response = await fetchReadyToPay({
47
+ state: instance,
48
+ riskMetadata,
49
+ });
45
50
 
46
- expect(instance.storefront.purchase.readyToPay).toBeCalledTimes(1);
47
- expect(instance.storefront.purchase.readyToPay).toBeCalledWith({
48
- data: expect.objectContaining({
49
- items: options.items,
50
- websiteId: options.websiteId,
51
- riskMetadata: expect.anything()
52
- })
51
+ expect(instance.storefront.purchase.readyToPay).toBeCalledTimes(1);
52
+ expect(instance.storefront.purchase.readyToPay).toBeCalledWith({
53
+ data: expect.objectContaining({
54
+ items: options.items,
55
+ websiteId: options.websiteId,
56
+ riskMetadata: expect.anything(),
57
+ }),
58
+ });
59
+ expect(response).toBeInstanceOf(Array);
60
+ expect(response[0]).toBeInstanceOf(ReadyToPayModel);
61
+ expect(response).toEqual([
62
+ new ReadyToPayModel({
63
+ index: 0,
64
+ ...readyToPayPayload[0],
65
+ metadata: new PaymentMetadataModel(paymentCardMetadata),
66
+ }),
67
+ ]);
53
68
  });
54
- expect(response).toBeInstanceOf(Array);
55
- expect(response[0]).toBeInstanceOf(ReadyToPayModel);
56
- expect(response).toEqual([
57
- new ReadyToPayModel({
58
- index: 0,
59
- ...readyToPayPayload[0],
60
- metadata: new PaymentMetadataModel(paymentCardMetadata),
61
- })
62
- ]);
63
- });
64
69
 
65
- it('should throw errors with no options', async () => {
66
- const riskMetadata = null;
70
+ it('should throw errors with no options', async () => {
71
+ const riskMetadata = null;
67
72
 
68
- const noConfigOrOptionsInstance = new StorefontTestingInstance({
69
- options: null
73
+ const noConfigOrOptionsInstance = new StorefontTestingInstance({
74
+ options: null,
75
+ });
76
+ await expectConfigurationError(
77
+ fetchReadyToPay({ riskMetadata, state: noConfigOrOptionsInstance }),
78
+ );
70
79
  });
71
- await expectConfigurationError(
72
- fetchReadyToPay({ riskMetadata, state: noConfigOrOptionsInstance })
73
- );
74
- });
75
80
  });
@@ -1,14 +1,14 @@
1
1
  import { MockStorefront } from 'tests/mocks/storefront-mock';
2
2
 
3
3
  describe('Storefront application programming interface', () => {
4
- it('can create rebilly-js-sdk instance', () => {
5
- const storefront = MockStorefront();
6
- expect(storefront).toHaveProperty('setPublishableKey');
7
- });
4
+ it('can create rebilly-js-sdk instance', () => {
5
+ const storefront = MockStorefront();
6
+ expect(storefront).toHaveProperty('setPublishableKey');
7
+ });
8
8
 
9
- it('has required endpoints', () => {
10
- const storefront = MockStorefront();
11
- expect(storefront).toHaveProperty('purchase');
12
- expect(storefront.purchase).toHaveProperty('readyToPay');
13
- });
9
+ it('has required endpoints', () => {
10
+ const storefront = MockStorefront();
11
+ expect(storefront).toHaveProperty('purchase');
12
+ expect(storefront.purchase).toHaveProperty('readyToPay');
13
+ });
14
14
  });
@@ -2,87 +2,113 @@ import cloneDeep from 'lodash.clonedeep';
2
2
  import state from '../state';
3
3
  import SummaryModel from './models/summary-model';
4
4
  import { Endpoint } from './index';
5
- import { mapItemsQuantities, createQuantitiesMap, updateItemQuantityFromMap } from '../utils/quantity';
5
+ import {
6
+ mapItemsQuantities,
7
+ createQuantitiesMap,
8
+ updateItemQuantityFromMap,
9
+ } from '../utils/quantity';
6
10
 
7
11
  export async function fetchSummary({ data = null } = {}) {
8
- return Endpoint(async () => {
9
- const items = state.options?.items;
10
- const websiteId = state.options?.websiteId || null;
11
- const bumpOfferProductsIds = state.options?.bumpOffer?.map(({ planId }) => planId) || [];
12
+ return Endpoint(async () => {
13
+ const items = state.options?.items;
14
+ const websiteId = state.options?.websiteId || null;
15
+ const bumpOfferProductsIds =
16
+ state.options?.bumpOffer?.map(({ planId }) => planId) || [];
12
17
 
13
- const payload = {
14
- data: {
15
- websiteId
16
- }
17
- };
18
+ const payload = {
19
+ data: {
20
+ websiteId,
21
+ },
22
+ };
18
23
 
19
- const isBumpOfferSummary = () => state.data.summaryLineItems.every(
20
- item => bumpOfferProductsIds.includes(item.planId)
21
- );
22
- if (!isBumpOfferSummary() && !state.data.acceptBumpOffer) {
23
- payload.data.items = mapItemsQuantities(state.data.summaryLineItems);
24
- } else if (items) {
25
- if (state.data.acceptBumpOffer) {
26
- payload.data.items = state.options.bumpOffer;
27
- } else {
28
- payload.data.items = mapItemsQuantities(items);
29
- }
30
- } else {
31
- payload.data.items = mapItemsQuantities(state.data.summaryLineItems);
24
+ const isBumpOfferSummary = () =>
25
+ state.data.summaryLineItems.every((item) =>
26
+ bumpOfferProductsIds.includes(item.planId),
27
+ );
28
+ if (!isBumpOfferSummary() && !state.data.acceptBumpOffer) {
29
+ payload.data.items = mapItemsQuantities(
30
+ state.data.summaryLineItems,
31
+ );
32
+ } else if (items) {
33
+ if (state.data.acceptBumpOffer) {
34
+ payload.data.items = state.options.bumpOffer;
35
+ } else {
36
+ payload.data.items = mapItemsQuantities(items);
37
+ }
38
+ } else {
39
+ payload.data.items = mapItemsQuantities(
40
+ state.data.summaryLineItems,
41
+ );
32
42
 
33
- if (state.data?.addons.length > 0) {
34
- payload.data.items = payload.data.items.concat(state.data.addons.map(mapItemsQuantities))
35
- }
36
- }
43
+ if (state.data?.addons.length > 0) {
44
+ payload.data.items = payload.data.items.concat(
45
+ state.data.addons.map(mapItemsQuantities),
46
+ );
47
+ }
48
+ }
37
49
 
38
- if (!state.data.acceptBumpOffer && state.data?.previewPurchase?.addonLineItems?.length > 0) {
39
- payload.data.items = payload.data.items.concat(state.data.previewPurchase.addonLineItems);
40
- }
50
+ if (
51
+ !state.data.acceptBumpOffer &&
52
+ state.data?.previewPurchase?.addonLineItems?.length > 0
53
+ ) {
54
+ payload.data.items = payload.data.items.concat(
55
+ state.data.previewPurchase.addonLineItems,
56
+ );
57
+ }
41
58
 
42
- if (state.data?.amountAndCurrency) {
43
- payload.data = {
44
- ...payload.data,
45
- ...state.data.amountAndCurrency
46
- }
47
- }
59
+ if (state.data?.amountAndCurrency) {
60
+ payload.data = {
61
+ ...payload.data,
62
+ ...state.data.amountAndCurrency,
63
+ };
64
+ }
48
65
 
49
- if (data?.billingAddress) {
50
- payload.data.billingAddress = data.billingAddress;
51
- }
66
+ if (data?.billingAddress) {
67
+ payload.data.billingAddress = data.billingAddress;
68
+ }
52
69
 
53
- if (data?.deliveryAddress) {
54
- payload.data.deliveryAddress = data.deliveryAddress;
55
- }
70
+ if (data?.deliveryAddress) {
71
+ payload.data.deliveryAddress = data.deliveryAddress;
72
+ }
56
73
 
57
- if (state.data?.couponIds) {
58
- payload.data.couponIds = state.data.couponIds;
59
- }
74
+ if (state.data?.couponIds) {
75
+ payload.data.couponIds = state.data.couponIds;
76
+ }
60
77
 
61
- const { fields: summaryFields } = await state.storefront.purchase.preview(
62
- payload
63
- );
78
+ const { fields: summaryFields } =
79
+ await state.storefront.purchase.preview(payload);
64
80
 
65
- let transformedFields = summaryFields;
66
- if (!state.data.acceptBumpOffer) {
67
- const quantitiesByPlanId = createQuantitiesMap(items);
81
+ let transformedFields = summaryFields;
82
+ if (!state.data.acceptBumpOffer) {
83
+ const quantitiesByPlanId = createQuantitiesMap(items);
68
84
 
69
- transformedFields = cloneDeep(summaryFields);
70
- if (transformedFields.lineItems) {
71
- if (state.data?.previewPurchase?.addonLineItems) {
72
- const addonsMap = state.data.previewPurchase.addonLineItems.reduce((map, curr) => {
73
- map.set(curr.planId, curr);
74
- return map;
75
- }, new Map());
76
- transformedFields.lineItems = transformedFields.lineItems.filter(item => !addonsMap.has(item.planId));
77
- transformedFields.addonLineItems = state.data.previewPurchase.addonLineItems;
85
+ transformedFields = cloneDeep(summaryFields);
86
+ if (transformedFields.lineItems) {
87
+ if (state.data?.previewPurchase?.addonLineItems) {
88
+ const addonsMap =
89
+ state.data.previewPurchase.addonLineItems.reduce(
90
+ (map, curr) => {
91
+ map.set(curr.planId, curr);
92
+ return map;
93
+ },
94
+ new Map(),
95
+ );
96
+ transformedFields.lineItems =
97
+ transformedFields.lineItems.filter(
98
+ (item) => !addonsMap.has(item.planId),
99
+ );
100
+ transformedFields.addonLineItems =
101
+ state.data.previewPurchase.addonLineItems;
102
+ }
103
+ transformedFields.lineItems.forEach(
104
+ updateItemQuantityFromMap(quantitiesByPlanId),
105
+ );
106
+ }
78
107
  }
79
- transformedFields.lineItems.forEach(updateItemQuantityFromMap(quantitiesByPlanId))
80
- }
81
- }
82
108
 
83
- // In case of preview purchase gets call again for updating the values
84
- state.data.previewPurchase = transformedFields;
109
+ // In case of preview purchase gets call again for updating the values
110
+ state.data.previewPurchase = transformedFields;
85
111
 
86
- return new SummaryModel(transformedFields);
87
- });
112
+ return new SummaryModel(transformedFields);
113
+ });
88
114
  }
@@ -7,128 +7,130 @@ import { expectConfigurationError } from 'tests/async-utilities';
7
7
  import { fetchSummary } from './summary';
8
8
 
9
9
  describe('Storefront API Summary', () => {
10
- it('can fetch preview', async () => {
11
- const options = {
12
- websiteId: 'test-website-id',
13
- items: [
14
- {
15
- planId: 'test-plan-id',
16
- quantity: 1
17
- }
18
- ]
19
- };
20
- const testSummary = {
21
- currency: 'USD',
22
- lineItems: [
23
- {
24
- description: 'test-plan-id-1',
25
- planId: 'test-plan-id-1',
26
- quantity: 1
27
- }
28
- ]
29
- };
10
+ it('can fetch preview', async () => {
11
+ const options = {
12
+ websiteId: 'test-website-id',
13
+ items: [
14
+ {
15
+ planId: 'test-plan-id',
16
+ quantity: 1,
17
+ },
18
+ ],
19
+ };
20
+ const testSummary = {
21
+ currency: 'USD',
22
+ lineItems: [
23
+ {
24
+ description: 'test-plan-id-1',
25
+ planId: 'test-plan-id-1',
26
+ quantity: 1,
27
+ },
28
+ ],
29
+ };
30
30
 
31
- when(post(`${storefrontURL}/preview-purchase`)).thenReturn(ok(testSummary));
31
+ when(post(`${storefrontURL}/preview-purchase`)).thenReturn(
32
+ ok(testSummary),
33
+ );
32
34
 
33
- const instance = StorefontTestingInstance({
34
- options
35
- });
35
+ const instance = StorefontTestingInstance({
36
+ options,
37
+ });
36
38
 
37
- vi.spyOn(instance.storefront.purchase, 'preview');
39
+ vi.spyOn(instance.storefront.purchase, 'preview');
38
40
 
39
- const response = await fetchSummary({ state: instance });
41
+ const response = await fetchSummary({ state: instance });
40
42
 
41
- expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
42
- expect(instance.storefront.purchase.preview).toBeCalledWith({
43
- data: expect.objectContaining({
44
- items: options.items,
45
- websiteId: options.websiteId
46
- })
43
+ expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
44
+ expect(instance.storefront.purchase.preview).toBeCalledWith({
45
+ data: expect.objectContaining({
46
+ items: options.items,
47
+ websiteId: options.websiteId,
48
+ }),
49
+ });
50
+ expect(response).toBeInstanceOf(SummaryModel);
51
+ expect(response).toEqual(new SummaryModel(testSummary));
47
52
  });
48
- expect(response).toBeInstanceOf(SummaryModel);
49
- expect(response).toEqual(new SummaryModel(testSummary));
50
- });
51
53
 
52
- it('Adds billing address to preview payload', async () => {
53
- const options = {
54
- websiteId: 'test-website-id',
55
- items: [
56
- {
57
- planId: 'test-plan-id',
58
- quantity: 1
59
- }
60
- ]
61
- };
62
- const billingAddress = {
63
- firstName: 'Test',
64
- lastName: 'Customer'
65
- };
66
- const instance = StorefontTestingInstance({
67
- options
68
- });
54
+ it('Adds billing address to preview payload', async () => {
55
+ const options = {
56
+ websiteId: 'test-website-id',
57
+ items: [
58
+ {
59
+ planId: 'test-plan-id',
60
+ quantity: 1,
61
+ },
62
+ ],
63
+ };
64
+ const billingAddress = {
65
+ firstName: 'Test',
66
+ lastName: 'Customer',
67
+ };
68
+ const instance = StorefontTestingInstance({
69
+ options,
70
+ });
69
71
 
70
- vi.spyOn(instance.storefront.purchase, 'preview');
72
+ vi.spyOn(instance.storefront.purchase, 'preview');
71
73
 
72
- await fetchSummary({
73
- data: {
74
- billingAddress
75
- },
76
- state: instance
77
- });
74
+ await fetchSummary({
75
+ data: {
76
+ billingAddress,
77
+ },
78
+ state: instance,
79
+ });
78
80
 
79
- expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
80
- expect(instance.storefront.purchase.preview).toBeCalledWith({
81
- data: expect.objectContaining({
82
- items: options.items,
83
- websiteId: options.websiteId,
84
- billingAddress
85
- })
81
+ expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
82
+ expect(instance.storefront.purchase.preview).toBeCalledWith({
83
+ data: expect.objectContaining({
84
+ items: options.items,
85
+ websiteId: options.websiteId,
86
+ billingAddress,
87
+ }),
88
+ });
86
89
  });
87
- });
88
90
 
89
- it('Adds delivery address to preview payload', async () => {
90
- const options = {
91
- websiteId: 'test-website-id',
92
- items: [
93
- {
94
- planId: 'test-plan-id',
95
- quantity: 1
96
- }
97
- ]
98
- };
99
- const deliveryAddress = {
100
- firstName: 'Test',
101
- lastName: 'Customer'
102
- };
103
- const instance = StorefontTestingInstance({
104
- options
105
- });
91
+ it('Adds delivery address to preview payload', async () => {
92
+ const options = {
93
+ websiteId: 'test-website-id',
94
+ items: [
95
+ {
96
+ planId: 'test-plan-id',
97
+ quantity: 1,
98
+ },
99
+ ],
100
+ };
101
+ const deliveryAddress = {
102
+ firstName: 'Test',
103
+ lastName: 'Customer',
104
+ };
105
+ const instance = StorefontTestingInstance({
106
+ options,
107
+ });
106
108
 
107
- vi.spyOn(instance.storefront.purchase, 'preview');
109
+ vi.spyOn(instance.storefront.purchase, 'preview');
108
110
 
109
- await fetchSummary({
110
- data: {
111
- deliveryAddress
112
- },
113
- state: instance
114
- });
111
+ await fetchSummary({
112
+ data: {
113
+ deliveryAddress,
114
+ },
115
+ state: instance,
116
+ });
115
117
 
116
- expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
117
- expect(instance.storefront.purchase.preview).toBeCalledWith({
118
- data: expect.objectContaining({
119
- items: options.items,
120
- websiteId: options.websiteId,
121
- deliveryAddress
122
- })
118
+ expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
119
+ expect(instance.storefront.purchase.preview).toBeCalledWith({
120
+ data: expect.objectContaining({
121
+ items: options.items,
122
+ websiteId: options.websiteId,
123
+ deliveryAddress,
124
+ }),
125
+ });
123
126
  });
124
- });
125
127
 
126
- it('should throw errors with no options', async () => {
127
- const noConfigOrOptionsInstance = StorefontTestingInstance({
128
- options: null
128
+ it('should throw errors with no options', async () => {
129
+ const noConfigOrOptionsInstance = StorefontTestingInstance({
130
+ options: null,
131
+ });
132
+ await expectConfigurationError(
133
+ fetchSummary({ state: noConfigOrOptionsInstance }),
134
+ );
129
135
  });
130
- await expectConfigurationError(
131
- fetchSummary({ state: noConfigOrOptionsInstance })
132
- );
133
- });
134
136
  });
@@ -3,10 +3,10 @@ import { Endpoint } from './index';
3
3
  import state from '../state';
4
4
 
5
5
  export async function fetchTransaction({ data = null }) {
6
- return Endpoint(async () => {
7
- state.storefront.setSessionToken(state.options.jwt);
8
- const {fields} = await state.storefront.transactions.get(data);
6
+ return Endpoint(async () => {
7
+ state.storefront.setSessionToken(state.options.jwt);
8
+ const { fields } = await state.storefront.transactions.get(data);
9
9
 
10
- return new TransactionModel(fields);
11
- });
12
- }
10
+ return new TransactionModel(fields);
11
+ });
12
+ }