@nuskin/contentstack-lib 2.1.0-pa-1117.6 → 2.1.0-pa-1117.7
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/__tests__/api.spec.js +62 -16
- package/docs/CHANGELOG.md +1 -1
- package/package.json +1 -1
- package/src/api.js +1 -1
package/__tests__/api.spec.js
CHANGED
|
@@ -157,9 +157,9 @@ describe("ContentstackApi", () => {
|
|
|
157
157
|
global.window = Object.create(window);
|
|
158
158
|
global.window.location = { hostname };
|
|
159
159
|
const {getStack} = require('../src/api');
|
|
160
|
-
getStack(
|
|
160
|
+
getStack();
|
|
161
161
|
expect(mockStack).toHaveBeenCalledWith({api_key: csCfg.apiKey, delivery_token: csCfg.deliveryToken, environment: csCfg.environment});
|
|
162
|
-
})
|
|
162
|
+
});
|
|
163
163
|
});
|
|
164
164
|
|
|
165
165
|
test('extractAddressFormFields maps address form field entries', () => {
|
|
@@ -204,6 +204,12 @@ describe("ContentstackApi", () => {
|
|
|
204
204
|
]);
|
|
205
205
|
});
|
|
206
206
|
|
|
207
|
+
test('extractAddressFormFields returns an empty list when no entries are provided', () => {
|
|
208
|
+
const {getStack} = require('../src/api');
|
|
209
|
+
const Stack = getStack('dev');
|
|
210
|
+
expect(Stack.extractAddressFormFields()).toStrictEqual([]);
|
|
211
|
+
});
|
|
212
|
+
|
|
207
213
|
test('getAddressForms maps address_elements', async () => {
|
|
208
214
|
mockPromiseResult.mockResolvedValueOnce([[
|
|
209
215
|
{
|
|
@@ -277,6 +283,21 @@ describe("ContentstackApi", () => {
|
|
|
277
283
|
]);
|
|
278
284
|
});
|
|
279
285
|
|
|
286
|
+
test('getAddressForms returns an empty list when no forms are found', async () => {
|
|
287
|
+
mockPromiseResult.mockResolvedValueOnce([undefined]);
|
|
288
|
+
const {getStack} = require('../src/api');
|
|
289
|
+
const Stack = getStack('dev');
|
|
290
|
+
await expect(Stack.getAddressForms(['Unknown'])).resolves.toStrictEqual([]);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test('getSingletonEntries maps language code in to id', async () => {
|
|
294
|
+
mockSinglePromiseResult.mockResolvedValueOnce(singleCheckoutAdrStrings);
|
|
295
|
+
const {getStack} = require('../src/api');
|
|
296
|
+
const Stack = getStack('dev');
|
|
297
|
+
await Stack.getSingletonEntries({contentTypeUIDs: ['checkout_adr_strings'], language: 'in'});
|
|
298
|
+
expect(mockSinglePromiseResult).toHaveBeenCalled();
|
|
299
|
+
});
|
|
300
|
+
|
|
280
301
|
test('getShippingAddressForms maps nested address form fields', async () => {
|
|
281
302
|
mockPromiseResult.mockResolvedValueOnce([[
|
|
282
303
|
{
|
|
@@ -296,13 +317,15 @@ describe("ContentstackApi", () => {
|
|
|
296
317
|
}
|
|
297
318
|
],
|
|
298
319
|
pre_address_fields: [addressFormFieldEntries[0]],
|
|
299
|
-
address_form:
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
320
|
+
address_form: [
|
|
321
|
+
{
|
|
322
|
+
title: 'default',
|
|
323
|
+
address_elements: addressFormFieldEntries,
|
|
324
|
+
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
325
|
+
verify_after_autocomplete: true,
|
|
326
|
+
wrap_address1_to_address2: false
|
|
327
|
+
}
|
|
328
|
+
],
|
|
306
329
|
post_address_fields: [addressFormFieldEntries[1]]
|
|
307
330
|
}
|
|
308
331
|
]]);
|
|
@@ -382,13 +405,15 @@ describe("ContentstackApi", () => {
|
|
|
382
405
|
}
|
|
383
406
|
],
|
|
384
407
|
pre_address_fields: [addressFormFieldEntries[0]],
|
|
385
|
-
address_form:
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
408
|
+
address_form: [
|
|
409
|
+
{
|
|
410
|
+
title: 'default',
|
|
411
|
+
address_elements: addressFormFieldEntries,
|
|
412
|
+
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
413
|
+
verify_after_autocomplete: true,
|
|
414
|
+
wrap_address1_to_address2: false
|
|
415
|
+
}
|
|
416
|
+
],
|
|
392
417
|
post_address_fields: [addressFormFieldEntries[1]]
|
|
393
418
|
}
|
|
394
419
|
]]);
|
|
@@ -448,4 +473,25 @@ describe("ContentstackApi", () => {
|
|
|
448
473
|
}
|
|
449
474
|
]);
|
|
450
475
|
});
|
|
476
|
+
|
|
477
|
+
test('getShippingAddressForms returns empty nested data when optional references are missing', async () => {
|
|
478
|
+
mockPromiseResult.mockResolvedValueOnce([[
|
|
479
|
+
{
|
|
480
|
+
countries: [],
|
|
481
|
+
pre_address_fields: undefined,
|
|
482
|
+
address_form: [],
|
|
483
|
+
post_address_fields: undefined
|
|
484
|
+
}
|
|
485
|
+
]]);
|
|
486
|
+
const {getStack} = require('../src/api');
|
|
487
|
+
const Stack = getStack('dev');
|
|
488
|
+
await expect(Stack.getShippingAddressForms(['Unknown'])).resolves.toStrictEqual([
|
|
489
|
+
{
|
|
490
|
+
countries: [],
|
|
491
|
+
pre_address_fields: [],
|
|
492
|
+
address_form: undefined,
|
|
493
|
+
post_address_fields: []
|
|
494
|
+
}
|
|
495
|
+
]);
|
|
496
|
+
});
|
|
451
497
|
});
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# [2.1.0-pa-1117.
|
|
1
|
+
# [2.1.0-pa-1117.7](https://code.tls.nuskin.io/ns-am/utility/npm/contentstack-lib/compare/v2.1.0-pa-1117.6...v2.1.0-pa-1117.7) (2026-04-08)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuskin/contentstack-lib",
|
|
3
|
-
"version": "2.1.0-pa-1117.
|
|
3
|
+
"version": "2.1.0-pa-1117.7",
|
|
4
4
|
"description": "This project contains configuration and api code to access Contentstack, to be shared between the backend (AWS Lambda) and frontend (Vue, etc).",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
package/src/api.js
CHANGED
|
@@ -246,7 +246,7 @@ const getShippingAddressForms = async (countries, camelcase = false) => {
|
|
|
246
246
|
const mappedResults = (results || []).map((result) => ({
|
|
247
247
|
countries: _extractShippingCountries(result.countries),
|
|
248
248
|
pre_address_fields: _extractAddressFormFields(result.pre_address_fields, camelcase),
|
|
249
|
-
address_form: _extractAddressForm(result.address_form, camelcase),
|
|
249
|
+
address_form: _extractAddressForm(result.address_form[0], camelcase),
|
|
250
250
|
post_address_fields: _extractAddressFormFields(result.post_address_fields, camelcase)
|
|
251
251
|
}));
|
|
252
252
|
|