@shopgate/pwa-tracking 6.19.2 → 6.20.0-beta.11
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/helpers/index.js
CHANGED
|
@@ -21,11 +21,11 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
|
|
|
21
21
|
* @param {Object} passedOrder Information about the order.
|
|
22
22
|
* @return {Object}
|
|
23
23
|
*/export var formatPurchaseData=function formatPurchaseData(passedOrder){// Return the passedOrder if the format is already correct
|
|
24
|
-
if(!passedOrder.totals&&passedOrder.amount){return{order:passedOrder};}var defaults={totals:[],products:[],number:'',currency:''};var order=_extends({},defaults,
|
|
24
|
+
if(!passedOrder.totals&&passedOrder.amount){return{order:passedOrder};}var defaults={totals:[],products:[],number:'',currency:''};var order=_extends({},defaults,passedOrder);var _ref3=find(order.totals,{type:'grandTotal'})||{},_ref3$amount=_ref3.amount,grandTotal=_ref3$amount===void 0?0:_ref3$amount;var _ref4=find(order.totals,{type:'shipping'})||{},_ref4$amount=_ref4.amount,shipping=_ref4$amount===void 0?0:_ref4$amount;var _ref5=find(order.totals,{type:'tax'})||{},_ref5$amount=_ref5.amount,tax=_ref5$amount===void 0?0:_ref5$amount;var grandTotalNet=grandTotal-tax;var products=order.products.map(function(product){return{uid:product.id||'',productNumber:product.id||'',name:product.name||'',quantity:product.quantity||1,amount:{currency:order.currency,gross:convertPriceToString(get(product,'price.withTax',0)),net:convertPriceToString(get(product,'price.net',0))}};});return{shop:{name:''},order:{number:order.number,amount:{currency:order.currency,gross:convertPriceToString(grandTotal),net:convertPriceToString(grandTotalNet),tax:convertPriceToString(tax)},shipping:{amount:{gross:convertPriceToString(shipping),net:convertPriceToString(shipping)}},products:products,shippingAddress:{city:'',country:''}}};};/**
|
|
25
25
|
* Creates data for the scanner tracking events.
|
|
26
26
|
* @param {Object} params params
|
|
27
27
|
* @return {Object}
|
|
28
|
-
*/export var createScannerEventData=function createScannerEventData(_ref6){var event=_ref6.event,format=_ref6.format,payload=_ref6.payload,userInteraction=_ref6.userInteraction;var eventLabel=[];if(payload){eventLabel=[format];if(SCANNER_FORMATS_QR_CODE.includes(format)){var parsedPayload=parse2dsQrCode(payload);if(parsedPayload){var type=parsedPayload.type,data=parsedPayload.data;switch(type){case QR_CODE_TYPE_HOMEPAGE:eventLabel.push('main');break;case QR_CODE_TYPE_PRODUCT:eventLabel.push('product');eventLabel.push(data.productId);break;case QR_CODE_TYPE_PRODUCT_WITH_COUPON:eventLabel.push('productcoupon');eventLabel.push("".concat(data.productId,"_").concat(data.couponCode));break;case QR_CODE_TYPE_COUPON:eventLabel.push('coupon');eventLabel.push(data.couponCode);break;case QR_CODE_TYPE_CATEGORY:eventLabel.push('category');eventLabel.push(data.categoryId);break;case QR_CODE_TYPE_SEARCH:eventLabel.push('search');eventLabel.push(data.searchPhrase);break;case QR_CODE_TYPE_PAGE:eventLabel.push('page');eventLabel.push(data.pageId);break;default:break;}}}else if(SCANNER_FORMATS_BARCODE.includes(format)){if(payload){eventLabel.push(payload);}}}eventLabel=eventLabel.join(' - ');return _extends({eventAction:event},eventLabel&&{eventLabel:eventLabel},
|
|
28
|
+
*/export var createScannerEventData=function createScannerEventData(_ref6){var event=_ref6.event,format=_ref6.format,payload=_ref6.payload,userInteraction=_ref6.userInteraction;var eventLabel=[];if(payload){eventLabel=[format];if(SCANNER_FORMATS_QR_CODE.includes(format)){var parsedPayload=parse2dsQrCode(payload);if(parsedPayload){var type=parsedPayload.type,data=parsedPayload.data;switch(type){case QR_CODE_TYPE_HOMEPAGE:eventLabel.push('main');break;case QR_CODE_TYPE_PRODUCT:eventLabel.push('product');eventLabel.push(data.productId);break;case QR_CODE_TYPE_PRODUCT_WITH_COUPON:eventLabel.push('productcoupon');eventLabel.push("".concat(data.productId,"_").concat(data.couponCode));break;case QR_CODE_TYPE_COUPON:eventLabel.push('coupon');eventLabel.push(data.couponCode);break;case QR_CODE_TYPE_CATEGORY:eventLabel.push('category');eventLabel.push(data.categoryId);break;case QR_CODE_TYPE_SEARCH:eventLabel.push('search');eventLabel.push(data.searchPhrase);break;case QR_CODE_TYPE_PAGE:eventLabel.push('page');eventLabel.push(data.pageId);break;default:break;}}}else if(SCANNER_FORMATS_BARCODE.includes(format)){if(payload){eventLabel.push(payload);}}}eventLabel=eventLabel.join(' - ');return _extends({eventAction:event},eventLabel&&{eventLabel:eventLabel},typeof userInteraction==='boolean'&&{userInteraction:userInteraction});};/**
|
|
29
29
|
* Creates data for the scanner utm url.
|
|
30
30
|
* @param {Object} params params
|
|
31
31
|
* @return {Object}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/pwa-tracking",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.20.0-beta.11",
|
|
4
4
|
"description": "Tracking library for the Shopgate Connect PWA.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"connect"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@shopgate/pwa-common": "6.
|
|
19
|
-
"@shopgate/pwa-common-commerce": "6.
|
|
20
|
-
"@shopgate/pwa-core": "6.
|
|
21
|
-
"@shopgate/tracking-core": "6.
|
|
18
|
+
"@shopgate/pwa-common": "6.20.0-beta.11",
|
|
19
|
+
"@shopgate/pwa-common-commerce": "6.20.0-beta.11",
|
|
20
|
+
"@shopgate/pwa-core": "6.20.0-beta.11",
|
|
21
|
+
"@shopgate/tracking-core": "6.20.0-beta.11",
|
|
22
22
|
"reselect": "^3.0.1",
|
|
23
23
|
"rxjs": "~5.5.12"
|
|
24
24
|
}
|
package/selectors/user.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
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 _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import{createSelector}from'reselect';import{DEFAULT_LOGIN_STRATEGY,isUserLoggedIn,getUserData,makeGetLoginStrategy}from'@shopgate/engage/user';/**
|
|
1
|
+
var _excluded=["isFetching","loginType"];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 _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import{createSelector}from'reselect';import{DEFAULT_LOGIN_STRATEGY,isUserLoggedIn,getUserData,makeGetLoginStrategy}from'@shopgate/engage/user';/**
|
|
2
2
|
* Creates a selector that retrieves user tracking data from the store.
|
|
3
3
|
* @param {string} name The name of the desired parameter.
|
|
4
4
|
* @returns {Function}
|
|
5
|
-
*/export function makeGetUser(){var getLoginStrategy=makeGetLoginStrategy();return createSelector(isUserLoggedIn,getUserData,getLoginStrategy,function(isLoggedIn,userData,loginStrategy){if(!isLoggedIn||!userData){return null;}var _ref=userData||{},isFetching=_ref.isFetching,loginType=_ref.loginType,trackedData=_objectWithoutProperties(_ref,
|
|
5
|
+
*/export function makeGetUser(){var getLoginStrategy=makeGetLoginStrategy();return createSelector(isUserLoggedIn,getUserData,getLoginStrategy,function(isLoggedIn,userData,loginStrategy){if(!isLoggedIn||!userData){return null;}var _ref=userData||{},isFetching=_ref.isFetching,loginType=_ref.loginType,trackedData=_objectWithoutProperties(_ref,_excluded);if(Object.keys(trackedData).length===0){return null;}var type=null;if(loginStrategy!==DEFAULT_LOGIN_STRATEGY){type=loginStrategy;}else if(['userGuest','userAccount'].includes(loginType)){type=loginType==='userGuest'?'guest':'standard';}return _extends({},trackedData,{type:type});});}
|
package/streams/pages.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e
|
|
1
|
+
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import{routeDidEnter$}from'@shopgate/pwa-common/streams/router';import{appWillStart$,pwaDidAppear$,pwaDidDisappear$}from'@shopgate/pwa-common/streams/app';import{APP_WILL_START,PWA_DID_APPEAR}from'@shopgate/pwa-common/constants/ActionTypes';import{SEARCH_PATH,SEARCH_FILTER_PATTERN}from'@shopgate/pwa-common-commerce/search/constants';import{ROOT_CATEGORY_PATTERN,CATEGORY_PATTERN,CATEGORY_FILTER_PATTERN}from'@shopgate/pwa-common-commerce/category/constants';import{ITEM_PATTERN,ITEM_GALLERY_PATTERN,ITEM_REVIEWS_PATTERN,ITEM_WRITE_REVIEW_PATTERN}from'@shopgate/pwa-common-commerce/product/constants';import{PAGE_PATTERN}from'@shopgate/engage/page';import{pwaVisibility$}from"./app";import{checkoutDidEnter$}from"./checkout";/**
|
|
2
2
|
* A blacklist of paths that should be tracked within their individual subscriptions.
|
|
3
3
|
* @type {Array}
|
|
4
4
|
*/export var blacklistedPatterns=[ROOT_CATEGORY_PATTERN,CATEGORY_PATTERN,ITEM_PATTERN,SEARCH_PATH,// Patterns for routes which are not supported for tracking at the moment.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e
|
|
1
|
+
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import getCart from"../selectors/cart";import*as helpers from"../helpers";import subscription from"./checkout";jest.mock('@shopgate/pwa-common/streams/app',function(){return{appDidStart$:jest.fn()};});jest.mock("../selectors/cart",function(){return function(state){return state;};});jest.mock('@shopgate/pwa-core/commands/registerEvents',function(){return jest.fn();});describe('Checkout subscriptions',function(){var subscribe=jest.fn();beforeEach(function(){jest.clearAllMocks();subscription(subscribe);});it('should call subscribe as expected',function(){expect(subscribe).toHaveBeenCalledTimes(2);});describe('checkoutDidEnter$',function(){var callback;beforeAll(function(){var _subscribe$mock$calls=_slicedToArray(subscribe.mock.calls,1);var _subscribe$mock$calls2=_slicedToArray(_subscribe$mock$calls[0],2);callback=_subscribe$mock$calls2[1];});it('should call the expected commands',function(){var trackSpy=jest.spyOn(helpers,'track');/**
|
|
2
2
|
* Mocked getState function.
|
|
3
3
|
* @return {Object}
|
|
4
4
|
*/var getState=function getState(){return{mocked:'state'};};callback({getState:getState});expect(trackSpy).toHaveBeenCalledTimes(1);expect(trackSpy).toHaveBeenCalledWith('initiatedCheckout',{cart:getCart(getState())},getState());});});});
|
package/subscriptions/scanner.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e
|
|
1
|
+
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import core from'@shopgate/tracking-core/core/Core';import{routeDidLeave$}from'@shopgate/pwa-common/streams';import{scanActivated$,scanFail$,scanSuccess$}from"../streams/scanner";import{buildScannerUtmUrl,createScannerEventData,track}from"../helpers";/**
|
|
2
2
|
* Scanner tracking subscriptions.
|
|
3
3
|
* @param {Function} subscribe The subscribe function.
|
|
4
4
|
*/export default function scanner(subscribe){var events=core.getScannerEvents();subscribe(scanActivated$,function(_ref){var action=_ref.action,getState=_ref.getState;var format=action.format;track('qrScanner',createScannerEventData({event:events.SCAN_ACTIVATED,userInteraction:false,format:format}),getState());});subscribe(scanSuccess$,function(_ref2){var action=_ref2.action,getState=_ref2.getState;var format=action.format,payload=action.payload;track('qrScanner',createScannerEventData({event:events.SCAN_SUCCESS,format:format,payload:payload}),getState());});subscribe(scanFail$,function(_ref3){var action=_ref3.action,getState=_ref3.getState;var format=action.format,payload=action.payload;track('qrScanner',createScannerEventData({event:events.SCAN_FAIL,format:format,payload:payload}),getState());});var afterScan$=scanActivated$.withLatestFrom(routeDidLeave$).switchMap(function(){return scanSuccess$.first();},function(_ref4,successAction){var _ref5=_slicedToArray(_ref4,2),activatedAction=_ref5[0],refererAction=_ref5[1];return{activatedAction:activatedAction,refererAction:refererAction,successAction:successAction,getState:activatedAction.getState};});subscribe(afterScan$,function(_ref6){var activatedAction=_ref6.activatedAction,refererAction=_ref6.refererAction,successAction=_ref6.successAction,getState=_ref6.getState;var _activatedAction$acti=activatedAction.action;_activatedAction$acti=_activatedAction$acti===void 0?{}:_activatedAction$acti;var scannerRoute=_activatedAction$acti.route;var _refererAction$action=refererAction.action.route;_refererAction$action=_refererAction$action===void 0?{}:_refererAction$action;var referer=_refererAction$action.location;var _successAction$action=successAction.action,format=_successAction$action.format,payload=_successAction$action.payload;// eslint-disable-next-line extra-rules/no-single-line-objects
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e
|
|
1
|
+
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}/* eslint-disable extra-rules/no-single-line-objects */import core from'@shopgate/tracking-core/core/Core';import{mainSubject}from'@shopgate/pwa-common/store/middelwares/streams';import{ROUTE_DID_ENTER,ROUTE_DID_LEAVE}from'@shopgate/pwa-common/constants/ActionTypes';import{SCANNER_SCOPE_DEFAULT}from'@shopgate/pwa-core/constants/Scanner';import{SCANNER_PATH,SUCCESS_HANDLE_SCANNER}from'@shopgate/pwa-common-commerce/scanner/constants';import{scanActivated$,scanFail$,scanSuccess$}from"../streams/scanner";import*as helpers from"../helpers";import subscription from"./scanner";var createScannerEventData=helpers.createScannerEventData;var scannerEvents=core.getScannerEvents();describe('Scanner subscriptions',function(){var mockedState={};var subscribe=jest.fn();var getState=jest.fn().mockReturnValue(mockedState);var trackSpy=jest.spyOn(helpers,'track');var format='QR_CODE';var payload='some.payload';beforeEach(function(){jest.clearAllMocks();subscription(subscribe);});it('should call subscribe as expected',function(){expect(subscribe).toHaveBeenCalledTimes(4);});describe('scanActivated$',function(){var stream;var callback;beforeAll(function(){var _subscribe$mock$calls=_slicedToArray(subscribe.mock.calls,1);var _subscribe$mock$calls2=_slicedToArray(_subscribe$mock$calls[0],2);stream=_subscribe$mock$calls2[0];callback=_subscribe$mock$calls2[1];});it('should subscribe the the correct stream',function(){expect(stream).toBe(scanActivated$);});it('should call the track function',function(){callback({action:{format:format},getState:getState});expect(trackSpy).toHaveBeenCalledWith('qrScanner',createScannerEventData({event:scannerEvents.SCAN_ACTIVATED,userInteraction:false,format:format}),mockedState);});});describe('scanSuccess$',function(){var stream;var callback;beforeAll(function(){var _subscribe$mock$calls3=_slicedToArray(subscribe.mock.calls,2);var _subscribe$mock$calls4=_slicedToArray(_subscribe$mock$calls3[1],2);stream=_subscribe$mock$calls4[0];callback=_subscribe$mock$calls4[1];});it('should subscribe the the correct stream',function(){expect(stream).toBe(scanSuccess$);});it('should call the track function',function(){callback({action:{format:format,payload:payload},getState:getState});expect(trackSpy).toHaveBeenCalledWith('qrScanner',createScannerEventData({event:scannerEvents.SCAN_SUCCESS,format:format,payload:payload}),mockedState);});});describe('scanFail$',function(){var stream;var callback;beforeAll(function(){var _subscribe$mock$calls5=_slicedToArray(subscribe.mock.calls,3);var _subscribe$mock$calls6=_slicedToArray(_subscribe$mock$calls5[2],2);stream=_subscribe$mock$calls6[0];callback=_subscribe$mock$calls6[1];});it('should subscribe the the correct stream',function(){expect(stream).toBe(scanFail$);});it('should call the track function',function(){callback({action:{format:format,payload:payload},getState:getState});expect(trackSpy).toHaveBeenCalledWith('qrScanner',createScannerEventData({event:scannerEvents.SCAN_FAIL,format:format,payload:payload}),mockedState);});});describe('afterScan$ UTM params',function(){var refererAction={action:{type:ROUTE_DID_LEAVE,route:{pathname:'/',location:'/'}},getState:getState};var activatedAction={action:{type:ROUTE_DID_ENTER,route:{pathname:SCANNER_PATH,location:SCANNER_PATH}},getState:getState};var successAction={action:{type:SUCCESS_HANDLE_SCANNER,scope:SCANNER_SCOPE_DEFAULT},getState:getState};var afterScan$;var callback;beforeAll(function(){var _subscribe$mock$calls7=_slicedToArray(subscribe.mock.calls,4);var _subscribe$mock$calls8=_slicedToArray(_subscribe$mock$calls7[3],2);afterScan$=_subscribe$mock$calls8[0];callback=_subscribe$mock$calls8[1];});it('should call subscriber with both actions',function(){var subscriber=jest.fn();afterScan$.subscribe(subscriber);mainSubject.next(refererAction);// route did leave
|
|
2
2
|
mainSubject.next(activatedAction);// route did enter
|
|
3
3
|
mainSubject.next(successAction);// scan is handled
|
|
4
4
|
expect(subscriber).toBeCalledTimes(1);expect(subscriber).toBeCalledWith({activatedAction:activatedAction,refererAction:refererAction,successAction:successAction,getState:getState});});it('should call the track function',function(){// eslint-disable-next-line object-curly-newline
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e
|
|
1
|
+
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import{loginDidFail$}from'@shopgate/engage/user';import*as helpers from"../helpers";import subscription from"./user";var mockedGetUser=jest.fn().mockReturnValue('getUser');jest.mock("../selectors/user",function(){return{makeGetUser:function makeGetUser(){return mockedGetUser;}};});describe('User subscriptions',function(){var subscribe=jest.fn();var getState=jest.fn().mockReturnValue('getState');var trackSpy=jest.spyOn(helpers,'track');beforeEach(function(){jest.clearAllMocks();subscription(subscribe);});it('should call subscribe as expected',function(){expect(subscribe).toHaveBeenCalledTimes(2);});describe('loginSuccess$',function(){var callback;beforeAll(function(){var _subscribe$mock$calls=_slicedToArray(subscribe.mock.calls,1);var _subscribe$mock$calls2=_slicedToArray(_subscribe$mock$calls[0],2);callback=_subscribe$mock$calls2[1];});it('should track the loginSuccess event',function(){callback({getState:getState});expect(trackSpy).toHaveBeenCalledTimes(1);expect(trackSpy).toHaveBeenCalledWith('loginSuccess','getUser','getState');});});describe('loginDidFail$',function(){var stream;var callback;beforeAll(function(){var _subscribe$mock$calls3=_slicedToArray(subscribe.mock.calls,2);var _subscribe$mock$calls4=_slicedToArray(_subscribe$mock$calls3[1],2);stream=_subscribe$mock$calls4[0];callback=_subscribe$mock$calls4[1];});it('should subscribe the the correct stream',function(){expect(stream).toBe(loginDidFail$);});it('should track the loginFailed event',function(){callback({getState:getState});expect(trackSpy).toHaveBeenCalledTimes(1);expect(trackSpy).toHaveBeenCalledWith('loginFailed',undefined,'getState');});});});
|