@rebilly/instruments 3.19.0-beta.0 → 3.21.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebilly/instruments",
3
- "version": "3.19.0-beta.0",
3
+ "version": "3.21.0-beta.0",
4
4
  "author": "Rebilly",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "lodash.kebabcase": "^4.1.1",
24
24
  "lodash.merge": "^4.6.2",
25
25
  "popostmate": "^1.6.4",
26
- "rebilly-js-sdk": "^47.13.2",
26
+ "rebilly-js-sdk": "^47.14.2",
27
27
  "values.js": "^2.0.0"
28
28
  },
29
29
  "devDependencies": {
@@ -2273,6 +2273,25 @@
2273
2273
  }
2274
2274
  ]
2275
2275
  },
2276
+ {
2277
+ "apiName": "SafetyPay",
2278
+ "name": "SafetyPay",
2279
+ "landscapeLogo": null,
2280
+ "portraitLogo": null,
2281
+ "summary": "SafetyPay operates the largest network of banks and cash collection points in Latin America, the result of 10+ years effort, with presence in 16 countries consolidated with 380 bank partners and 180,000 collection points.\n",
2282
+ "description": "SafetyPay operates the largest network of banks and cash collection points in Latin America, the result of 10+ years effort, with presence in 16 countries consolidated with 380 bank partners and 180,000 collection points.\n",
2283
+ "countries": {
2284
+ "mode": "unknown",
2285
+ "values": []
2286
+ },
2287
+ "storefrontEnabled": true,
2288
+ "_links": [
2289
+ {
2290
+ "rel": "self",
2291
+ "href": "https://api.rebilly.com/payment-methods/SafetyPay"
2292
+ }
2293
+ ]
2294
+ },
2276
2295
  {
2277
2296
  "apiName": "Siirto",
2278
2297
  "name": "Siirto",
@@ -1,10 +1,11 @@
1
1
  import { collectData } from '@rebilly/risk-data-collector';
2
2
  import { fetchProductsFromPlans } from '../../storefront/fetch-products-from-plans';
3
+ import { fetchPlansFromAddonsBumpOffers } from '../../storefront/fetch-plans-from-addons-bumpOffers';
3
4
  import { fetchReadyToPay } from '../../storefront/ready-to-pay';
4
5
  import { fetchSummary } from '../../storefront/summary';
5
6
  import { fetchInvoiceAndProducts as FetchInvoiceAndProducts } from '../../storefront/invoices';
6
7
  import { fetchTransaction as FetchTransaction } from '../../storefront/transactions';
7
- import { fetchAccount as FetchAccount } from '../../storefront/account';
8
+ import { fetchAccountAndWebsite as FetchAccountAndWebsite } from '../../storefront/account-and-website';
8
9
  import { fetchPaymentInstrument as FetchInstruments } from '../../storefront/payment-instruments';
9
10
 
10
11
  export class DataInstance {
@@ -21,6 +22,7 @@ export class DataInstance {
21
22
 
22
23
  this.money = state.options?.money || null;
23
24
  this.couponIds = [];
25
+ this.addons = [];
24
26
  }
25
27
 
26
28
  get amountAndCurrency() {
@@ -122,7 +124,7 @@ export async function fetchData({
122
124
  // Dependency injectable functions
123
125
  fetchInvoiceAndProducts = FetchInvoiceAndProducts,
124
126
  fetchTransaction = FetchTransaction,
125
- fetchAccount = FetchAccount,
127
+ fetchAccountAndWebsite = FetchAccountAndWebsite,
126
128
  fetchInstruments = FetchInstruments
127
129
  }) {
128
130
  try {
@@ -133,8 +135,9 @@ export async function fetchData({
133
135
  let accountPromise = Promise.resolve(null);
134
136
  let availableInstrumentsPromise = null;
135
137
  if (state.options?.jwt) {
136
- accountPromise = fetchAccount({state}).then(account => {
138
+ accountPromise = fetchAccountAndWebsite({state}).then(({account, website}) => {
137
139
  state.data.account = account;
140
+ state.data.website = website;
138
141
  });
139
142
  availableInstrumentsPromise = fetchInstruments({state});
140
143
  }
@@ -174,15 +177,22 @@ export async function fetchData({
174
177
  productsPromise = fetchProductsFromPlans({ state });
175
178
  }
176
179
 
180
+ let plansPromise = new Promise((resolve) => resolve([]));
181
+ if (state.options?.addons || state.options?.bumpOffers) {
182
+ plansPromise = fetchPlansFromAddonsBumpOffers({ state });
183
+ }
184
+
177
185
  const [
178
186
  readyToPay,
179
187
  previewPurchase,
180
188
  products,
189
+ plans,
181
190
  availableInstruments
182
191
  ] = await Promise.all([
183
192
  readyToPayPromise,
184
193
  previewPurchasePromise,
185
194
  productsPromise,
195
+ plansPromise,
186
196
  availableInstrumentsPromise
187
197
  ]);
188
198
 
@@ -191,6 +201,7 @@ export async function fetchData({
191
201
  readyToPay,
192
202
  previewPurchase,
193
203
  products,
204
+ plans,
194
205
  availableInstruments
195
206
  });
196
207
  } catch(error) {
@@ -75,7 +75,7 @@ describe('fetchData function', () => {
75
75
  });
76
76
 
77
77
  it('Should fetch account when JWT is supplied', async () => {
78
- const mockFetchAccount = jest.fn();
78
+ const mockFetchAccountAndWebsite = jest.fn();
79
79
  const accountState = {
80
80
  options: {
81
81
  jwt: 'TEST_JWT'
@@ -84,23 +84,23 @@ describe('fetchData function', () => {
84
84
 
85
85
  await fetchData({
86
86
  state: accountState,
87
- fetchAccount: mockFetchAccount,
87
+ fetchAccountAndWebsite: mockFetchAccountAndWebsite,
88
88
  });
89
89
 
90
- expect(mockFetchAccount).toBeCalledTimes(1);
90
+ expect(mockFetchAccountAndWebsite).toBeCalledTimes(1);
91
91
  });
92
92
 
93
93
  it('Should not fetch account when there JWT is not supplied', async () => {
94
- const mockFetchAccount = jest.fn();
94
+ const mockFetchAccountAndWebsite = jest.fn();
95
95
 
96
96
  await fetchData({
97
97
  state: {
98
98
  options: {}
99
99
  },
100
- fetchAccount: mockFetchAccount,
100
+ fetchAccountAndWebsite: mockFetchAccountAndWebsite,
101
101
  });
102
102
 
103
- expect(mockFetchAccount).toBeCalledTimes(0);
103
+ expect(mockFetchAccountAndWebsite).toBeCalledTimes(0);
104
104
  });
105
105
  });
106
106
 
@@ -7,6 +7,8 @@ export const defaults = {
7
7
  theme: {
8
8
  labels: 'stacked'
9
9
  },
10
+ addons: [],
11
+ bumpOffers: [],
10
12
  paymentInstruments: {
11
13
  address: {
12
14
  name: 'default',
@@ -136,6 +138,7 @@ export default ({
136
138
  // Add optional key's
137
139
  [
138
140
  'items',
141
+ 'bumpOffers',
139
142
  'money',
140
143
  'invoiceId',
141
144
  'transactionId',
@@ -147,5 +150,12 @@ export default ({
147
150
  }
148
151
  });
149
152
 
153
+ // only add "addons" if items are available
154
+ if (combinedOptions.items) {
155
+ if (options.addons) {
156
+ combinedOptions.addons = options.addons;
157
+ }
158
+ }
159
+
150
160
  return combinedOptions;
151
161
  }
@@ -74,6 +74,14 @@ export async function makePurchase({ state, payload }) {
74
74
  data.couponIds = state.data.couponIds
75
75
  }
76
76
 
77
+ if (state.options.addons && state.data.addons && Array.isArray(state.data.addons)) {
78
+ state.options.addons.forEach(addon => {
79
+ if (state.data.addons.includes(addon.planId)) {
80
+ data.items.push(addon);
81
+ }
82
+ })
83
+ }
84
+
77
85
  const { fields } = await postPurchase({
78
86
  state,
79
87
  data
@@ -0,0 +1,15 @@
1
+ import AccountModel from './models/account-model';
2
+ import WebsiteModel from './models/website-model';
3
+ import { Endpoint } from './index';
4
+
5
+ export async function fetchAccountAndWebsite({ state = null }) {
6
+ return Endpoint({state}, async () => {
7
+ state.storefront.setSessionToken(state.options.jwt);
8
+ const {fields} = await state.storefront.account.get({expand: 'website'});
9
+
10
+ return {
11
+ website: new WebsiteModel(fields._embedded?.website),
12
+ account: new AccountModel(fields),
13
+ }
14
+ });
15
+ }
@@ -0,0 +1,73 @@
1
+ import { StorefontTestingInstance } from 'tests/mocks/storefront-mock';
2
+ import { ok, get } from 'msw-when-then';
3
+ import { when } from 'tests/msw/server';
4
+ import { storefrontURL } from 'tests/mocks/storefront-api-mock';
5
+ import { fetchAccountAndWebsite } from './account-and-website';
6
+ import AccountModel, { AddressModel } from './models/account-model';
7
+ import WebsiteModel from './models/website-model';
8
+
9
+ describe('Storefront API Account', () => {
10
+ it('should handle fetch a customer with a null primary address', async () => {
11
+ const options = {
12
+ jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzYjBkNTRkOS0xNmM4LTRlZDAtYjljMy01ODAyZmQ4YzE2ZTIiLCJleHAiOjE2ODY2OTc0MTQuODQxMjUsImlhdCI6MTY1NTE2MTQxNC44Nzk4OTEsImFjbCI6W3sic2NvcGUiOnsib3JnYW5pemF0aW9uSWQiOlsiMzY0NEFGTEFKMUciXSwicGF5bWVudE1ldGhvZHMiOlsicGF5bWVudC1jYXJkIl19LCJwZXJtaXNzaW9ucyI6WzI4NCwyODYsNDE0LDQxNSw0MzQsNDExLDQxMiw0MTMsNDI0LDQyNSw0MjYsNDI3LDQyOCw0MjksNDA5LDQxMCw0MDEsNDAyLDQzMyw0ODgsNDg3XX1dLCJjbGFpbXMiOnsid2Vic2l0ZUlkIjoiZGVtby13ZWJzaXRlIiwidHJhbnNhY3Rpb25JZCI6IjRiZDE3N2NmLTFlY2EtNDA2Yy04OWI0LTEzYzMzODk5NzlmMCIsInBheW1lbnRNZXRob2RzIjpbInBheW1lbnQtY2FyZCJdfSwibWVyY2hhbnQiOiIzNjQ0QUZMQUoxRyIsImN1c3RvbWVyIjp7ImlkIjoidGVzdC1jdXN0b21lci1pZCIsIm5hbWUiOiJUZXN0IEN1c3RvbWVyIE5hbWUiLCJjcmVhdGVkVGltZSI6IjIwMjItMDctMTRUMDA6MDA6MDArMDA6MDAifX0.VPue9QBhRGe3vvncaD47w84N8Bv2hEeShUl6SlNqoOQ',
13
+ items: [
14
+ {
15
+ planId: 'test-plan-id',
16
+ quantity: 1
17
+ }
18
+ ]
19
+ };
20
+
21
+ when(get(`${storefrontURL}/acount`)).thenReturn(
22
+ ok({
23
+ defaultPaymentInstrument: null,
24
+ id: "test-customer-id",
25
+ primaryAddress: null,
26
+ websiteId: "test-website-id",
27
+ })
28
+ );
29
+
30
+ const instance = StorefontTestingInstance({
31
+ options
32
+ });
33
+
34
+ jest.spyOn(instance.storefront.account, 'get');
35
+
36
+ const response = await fetchAccountAndWebsite({ state: instance });
37
+ expect(response.account.address).toEqual(new AddressModel({}));
38
+ })
39
+
40
+ it('should return an object with account and website', async () => {
41
+ const options = {
42
+ jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzYjBkNTRkOS0xNmM4LTRlZDAtYjljMy01ODAyZmQ4YzE2ZTIiLCJleHAiOjE2ODY2OTc0MTQuODQxMjUsImlhdCI6MTY1NTE2MTQxNC44Nzk4OTEsImFjbCI6W3sic2NvcGUiOnsib3JnYW5pemF0aW9uSWQiOlsiMzY0NEFGTEFKMUciXSwicGF5bWVudE1ldGhvZHMiOlsicGF5bWVudC1jYXJkIl19LCJwZXJtaXNzaW9ucyI6WzI4NCwyODYsNDE0LDQxNSw0MzQsNDExLDQxMiw0MTMsNDI0LDQyNSw0MjYsNDI3LDQyOCw0MjksNDA5LDQxMCw0MDEsNDAyLDQzMyw0ODgsNDg3XX1dLCJjbGFpbXMiOnsid2Vic2l0ZUlkIjoiZGVtby13ZWJzaXRlIiwidHJhbnNhY3Rpb25JZCI6IjRiZDE3N2NmLTFlY2EtNDA2Yy04OWI0LTEzYzMzODk5NzlmMCIsInBheW1lbnRNZXRob2RzIjpbInBheW1lbnQtY2FyZCJdfSwibWVyY2hhbnQiOiIzNjQ0QUZMQUoxRyIsImN1c3RvbWVyIjp7ImlkIjoidGVzdC1jdXN0b21lci1pZCIsIm5hbWUiOiJUZXN0IEN1c3RvbWVyIE5hbWUiLCJjcmVhdGVkVGltZSI6IjIwMjItMDctMTRUMDA6MDA6MDArMDA6MDAifX0.VPue9QBhRGe3vvncaD47w84N8Bv2hEeShUl6SlNqoOQ',
43
+ items: [
44
+ {
45
+ planId: 'test-plan-id',
46
+ quantity: 1
47
+ }
48
+ ]
49
+ };
50
+
51
+ when(get(`${storefrontURL}/acount`)).thenReturn(
52
+ ok({
53
+ defaultPaymentInstrument: null,
54
+ id: "test-customer-id",
55
+ primaryAddress: null,
56
+ websiteId: "test-website-id",
57
+ _embedded: {
58
+ website: {},
59
+ }
60
+ })
61
+ );
62
+
63
+ const instance = StorefontTestingInstance({
64
+ options
65
+ });
66
+
67
+ jest.spyOn(instance.storefront.account, 'get');
68
+
69
+ const response = await fetchAccountAndWebsite({ state: instance });
70
+ expect(response.account instanceof(AccountModel)).toBe(true);
71
+ expect(response.website instanceof(WebsiteModel)).toBe(true);
72
+ })
73
+ });
@@ -0,0 +1,27 @@
1
+ import PlanModel from './models/plan-model';
2
+ import { Endpoint } from './index';
3
+
4
+ export async function fetchPlansFromAddonsBumpOffers({ state = {} }) {
5
+ return Endpoint({state}, async () => {
6
+ let ids = [];
7
+
8
+ if (state.options?.addons) {
9
+ ids = ids.concat(state.options.addons
10
+ .map((item) => item.planId));
11
+ }
12
+
13
+ if (state.options?.bumpOffers) {
14
+ ids = ids.concat(state.options.bumpOffers
15
+ .map((item) => item.planId));
16
+ }
17
+
18
+ if (ids.length > 0) {
19
+ const { items: planItems } = await state.storefront.plans.getAll({
20
+ filter: `id:${ids.join(',')}`
21
+ });
22
+ return planItems.map(({fields}) => new PlanModel(fields).toPayload());
23
+ }
24
+
25
+ return [];
26
+ });
27
+ }
@@ -15,9 +15,20 @@ export async function fetchProductsFromPlans({ state = {} }) {
15
15
  };
16
16
 
17
17
  if (lineItems.length) {
18
- filterByPlanId.filter = `id:${lineItems
19
- .map((item) => item.planId)
20
- .join(',')}`;
18
+ let ids = lineItems
19
+ .map((item) => item.planId);
20
+
21
+ if (state.options?.addons) {
22
+ ids = ids.concat(state.options.addons
23
+ .map((item) => item.planId));
24
+ }
25
+
26
+ if (state.options?.bumpOffers) {
27
+ ids = ids.concat(state.options.bumpOffers
28
+ .map((item) => item.planId));
29
+ }
30
+
31
+ filterByPlanId.filter = `id:${[...new Set(ids)].join(',')}`;
21
32
  }
22
33
 
23
34
  // Only fetch plans if we have specific plans to fetch
@@ -28,7 +39,15 @@ export async function fetchProductsFromPlans({ state = {} }) {
28
39
  filterByPlanId
29
40
  );
30
41
 
31
- return planItems.map(({ fields }) => new ProductModel(fields._embedded.product));
42
+ const products = []
43
+ planItems
44
+ .map(({ fields }) => new ProductModel(fields._embedded.product))
45
+ .forEach(product => {
46
+ if (products.every(item => item.id !== product.id)) {
47
+ products.push(product)
48
+ }
49
+ });
50
+ return products;
32
51
  } catch(e) {
33
52
  // Ignore and return empty items
34
53
  };
@@ -1,3 +1,85 @@
1
1
  import BaseModel from './base-model';
2
2
 
3
- export default class PlanModel extends BaseModel {}
3
+ export class PlanPricingBracketModel {
4
+ constructor ({
5
+ maxQuantity = null,
6
+ price = null
7
+ } = {}) {
8
+ this.maxQuantity = maxQuantity || Number.MAX_SAFE_INTEGER;
9
+ this.price = !Number.isNaN(parseFloat(price)) ? parseFloat(price) : null;
10
+ }
11
+ }
12
+
13
+ export class PlanPricingModel {
14
+ static SimpleFormulas = {
15
+ fixedFee: 'fixed-fee',
16
+ flatRate: 'flat-rate'
17
+ };
18
+
19
+ static BracketFormulas = {
20
+ stairstep: 'stairstep',
21
+ tiered: 'tiered',
22
+ volume: 'volume'
23
+ };
24
+
25
+ static Formulas = {
26
+ ...PlanPricingModel.SimpleFormulas,
27
+ ...PlanPricingModel.BracketFormulas
28
+ };
29
+
30
+ constructor ({
31
+ formula = PlanPricingModel.Formulas.fixedFee,
32
+ price = 0,
33
+ maxQuantity = null,
34
+ brackets = []
35
+ } = {}) {
36
+ this.formula = formula;
37
+
38
+ switch (this.formula) {
39
+ case PlanPricingModel.Formulas.stairstep:
40
+ case PlanPricingModel.Formulas.tiered:
41
+ case PlanPricingModel.Formulas.volume:
42
+ this.brackets = brackets.map(bracket => new PlanPricingBracketModel(bracket));
43
+ break;
44
+ case PlanPricingModel.Formulas.flatRate:
45
+ this.price = !Number.isNaN(parseFloat(price)) ? parseFloat(price) : null;
46
+ this.maxQuantity = maxQuantity;
47
+ break;
48
+ case PlanPricingModel.Formulas.fixedFee:
49
+ default:
50
+ this.price = !Number.isNaN(parseFloat(price)) ? parseFloat(price) : null;
51
+ break;
52
+ }
53
+ }
54
+
55
+ get isSimple() {
56
+ return Object.values(PlanPricingModel.SimpleFormulas).includes(this.formula);
57
+ }
58
+
59
+ get isBracket () {
60
+ return Object.values(PlanPricingModel.BracketFormulas).includes(this.formula);
61
+ }
62
+
63
+ toPayload() {
64
+ return {
65
+ ...this,
66
+ isSimple: this.isSimple,
67
+ isBracket: this.isBracket,
68
+ }
69
+ }
70
+ }
71
+
72
+ export default class PlanModel extends BaseModel {
73
+ constructor(fields = {}) {
74
+ super(fields);
75
+
76
+ this.pricing = new PlanPricingModel(fields.pricing || {});
77
+ }
78
+
79
+ toPayload() {
80
+ return {
81
+ ...this,
82
+ pricing: this.pricing.toPayload(),
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,3 @@
1
+ import BaseModel from './base-model';
2
+
3
+ export default class WebsiteModel extends BaseModel {}
@@ -18,6 +18,10 @@ export async function fetchSummary({ data = null, state = null } = {}) {
18
18
  planId: item.planId,
19
19
  quantity: item.quantity,
20
20
  }));
21
+
22
+ if (state.data?.addons > 0) {
23
+ payload.data.items.concat(state.data.addons)
24
+ }
21
25
  }
22
26
 
23
27
  if (state.data?.amountAndCurrency) {
@@ -0,0 +1,21 @@
1
+ export function updateAddonsHandler(iframe) {
2
+ iframe.component.on(`${iframe.name}-update-addons`, async ({addons, previewPurchase}) => {
3
+ const addonPlanIds = addons.map(addon => addon.planId);
4
+ iframe.state.data.addons = addonPlanIds;
5
+ iframe.state.data.previewPurchase = previewPurchase;
6
+
7
+ iframe.state.data.previewPurchase.addonLineItems = iframe.state.data.previewPurchase.lineItems
8
+ .filter(item => addonPlanIds.includes(item.planId));
9
+ iframe.state.data.previewPurchase.lineItems = iframe.state.data.previewPurchase.lineItems
10
+ .filter(item => !addonPlanIds.includes(item.planId));
11
+
12
+ const updateModel = {
13
+ data: iframe.state.data.toPostmatesModel(),
14
+ options: iframe.state.options
15
+ }
16
+ if (iframe.state.iframeComponents.summary) {
17
+ iframe.state.iframeComponents.summary.component.call('update', updateModel);
18
+ }
19
+ iframe.state.iframeComponents.form.component.call('update', updateModel);
20
+ });
21
+ }
@@ -3,6 +3,7 @@ import BaseIframe from './base-iframe';
3
3
  import { resizeComponentHandler } from './events/resize-component-handler';
4
4
  import { dispatchEventHandler } from './events/dispatch-event-handler';
5
5
  import { updateCouponsHandler } from './events/update-coupons-handler';
6
+ import { updateAddonsHandler } from './events/update-addons-handler';
6
7
  import { showErrorHandler } from './events/show-error-handler';
7
8
  import { stopLoaderHandler } from './events/stop-loader-handler';
8
9
 
@@ -17,5 +18,6 @@ export class ViewIframe extends BaseIframe {
17
18
  stopLoaderHandler(this, { loader });
18
19
  showErrorHandler(this);
19
20
  updateCouponsHandler(this);
21
+ updateAddonsHandler(this);
20
22
  }
21
23
  }
@@ -1,11 +0,0 @@
1
- import AccountModel from './models/account-model';
2
- import { Endpoint } from './index';
3
-
4
- export async function fetchAccount({ state = null }) {
5
- return Endpoint({state}, async () => {
6
- state.storefront.setSessionToken(state.options.jwt);
7
- const {fields} = await state.storefront.account.get();
8
-
9
- return new AccountModel(fields);
10
- });
11
- }
@@ -1,39 +0,0 @@
1
- import { StorefontTestingInstance } from 'tests/mocks/storefront-mock';
2
- import { ok, get } from 'msw-when-then';
3
- import { when } from 'tests/msw/server';
4
- import { storefrontURL } from 'tests/mocks/storefront-api-mock';
5
- import { fetchAccount } from './account';
6
- import { AddressModel } from './models/account-model';
7
-
8
- describe('Storefront API Account', () => {
9
- it('should handle fetch a customer with a null primary address', async () => {
10
- const options = {
11
- jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzYjBkNTRkOS0xNmM4LTRlZDAtYjljMy01ODAyZmQ4YzE2ZTIiLCJleHAiOjE2ODY2OTc0MTQuODQxMjUsImlhdCI6MTY1NTE2MTQxNC44Nzk4OTEsImFjbCI6W3sic2NvcGUiOnsib3JnYW5pemF0aW9uSWQiOlsiMzY0NEFGTEFKMUciXSwicGF5bWVudE1ldGhvZHMiOlsicGF5bWVudC1jYXJkIl19LCJwZXJtaXNzaW9ucyI6WzI4NCwyODYsNDE0LDQxNSw0MzQsNDExLDQxMiw0MTMsNDI0LDQyNSw0MjYsNDI3LDQyOCw0MjksNDA5LDQxMCw0MDEsNDAyLDQzMyw0ODgsNDg3XX1dLCJjbGFpbXMiOnsid2Vic2l0ZUlkIjoiZGVtby13ZWJzaXRlIiwidHJhbnNhY3Rpb25JZCI6IjRiZDE3N2NmLTFlY2EtNDA2Yy04OWI0LTEzYzMzODk5NzlmMCIsInBheW1lbnRNZXRob2RzIjpbInBheW1lbnQtY2FyZCJdfSwibWVyY2hhbnQiOiIzNjQ0QUZMQUoxRyIsImN1c3RvbWVyIjp7ImlkIjoidGVzdC1jdXN0b21lci1pZCIsIm5hbWUiOiJUZXN0IEN1c3RvbWVyIE5hbWUiLCJjcmVhdGVkVGltZSI6IjIwMjItMDctMTRUMDA6MDA6MDArMDA6MDAifX0.VPue9QBhRGe3vvncaD47w84N8Bv2hEeShUl6SlNqoOQ',
12
- websiteId: 'test-website-id',
13
- items: [
14
- {
15
- planId: 'test-plan-id',
16
- quantity: 1
17
- }
18
- ]
19
- };
20
-
21
- when(get(`${storefrontURL}/acount`)).thenReturn(
22
- ok({
23
- defaultPaymentInstrument: null,
24
- id: "test-customer-id",
25
- primaryAddress: null,
26
- websiteId: "test-website-id",
27
- })
28
- );
29
-
30
- const instance = StorefontTestingInstance({
31
- options
32
- });
33
-
34
- jest.spyOn(instance.storefront.account, 'get');
35
-
36
- const response = await fetchAccount({ state: instance });
37
- expect(response.address).toEqual(new AddressModel({}));
38
- })
39
- });