UNPKG

@shopgate/pwa-common-commerce

Version:

Commerce library for the Shopgate Connect PWA.

15 lines 2.71 kB
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import{mockedProducts as mockedList}from"../product/mock";export var mockedDefaultListId='DEFAULT';var mockedStateWithoutProducts={favorites:{byList:_defineProperty({},mockedDefaultListId,{isFetching:false,expires:0,ids:[]}),lists:{expires:0,lists:[{id:mockedDefaultListId,name:'Wish List'}]}}};/** * Creates a products state from the mocked list. * @return {Object} */var createProductsState=function createProductsState(){var productsById=mockedList.products.reduce(function(result,current){return _extends({},result,_defineProperty({},current.id,{isFetching:false,expires:0,productData:current}));},{});return{product:{productsById:productsById}};};var mockedStateWithProducts=_extends({},createProductsState(),{favorites:{byList:_defineProperty({},mockedDefaultListId,{isFetching:false,expires:0,ids:[mockedList.products[0].id,mockedList.products[1].id]}),lists:{expires:0,lists:[{id:mockedDefaultListId,name:'Wish List'}]}}});/** * Gets mocked state. * @param {boolean} withProducts When true products are returned. * @param {boolean} validCache When true, `.expires` flag is > `Date.now()` * @returns {Object} */var getMockedState=function getMockedState(_ref){var withProducts=_ref.withProducts,_ref$validCache=_ref.validCache,validCache=_ref$validCache===void 0?false:_ref$validCache;var data=withProducts?mockedStateWithProducts:mockedStateWithoutProducts;if(validCache){data.favorites.byList[mockedDefaultListId].expires=Date.now()+999999;}return data;};/** * Gets mocked state. * @param {'then'|string} variant Variant as in MockedPipelineResponse. * @param {boolean} withProducts When true products are returned. * @param {boolean} validCache When true, `.expires` flag is > `Date.now()` * @returns {Function} */var mockedGetState=function mockedGetState(variant){var _ref2=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},_ref2$withProducts=_ref2.withProducts,withProducts=_ref2$withProducts===void 0?false:_ref2$withProducts,_ref2$validCache=_ref2.validCache,validCache=_ref2$validCache===void 0?false:_ref2$validCache;return function(){if(variant==='then'){return getMockedState({withProducts:withProducts,validCache:validCache});}return getMockedState({withProducts:false});};};export{mockedList,mockedGetState};