diff --git a/src/constants.ts b/src/constants.ts index 456b10539..bf54b927f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -6,8 +6,9 @@ const Constants = { platform: 'web', Messages: { DeprecationMessages: { - MethodIsDeprecatedPostfix: - 'is a deprecated method and will be removed in future releases', + MethodHasBeenDeprecated: 'has been deprecated.', + MethodMarkedForDeprecationPostfix: + 'is a deprecated method and will be removed in future releases.', AlternativeMethodPrefix: 'Please use the alternate method:', }, ErrorMessages: { @@ -232,11 +233,10 @@ export const HTTP_SERVER_ERROR = 500 as const; export type PrivacyControl = 'functional' | 'targeting'; -export type StorageTypes = 'SDKState' | 'Products' | 'OfflineEvents' | 'IdentityCache' | 'TimeOnSite'; +export type StorageTypes = 'SDKState' | 'OfflineEvents' | 'IdentityCache' | 'TimeOnSite'; export const StoragePrivacyMap: Record = { SDKState: 'functional', - Products: 'targeting', OfflineEvents: 'functional', IdentityCache: 'functional', TimeOnSite: 'targeting', diff --git a/src/helpers.js b/src/helpers.js index ec234dc55..3eec10dbf 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -376,16 +376,6 @@ export default function Helpers(mpInstance) { } }; - this.createProductStorageName = function(workspaceToken) { - if (workspaceToken) { - return ( - StorageNames.currentStorageProductsName + '_' + workspaceToken - ); - } else { - return StorageNames.currentStorageProductsName; - } - }; - // TODO: Refactor SDK to directly use these methods // https://go.mparticle.com/work/SQDSDKS-5239 // Utility Functions diff --git a/src/identity-user-interfaces.ts b/src/identity-user-interfaces.ts index e50b52d68..9a4b673b6 100644 --- a/src/identity-user-interfaces.ts +++ b/src/identity-user-interfaces.ts @@ -115,8 +115,8 @@ export interface IdentityModifyResultBody { } export interface mParticleUserCart { - add(product: SDKProduct | SDKProduct[], logEvent: boolean): void; - remove(product: SDKProduct | SDKProduct[], logEvent: boolean): void; + add(): void; + remove(): void; clear(): void; getCartProducts(): SDKProduct[]; } diff --git a/src/identity.interfaces.ts b/src/identity.interfaces.ts index 5b03c6cbf..8f164c7c7 100644 --- a/src/identity.interfaces.ts +++ b/src/identity.interfaces.ts @@ -206,5 +206,5 @@ export interface IIdentity { /** * @deprecated */ - mParticleUserCart(mpid: MPID): mParticleUserCart; + mParticleUserCart(): mParticleUserCart; } diff --git a/src/identity.js b/src/identity.js index 795549546..a4dba476a 100644 --- a/src/identity.js +++ b/src/identity.js @@ -1215,7 +1215,7 @@ export default function Identity(mpInstance) { mpInstance.Logger.warning( 'Deprecated function Identity.getCurrentUser().getCart() will be removed in future releases' ); - return self.mParticleUserCart(mpid); + return self.mParticleUserCart(); }, /** @@ -1286,133 +1286,37 @@ export default function Identity(mpInstance) { * @class mParticle.Identity.getCurrentUser().getCart() * @deprecated */ - this.mParticleUserCart = function(mpid) { + this.mParticleUserCart = function() { return { /** * Adds a cart product to the user cart * @method add - * @param {Object} product the product - * @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs. * @deprecated */ - add: function(product, logEvent) { + add: function() { mpInstance.Logger.warning( - 'Deprecated function Identity.getCurrentUser().getCart().add() will be removed in future releases' + generateDeprecationMessage( + 'Identity.getCurrentUser().getCart().add()', + true, + 'eCommerce.logProductAction()', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); - var allProducts, userProducts, arrayCopy; - - arrayCopy = Array.isArray(product) - ? product.slice() - : [product]; - arrayCopy.forEach(function(product) { - product.Attributes = mpInstance._Helpers.sanitizeAttributes( - product.Attributes - ); - }); - - if (mpInstance._Store.webviewBridgeEnabled) { - mpInstance._NativeSdkHelpers.sendToNative( - Constants.NativeSdkPaths.AddToCart, - JSON.stringify(arrayCopy) - ); - } else { - mpInstance._SessionManager.resetSessionTimer(); - - userProducts = mpInstance._Persistence.getUserProductsFromLS( - mpid - ); - - userProducts = userProducts.concat(arrayCopy); - - if (logEvent === true) { - mpInstance._Events.logProductActionEvent( - Types.ProductActionType.AddToCart, - arrayCopy - ); - } - - var productsForMemory = {}; - productsForMemory[mpid] = { cp: userProducts }; - - if ( - userProducts.length > - mpInstance._Store.SDKConfig.maxProducts - ) { - mpInstance.Logger.verbose( - 'The cart contains ' + - userProducts.length + - ' items. Only ' + - mpInstance._Store.SDKConfig.maxProducts + - ' can currently be saved in cookies.' - ); - userProducts = userProducts.slice( - -mpInstance._Store.SDKConfig.maxProducts - ); - } - - allProducts = mpInstance._Persistence.getAllUserProductsFromLS(); - allProducts[mpid].cp = userProducts; - - mpInstance._Persistence.setCartProducts(allProducts); - } }, /** * Removes a cart product from the current user cart * @method remove - * @param {Object} product the product - * @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs. * @deprecated */ - remove: function(product, logEvent) { + remove: function() { mpInstance.Logger.warning( - 'Deprecated function Identity.getCurrentUser().getCart().remove() will be removed in future releases' + generateDeprecationMessage( + 'Identity.getCurrentUser().getCart().remove()', + true, + 'eCommerce.logProductAction()', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); - var allProducts, - userProducts, - cartIndex = -1, - cartItem = null; - - if (mpInstance._Store.webviewBridgeEnabled) { - mpInstance._NativeSdkHelpers.sendToNative( - Constants.NativeSdkPaths.RemoveFromCart, - JSON.stringify(product) - ); - } else { - mpInstance._SessionManager.resetSessionTimer(); - - userProducts = mpInstance._Persistence.getUserProductsFromLS( - mpid - ); - - if (userProducts) { - userProducts.forEach(function(cartProduct, i) { - if (cartProduct.Sku === product.Sku) { - cartIndex = i; - cartItem = cartProduct; - } - }); - - if (cartIndex > -1) { - userProducts.splice(cartIndex, 1); - - if (logEvent === true) { - mpInstance._Events.logProductActionEvent( - Types.ProductActionType.RemoveFromCart, - cartItem - ); - } - } - } - - var productsForMemory = {}; - productsForMemory[mpid] = { cp: userProducts }; - - allProducts = mpInstance._Persistence.getAllUserProductsFromLS(); - - allProducts[mpid].cp = userProducts; - - mpInstance._Persistence.setCartProducts(allProducts); - } }, /** * Clears the user's cart @@ -1421,31 +1325,13 @@ export default function Identity(mpInstance) { */ clear: function() { mpInstance.Logger.warning( - 'Deprecated function Identity.getCurrentUser().getCart().clear() will be removed in future releases' + generateDeprecationMessage( + 'Identity.getCurrentUser().getCart().clear()', + true, + '', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); - - var allProducts; - - if (mpInstance._Store.webviewBridgeEnabled) { - mpInstance._NativeSdkHelpers.sendToNative( - Constants.NativeSdkPaths.ClearCart - ); - } else { - mpInstance._SessionManager.resetSessionTimer(); - allProducts = mpInstance._Persistence.getAllUserProductsFromLS(); - - if ( - allProducts && - allProducts[mpid] && - allProducts[mpid].cp - ) { - allProducts[mpid].cp = []; - - allProducts[mpid].cp = []; - - mpInstance._Persistence.setCartProducts(allProducts); - } - } }, /** * Returns all cart products @@ -1455,9 +1341,14 @@ export default function Identity(mpInstance) { */ getCartProducts: function() { mpInstance.Logger.warning( - 'Deprecated function Identity.getCurrentUser().getCart().getCartProducts() will be removed in future releases' + generateDeprecationMessage( + 'Identity.getCurrentUser().getCart().getCartProducts()', + true, + 'eCommerce.logProductAction()', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); - return mpInstance._Persistence.getCartProducts(mpid); + return []; }, }; }; diff --git a/src/mp-instance.ts b/src/mp-instance.ts index 34d973a25..567f722fb 100644 --- a/src/mp-instance.ts +++ b/src/mp-instance.ts @@ -36,7 +36,7 @@ import Consent, { IConsent } from './consent'; import KitBlocker from './kitBlocking'; import ConfigAPIClient, { IKitConfigs } from './configAPIClient'; import IdentityAPIClient from './identityApiClient'; -import { isFunction, parseConfig, valueof } from './utils'; +import { isFunction, parseConfig, valueof, generateDeprecationMessage } from './utils'; import { DisabledVault, LocalStorageVault } from './vault'; import { removeExpiredIdentityCacheDates } from './identity-utils'; import IntegrationCapture from './integrationCapture'; @@ -706,16 +706,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan */ add: function(product, logEventBoolean) { self.Logger.warning( - 'Deprecated function eCommerce.Cart.add() will be removed in future releases' + generateDeprecationMessage( + 'eCommerce.Cart.add()', + true, + 'eCommerce.logProductAction()', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); - let mpid; - const currentUser = self.Identity.getCurrentUser(); - if (currentUser) { - mpid = currentUser.getMPID(); - } - self._Identity - .mParticleUserCart(mpid) - .add(product, logEventBoolean); }, /** * Removes a product from the cart @@ -726,16 +723,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan */ remove: function(product, logEventBoolean) { self.Logger.warning( - 'Deprecated function eCommerce.Cart.remove() will be removed in future releases' + generateDeprecationMessage( + 'eCommerce.Cart.remove()', + true, + 'eCommerce.logProductAction()', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); - let mpid; - const currentUser = self.Identity.getCurrentUser(); - if (currentUser) { - mpid = currentUser.getMPID(); - } - self._Identity - .mParticleUserCart(mpid) - .remove(product, logEventBoolean); }, /** * Clears the cart @@ -744,14 +738,13 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan */ clear: function() { self.Logger.warning( - 'Deprecated function eCommerce.Cart.clear() will be removed in future releases' + generateDeprecationMessage( + 'eCommerce.Cart.clear()', + true, + '', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); - let mpid; - const currentUser = self.Identity.getCurrentUser(); - if (currentUser) { - mpid = currentUser.getMPID(); - } - self._Identity.mParticleUserCart(mpid).clear(); }, }, /** diff --git a/src/persistence.interfaces.ts b/src/persistence.interfaces.ts index dadbb0f42..639de8a3e 100644 --- a/src/persistence.interfaces.ts +++ b/src/persistence.interfaces.ts @@ -99,11 +99,8 @@ export interface IPersistence { useLocalStorage(): boolean; initializeStorage(): void; update(): void; - storeProductsInMemory(products: Product[], mpid: MPID): void; storeDataInMemory(obj: IPersistenceMinified, currentMPID: MPID): void; determineLocalStorageAvailability(storage: Storage): boolean; - getUserProductsFromLS(mpid: MPID): Product[]; - getAllUserProductsFromLS(): Product[]; setLocalStorage(): void; getLocalStorage(): IPersistenceMinified | null; expireCookies(cookieName: string): void; @@ -120,8 +117,6 @@ export interface IPersistence { decodePersistence(persistenceString: string): string; getCookieDomain(): string; getDomain(doc: string, locationHostname: string): string; - getCartProducts(mpid: MPID): Product[]; - setCartProducts(allProducts: Product[]): void; saveUserCookieSyncDatesToPersistence(mpid: MPID, csd: CookieSyncDates): void; savePersistence(persistance: IPersistenceMinified): void; getPersistence(): IPersistenceMinified; diff --git a/src/persistence.js b/src/persistence.js index 2ad76d995..256595434 100644 --- a/src/persistence.js +++ b/src/persistence.js @@ -90,35 +90,6 @@ export default function _Persistence(mpInstance) { self.storeDataInMemory(cookies); } - // https://go.mparticle.com/work/SQDSDKS-6048 - try { - if (mpInstance._Store.isLocalStorageAvailable) { - var encodedProducts = localStorage.getItem( - mpInstance._Store.prodStorageName - ); - - if (encodedProducts) { - var decodedProducts = JSON.parse( - Base64.decode(encodedProducts) - ); - } - if (mpInstance._Store.mpid) { - self.storeProductsInMemory( - decodedProducts, - mpInstance._Store.mpid - ); - } - } - } catch (e) { - if (mpInstance._Store.isLocalStorageAvailable) { - localStorage.removeItem(mpInstance._Store.prodStorageName); - } - mpInstance._Store.cartProducts = []; - mpInstance.Logger.error( - 'Error loading products in initialization: ' + e - ); - } - // https://go.mparticle.com/work/SQDSDKS-6046 // Stores all non-current user MPID information into the store for (var key in allData) { @@ -158,21 +129,6 @@ export default function _Persistence(mpInstance) { } }; - this.storeProductsInMemory = function(products, mpid) { - if (products) { - try { - mpInstance._Store.cartProducts = - products[mpid] && products[mpid].cp - ? products[mpid].cp - : []; - } catch (e) { - mpInstance.Logger.error( - Messages.ErrorMessages.CookieParseError - ); - } - } - }; - // https://go.mparticle.com/work/SQDSDKS-6045 this.storeDataInMemory = function(obj, currentMPID) { try { @@ -275,64 +231,6 @@ export default function _Persistence(mpInstance) { } }; - this.getUserProductsFromLS = function(mpid) { - if (!mpInstance._Store.isLocalStorageAvailable) { - return []; - } - - var decodedProducts, - userProducts, - parsedProducts, - encodedProducts = localStorage.getItem( - mpInstance._Store.prodStorageName - ); - if (encodedProducts) { - decodedProducts = Base64.decode(encodedProducts); - } - // if there is an MPID, we are retrieving the user's products, which is an array - if (mpid) { - try { - if (decodedProducts) { - parsedProducts = JSON.parse(decodedProducts); - } - if ( - decodedProducts && - parsedProducts[mpid] && - parsedProducts[mpid].cp && - Array.isArray(parsedProducts[mpid].cp) - ) { - userProducts = parsedProducts[mpid].cp; - } else { - userProducts = []; - } - return userProducts; - } catch (e) { - return []; - } - } else { - return []; - } - }; - - this.getAllUserProductsFromLS = function() { - var decodedProducts, - encodedProducts = localStorage.getItem( - mpInstance._Store.prodStorageName - ), - parsedDecodedProducts; - if (encodedProducts) { - decodedProducts = Base64.decode(encodedProducts); - } - // returns an object with keys of MPID and values of array of products - try { - parsedDecodedProducts = JSON.parse(decodedProducts); - } catch (e) { - parsedDecodedProducts = {}; - } - - return parsedDecodedProducts; - }; - // https://go.mparticle.com/work/SQDSDKS-6021 this.setLocalStorage = function() { if (!mpInstance._Store.isLocalStorageAvailable) { @@ -340,30 +238,9 @@ export default function _Persistence(mpInstance) { } var key = mpInstance._Store.storageName, - allLocalStorageProducts = self.getAllUserProductsFromLS(), localStorageData = self.getLocalStorage() || {}, currentUser = mpInstance.Identity.getCurrentUser(), - mpid = currentUser ? currentUser.getMPID() : null, - currentUserProducts = { - cp: allLocalStorageProducts[mpid] - ? allLocalStorageProducts[mpid].cp - : [], - }; - if (mpid) { - allLocalStorageProducts = allLocalStorageProducts || {}; - allLocalStorageProducts[mpid] = currentUserProducts; - try { - window.localStorage.setItem( - encodeURIComponent(mpInstance._Store.prodStorageName), - Base64.encode(JSON.stringify(allLocalStorageProducts)) - ); - } catch (e) { - mpInstance.Logger.error( - 'Error with setting products on localStorage.' - ); - } - } - + mpid = currentUser ? currentUser.getMPID() : null; if (!mpInstance._Store.SDKConfig.useCookieStorage) { localStorageData.gs = localStorageData.gs || {}; @@ -900,42 +777,6 @@ export default function _Persistence(mpInstance) { return ''; }; - this.getCartProducts = function(mpid) { - var allCartProducts, - cartProductsString = localStorage.getItem( - mpInstance._Store.prodStorageName - ); - if (cartProductsString) { - allCartProducts = JSON.parse(Base64.decode(cartProductsString)); - if ( - allCartProducts && - allCartProducts[mpid] && - allCartProducts[mpid].cp - ) { - return allCartProducts[mpid].cp; - } - } - - return []; - }; - - this.setCartProducts = function(allProducts) { - if (!mpInstance._Store.isLocalStorageAvailable) { - return; - } - - try { - window.localStorage.setItem( - encodeURIComponent(mpInstance._Store.prodStorageName), - Base64.encode(JSON.stringify(allProducts)) - ); - } catch (e) { - mpInstance.Logger.error( - 'Error with setting products on localStorage.' - ); - } - }; - this.saveUserCookieSyncDatesToPersistence = function(mpid, csd) { if (csd) { var persistence = self.getPersistence(); @@ -1111,7 +952,6 @@ export default function _Persistence(mpInstance) { removeLocalStorage(StorageNames.localStorageName); removeLocalStorage(StorageNames.localStorageNameV3); removeLocalStorage(StorageNames.localStorageNameV4); - removeLocalStorage(mpInstance._Store.prodStorageName); removeLocalStorage(mpInstance._Store.storageName); removeLocalStorage(StorageNames.localStorageProductsV4); @@ -1119,7 +959,6 @@ export default function _Persistence(mpInstance) { self.expireCookies(StorageNames.cookieNameV2); self.expireCookies(StorageNames.cookieNameV3); self.expireCookies(StorageNames.cookieNameV4); - self.expireCookies(mpInstance._Store.prodStorageName); self.expireCookies(mpInstance._Store.storageName); if (mParticle._isTestEnv) { @@ -1130,9 +969,6 @@ export default function _Persistence(mpInstance) { self.expireCookies( mpInstance._Helpers.createMainStorageName(testWorkspaceToken) ); - removeLocalStorage( - mpInstance._Helpers.createProductStorageName(testWorkspaceToken) - ); } }; diff --git a/src/sdkRuntimeModels.ts b/src/sdkRuntimeModels.ts index 6f129b47c..dbe1fcef1 100644 --- a/src/sdkRuntimeModels.ts +++ b/src/sdkRuntimeModels.ts @@ -319,7 +319,6 @@ export interface DataPlanConfig { export interface SDKHelpersApi { canLog?(): boolean; createMainStorageName?(workspaceToken: string): string; - createProductStorageName?(workspaceToken: string): string; createServiceUrl(url: string, devToken?: string): string; createXHR?(cb: () => void): XMLHttpRequest; extend?(...args: any[]); diff --git a/src/sessionManager.ts b/src/sessionManager.ts index 477798658..fafbde631 100644 --- a/src/sessionManager.ts +++ b/src/sessionManager.ts @@ -72,7 +72,7 @@ export default function SessionManager( mpInstance.Logger.warning( generateDeprecationMessage( 'SessionManager.getSession()', - + false, 'SessionManager.getSessionId()' ) ); diff --git a/src/store.ts b/src/store.ts index 8f7177b8c..43e1b4134 100644 --- a/src/store.ts +++ b/src/store.ts @@ -194,7 +194,6 @@ export interface IStore { requireDelay: boolean; isLocalStorageAvailable: boolean | null; storageName: string | null; - prodStorageName: string | null; activeForwarders: ConfiguredKit[]; kits: Dictionary; sideloadedKits: MPForwarder[]; @@ -247,7 +246,6 @@ export default function Store( ) { const { createMainStorageName, - createProductStorageName, } = mpInstance._Helpers; const { isWebviewEnabled } = mpInstance._NativeSdkHelpers; @@ -287,7 +285,6 @@ export default function Store( requireDelay: true, isLocalStorageAvailable: null, storageName: null, - prodStorageName: null, activeForwarders: [], kits: {}, sideloadedKits: [], @@ -762,7 +759,6 @@ export default function Store( } // add a new function to apply items to the store that require config to be returned this.storageName = createMainStorageName(workspaceToken); - this.prodStorageName = createProductStorageName(workspaceToken); this.SDKConfig.requiredWebviewBridgeName = requiredWebviewBridgeName || workspaceToken; diff --git a/src/utils.ts b/src/utils.ts index b1e0161fa..52a7b3de4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -57,18 +57,25 @@ const findKeyInObject = (obj: any, key: string): string => { const generateDeprecationMessage = ( methodName: string, - alternateMethod: string + isDeprecated?: boolean, + alternateMethod?: string, + docsUrl?: string, ): string => { - const messageArray: string[] = [ - methodName, - Messages.DeprecationMessages.MethodIsDeprecatedPostfix, - ]; + const messageArray: string[] = [methodName]; + + if (isDeprecated) { + messageArray.push(Messages.DeprecationMessages.MethodHasBeenDeprecated); + } else { + messageArray.push(Messages.DeprecationMessages.MethodMarkedForDeprecationPostfix); + } if (alternateMethod) { - messageArray.push(alternateMethod); - messageArray.push( - Messages.DeprecationMessages.MethodIsDeprecatedPostfix - ); + messageArray.push(Messages.DeprecationMessages.AlternativeMethodPrefix); + messageArray.push(alternateMethod + "."); + } + + if (docsUrl) { + messageArray.push("See - " + docsUrl); } return messageArray.join(' '); diff --git a/test/jest/persistence.spec.ts b/test/jest/persistence.spec.ts index c951b9587..c1f7e8610 100644 --- a/test/jest/persistence.spec.ts +++ b/test/jest/persistence.spec.ts @@ -13,12 +13,9 @@ describe('Persistence', () => { store = {} as IStore; mockMPInstance = { _Helpers: { - createMainStorageName: () => 'mprtcl-v4', isObject, }, - _NativeSdkHelpers: { - isWebviewEnabled: () => false, - }, + _NativeSdkHelpers: {}, _Store: store, Identity: { getCurrentUser: jest.fn().mockReturnValue({ @@ -39,7 +36,6 @@ describe('Persistence', () => { store.webviewBridgeEnabled = false; persistence = new Persistence(mockMPInstance); - window.localStorage.removeItem(encodeURIComponent(store.storageName)); }); describe('#update', () => { @@ -59,7 +55,6 @@ describe('Persistence', () => { expect(setCookieSpy).not.toHaveBeenCalled(); expect(setLocalStorageSpy).not.toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).toBeNull(); }); it('should NOT write to localStorage when useCookieStorage is false', () => { @@ -72,7 +67,6 @@ describe('Persistence', () => { expect(setCookieSpy).not.toHaveBeenCalled(); expect(setLocalStorageSpy).not.toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).toBeNull(); }); }); @@ -94,7 +88,6 @@ describe('Persistence', () => { expect(setCookieSpy).toHaveBeenCalled(); expect(setLocalStorageSpy).toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).not.toBeNull(); }); it('should write to localStorage when useCookieStorage is false', () => { @@ -107,7 +100,6 @@ describe('Persistence', () => { expect(setCookieSpy).not.toHaveBeenCalled(); expect(setLocalStorageSpy).toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).not.toBeNull(); }); }); @@ -129,7 +121,6 @@ describe('Persistence', () => { expect(setCookieSpy).toHaveBeenCalled(); expect(setLocalStorageSpy).toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).not.toBeNull(); }); it('should write to localStorage by default when useCookieStorage is false', () => { @@ -142,7 +133,6 @@ describe('Persistence', () => { expect(setCookieSpy).not.toHaveBeenCalled(); expect(setLocalStorageSpy).toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).not.toBeNull(); }); }); @@ -158,7 +148,6 @@ describe('Persistence', () => { expect(setCookieSpy).not.toHaveBeenCalled(); expect(setLocalStorageSpy).not.toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).toBeNull(); }); }); }); \ No newline at end of file diff --git a/test/src/config/utils.js b/test/src/config/utils.js index f46803058..2580710ae 100644 --- a/test/src/config/utils.js +++ b/test/src/config/utils.js @@ -12,17 +12,6 @@ import { import fetchMock from 'fetch-mock/esm/client'; var pluses = /\+/g, - getLocalStorageProducts = function getLocalStorageProducts() { - return JSON.parse( - atob( - localStorage.getItem( - mParticle - .getInstance() - ._Helpers.createProductStorageName(workspaceToken) - ) - ) - ); - }, decoded = function decoded(s) { return decodeURIComponent(s.replace(pluses, ' ')); }, @@ -638,7 +627,6 @@ var pluses = /\+/g, hasConfigurationReturned = () => !!mParticle.getInstance()?._Store?.configurationLoaded; var TestsCore = { - getLocalStorageProducts: getLocalStorageProducts, findCookie: findCookie, setCookie: setCookie, setLocalStorage: setLocalStorage, diff --git a/test/src/tests-eCommerce.js b/test/src/tests-eCommerce.js index 8c3e1dc8e..de8044b98 100644 --- a/test/src/tests-eCommerce.js +++ b/test/src/tests-eCommerce.js @@ -1,11 +1,10 @@ import Utils from './config/utils'; import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; -import { urls, apiKey, workspaceToken, MPConfig, testMPID, ProductActionType, PromotionActionType } from './config/constants'; +import { urls, apiKey, MPConfig, testMPID, ProductActionType, PromotionActionType } from './config/constants'; const { waitForCondition, fetchMockSuccess, hasIdentifyReturned } = Utils; -const getLocalStorageProducts = Utils.getLocalStorageProducts, - forwarderDefaultConfiguration = Utils.forwarderDefaultConfiguration, +const forwarderDefaultConfiguration = Utils.forwarderDefaultConfiguration, findEventFromRequest = Utils.findEventFromRequest, MockForwarder = Utils.MockForwarder; @@ -664,111 +663,6 @@ describe('eCommerce', function() { }) }); - it('should add products to cart', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { - const product = mParticle.eCommerce.createProduct('iPhone', '12345', 400); - - mParticle.eCommerce.Cart.add(product, true); - - const addToCartEvent = findEventFromRequest(fetchMock.calls(), 'add_to_cart'); - - addToCartEvent.data.should.have.property('product_action'); - addToCartEvent.data.product_action.should.have.property('action', 'add_to_cart'); - addToCartEvent.data.product_action.should.have.property('products').with.lengthOf(1); - addToCartEvent.data.product_action.products[0].should.have.property('id', '12345'); - - done(); - }) - }); - - it('should remove products to cart', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { - const product = mParticle.eCommerce.createProduct('iPhone', '12345', 400); - - mParticle.eCommerce.Cart.add(product); - mParticle.eCommerce.Cart.remove({ Sku: '12345' }, true); - - const removeFromCartEvent = findEventFromRequest(fetchMock.calls(), 'remove_from_cart'); - - removeFromCartEvent.data.should.have.property('product_action'); - removeFromCartEvent.data.product_action.should.have.property('action', 'remove_from_cart'); - removeFromCartEvent.data.product_action.should.have.property('products').with.lengthOf(1); - removeFromCartEvent.data.product_action.products[0].should.have.property('id', '12345'); - - done(); - }) - }); - - it('should update cart products in cookies after adding/removing product to/from a cart and clearing cart', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { - const product = mParticle.eCommerce.createProduct('iPhone', '12345', 400); - - mParticle.eCommerce.Cart.add(product); - const products1 = getLocalStorageProducts(); - - products1[testMPID].cp[0].should.have.properties([ - 'Name', - 'Sku', - 'Price', - ]); - - mParticle.eCommerce.Cart.remove(product); - const products2 = getLocalStorageProducts(); - products2[testMPID].cp.length.should.equal(0); - - mParticle.eCommerce.Cart.add(product); - const products3 = getLocalStorageProducts(); - products3[testMPID].cp[0].should.have.properties([ - 'Name', - 'Sku', - 'Price', - ]); - - mParticle.eCommerce.Cart.clear(); - const products4 = getLocalStorageProducts(); - products4[testMPID].cp.length.should.equal(0); - - done(); - }) - }); - - it('should not add the (config.maxProducts + 1st) item to cookie cartItems and only send cookie cartProducts when logging', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { - mParticle.config.maxProducts = 10; - mParticle.config.workspaceToken = workspaceToken; - mParticle.init(apiKey, window.mParticle.config); - - const product = mParticle.eCommerce.createProduct( - 'Product', - '12345', - 400 - ); - for (let i = 0; i < mParticle.config.maxProducts; i++) { - mParticle.eCommerce.Cart.add(product); - } - - mParticle.eCommerce.Cart.add( - mParticle.eCommerce.createProduct('Product11', '12345', 400) - ); - const products1 = getLocalStorageProducts(); - - const foundProductInCookies = products1[testMPID].cp.filter(function( - product - ) { - return product.Name === 'Product11'; - })[0]; - - products1[testMPID].cp.length.should.equal(10); - Should(foundProductInCookies).be.ok(); - - done(); - }) - }); - it('should log checkout via deprecated logCheckout method', function(done) { waitForCondition(hasIdentifyReturned) .then(() => { @@ -965,69 +859,6 @@ describe('eCommerce', function() { }) }); - it('should support array of products when adding to cart', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { - const product1 = mParticle.eCommerce.createProduct( - 'iPhone', - '12345', - 400, - 2 - ), - product2 = mParticle.eCommerce.createProduct( - 'Nexus', - '67890', - 300, - 1 - ); - - mParticle.eCommerce.Cart.add([product1, product2], true); - - const addToCartEvent = findEventFromRequest(fetchMock.calls(), 'add_to_cart'); - - Should(addToCartEvent).be.ok(); - - addToCartEvent.data.should.have.property('product_action'); - addToCartEvent.data.product_action.should.have.property('action', 'add_to_cart'); - addToCartEvent.data.product_action.should.have.property('products').with.lengthOf(2); - - addToCartEvent.data.product_action.products[0].should.have.property('id', '12345'); - addToCartEvent.data.product_action.products[0].should.have.property('name', 'iPhone'); - - addToCartEvent.data.product_action.products[1].should.have.property('id', '67890'); - addToCartEvent.data.product_action.products[1].should.have.property('name', 'Nexus'); - - done(); - }) - }); - - it('should support a single product when adding to cart', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { - const product1 = mParticle.eCommerce.createProduct( - 'iPhone', - '12345', - 400, - 2 - ); - - mParticle.eCommerce.Cart.add(product1, true); - - const addToCartEvent = findEventFromRequest(fetchMock.calls(), 'add_to_cart'); - - Should(addToCartEvent).be.ok(); - - addToCartEvent.data.should.have.property('product_action'); - addToCartEvent.data.product_action.should.have.property('action', 'add_to_cart'); - addToCartEvent.data.product_action.should.have.property('products').with.lengthOf(1); - - addToCartEvent.data.product_action.products[0].should.have.property('id', '12345'); - addToCartEvent.data.product_action.products[0].should.have.property('name', 'iPhone'); - - done(); - }) - }); - it('expand product purchase commerce event', function(done) { waitForCondition(hasIdentifyReturned) .then(() => { @@ -1690,10 +1521,11 @@ describe('eCommerce', function() { bond.called.should.eql(true); bond.getCalls()[0].args[0].should.eql( - 'Deprecated function eCommerce.Cart.add() will be removed in future releases' + 'eCommerce.Cart.add() has been deprecated. Please use the alternate method: eCommerce.logProductAction(). See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking' ); }) }); + it('should deprecate remove', function() { waitForCondition(hasIdentifyReturned) .then(() => { @@ -1709,7 +1541,7 @@ describe('eCommerce', function() { bond.called.should.eql(true); bond.getCalls()[0].args[0].should.eql( - 'Deprecated function eCommerce.Cart.remove() will be removed in future releases' + 'eCommerce.Cart.remove() has been deprecated. Please use the alternate method: eCommerce.logProductAction(). See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking' ); }) }); @@ -1723,7 +1555,7 @@ describe('eCommerce', function() { bond.called.should.eql(true); bond.getCalls()[0].args[0].should.eql( - 'Deprecated function eCommerce.Cart.clear() will be removed in future releases' + 'eCommerce.Cart.clear() has been deprecated. See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking' ); }) }); diff --git a/test/src/tests-helpers.js b/test/src/tests-helpers.js index 91c69e420..17c601cad 100644 --- a/test/src/tests-helpers.js +++ b/test/src/tests-helpers.js @@ -308,21 +308,4 @@ describe('helpers', function() { done(); }); - - it('should create a product storage name based on default mParticle storage version + apiKey if apiKey is passed in', function(done) { - const cookieName = mParticle - .getInstance() - ._Helpers.createProductStorageName(apiKey); - cookieName.should.equal('mprtcl-prodv4_test_key'); - - done(); - }); - it('should create a product storage name based on default mParticle storage version if no apiKey is passed in', function(done) { - const cookieName = mParticle - .getInstance() - ._Helpers.createProductStorageName(); - cookieName.should.equal('mprtcl-prodv4'); - - done(); - }); }); \ No newline at end of file diff --git a/test/src/tests-identities-attributes.ts b/test/src/tests-identities-attributes.ts index 1c9fdd222..eb447c3d4 100644 --- a/test/src/tests-identities-attributes.ts +++ b/test/src/tests-identities-attributes.ts @@ -798,30 +798,6 @@ describe('identities and attributes', function() { }) }); - it('should get cart products', function(done) { - const product1: SDKProduct = mParticle.eCommerce.createProduct('iPhone', 'SKU1', 1, 1); - const product2: SDKProduct = mParticle.eCommerce.createProduct('Android', 'SKU2', 1, 1); - - waitForCondition(hasIdentifyReturned) - .then(() => { - mParticle.eCommerce.Cart.add([product1, product2], null); - - const cartProducts = mParticle.Identity.getCurrentUser() - .getCart() - .getCartProducts(); - - expect(cartProducts.length).to.equal(2); - expect(JSON.stringify(cartProducts[0])).to.equal( - JSON.stringify(product1) - ); - expect(JSON.stringify(cartProducts[1])).to.equal( - JSON.stringify(product2) - ); - - done(); - }) - }); - it('should send user attribute change requests when setting new attributes', function(done) { mParticle._resetForTests(MPConfig); diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 0e8678f6e..2e4a99d41 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -34,7 +34,6 @@ const { setLocalStorage, findCookie, forwarderDefaultConfiguration, - getLocalStorageProducts, findEventFromRequest, findBatch, setCookie, @@ -2112,14 +2111,6 @@ describe('identity', function() { mParticle.Identity.getCurrentUser().setUserAttribute('foo1', 'bar1'); expect(fetchMock.calls().length).to.equal(7); - const product1: SDKProduct = mParticle.eCommerce.createProduct( - 'iPhone', - '12345', - '1000', - 2 - ); - mParticle.eCommerce.Cart.add(product1); - // This will add a new custom event to the call mParticle.logEvent('Test Event 1'); expect(fetchMock.calls().length).to.equal(8); @@ -2132,18 +2123,6 @@ describe('identity', function() { 'email': 'email2@test.com' }); - const products = getLocalStorageProducts(); - - products.testMPID.cp[0].should.have.property( - 'Name', - 'iPhone', - 'sku', - 'quantity' - ); - products.testMPID.cp[0].should.have.property('Sku', '12345'); - products.testMPID.cp[0].should.have.property('Price', 1000); - products.testMPID.cp[0].should.have.property('Quantity', 2); - const user2 = { userIdentities: { customerid: 'customerid2', @@ -2198,18 +2177,6 @@ describe('identity', function() { 'customer_id': 'customerid1', 'email': 'email2@test.com' }); - - const products2 = getLocalStorageProducts(); - - products2.testMPID.cp[0].should.have.property( - 'Name', - 'iPhone', - 'sku', - 'quantity' - ); - products2.testMPID.cp[0].should.have.property('Sku', '12345'); - products2.testMPID.cp[0].should.have.property('Price', 1000); - products2.testMPID.cp[0].should.have.property('Quantity', 2); }); it('should add new MPIDs to cookie structure when initializing new identity requests, returning an existing mpid when reinitializing with a previous identity', async () => { @@ -2496,92 +2463,6 @@ describe('identity', function() { expect(userIdentities2.userIdentities).to.deep.equal({}); }); - it("saves proper cookies for each user's products, and purchases record cartProducts correctly", async () => { - mParticle._resetForTests(MPConfig); - - const identityAPIRequest1 = { - userIdentities: { - customerid: '123', - }, - }; - mParticle.init(apiKey, window.mParticle.config); - - await waitForCondition(hasIdentifyReturned) - - const product1 = mParticle.eCommerce.createProduct('iPhone', 'SKU1', 1), - product2 = mParticle.eCommerce.createProduct('Android', 'SKU2', 2), - product3 = mParticle.eCommerce.createProduct('Windows', 'SKU3', 3), - product4 = mParticle.eCommerce.createProduct('HTC', 'SKU4', 4); - - mParticle.eCommerce.Cart.add([product1, product2]); - - const identityAPIRequest2 = { - userIdentities: { - customerid: '234', - }, - }; - - const products = getLocalStorageProducts(); - const cartProducts = products[testMPID].cp; - - cartProducts[0].Name.should.equal('iPhone'); - cartProducts[1].Name.should.equal('Android'); - - fetchMockSuccess(urls.login, { - mpid: 'otherMPID', - is_logged_in: true, - }); - - mParticle.Identity.login(identityAPIRequest2); - - await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === 'otherMPID') - - mParticle.eCommerce.Cart.add([product3, product4]); - - const products2 = getLocalStorageProducts(); - const cartProducts2 = products2['otherMPID'].cp; - - cartProducts2[0].Name.should.equal('Windows'); - cartProducts2[1].Name.should.equal('HTC'); - - // https://go.mparticle.com/work/SQDSDKS-6846 - mParticle.eCommerce.logCheckout(1); - - const checkoutEvent = findEventFromRequest( - fetchMock.calls(), - 'checkout' - ); - - checkoutEvent.data.product_action.should.have.property( - 'products', - null - ); - - fetchMockSuccess(urls.login, { - mpid: testMPID, - is_logged_in: true, - }); - - mParticle.Identity.login(identityAPIRequest1); - - await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === 'otherMPID') - - fetchMock.resetHistory(); - - // https://go.mparticle.com/work/SQDSDKS-6846 - mParticle.eCommerce.logCheckout(1); - - const checkoutEvent2 = findEventFromRequest( - fetchMock.calls(), - 'checkout' - ); - - checkoutEvent2.data.product_action.should.have.property( - 'products', - null - ); - }); - it('should update cookies after modifying identities', async () => { mParticle.init(apiKey, window.mParticle.config); const user = { @@ -4806,7 +4687,7 @@ describe('identity', function() { // deprecates on both .getCart, then .add bond.callCount.should.equal(4); bond.getCalls()[1].args[0].should.eql( - 'Deprecated function Identity.getCurrentUser().getCart().add() will be removed in future releases' + 'Identity.getCurrentUser().getCart().add() has been deprecated. Please use the alternate method: eCommerce.logProductAction(). See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking' ); }); @@ -4835,7 +4716,7 @@ describe('identity', function() { // deprecates on both .getCart, then .add bond.callCount.should.equal(4); bond.getCalls()[1].args[0].should.eql( - 'Deprecated function Identity.getCurrentUser().getCart().remove() will be removed in future releases' + 'Identity.getCurrentUser().getCart().remove() has been deprecated. Please use the alternate method: eCommerce.logProductAction(). See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking' ); }); @@ -4857,7 +4738,7 @@ describe('identity', function() { // deprecates on both .getCart, then .add bond.callCount.should.equal(4); bond.getCalls()[1].args[0].should.eql( - 'Deprecated function Identity.getCurrentUser().getCart().clear() will be removed in future releases' + 'Identity.getCurrentUser().getCart().clear() has been deprecated. See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking' ); }); @@ -4880,7 +4761,7 @@ describe('identity', function() { // deprecates on both .getCart, then .add bond.callCount.should.equal(4); bond.getCalls()[1].args[0].should.eql( - 'Deprecated function Identity.getCurrentUser().getCart().getCartProducts() will be removed in future releases' + 'Identity.getCurrentUser().getCart().getCartProducts() has been deprecated. Please use the alternate method: eCommerce.logProductAction(). See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking' ); }); }); diff --git a/test/src/tests-native-sdk.js b/test/src/tests-native-sdk.js index 8b98c87fa..a6801958e 100644 --- a/test/src/tests-native-sdk.js +++ b/test/src/tests-native-sdk.js @@ -467,74 +467,6 @@ describe('native-sdk methods', function() { done(); }); - // TBD _ ask will/peter about add to cart array vs product? - it('should invoke native sdk method addToCart', function(done) { - const product = mParticle.eCommerce.createProduct( - 'name', - 'sku', - 10, - 1 - ); - const product2 = mParticle.eCommerce.createProduct( - 'name', - 'sku', - 10, - 1 - ); - - mParticle.eCommerce.Cart.add(product); - - window.mParticleAndroid.should.have.property( - 'addToCartCalled', - true - ); - window.mParticleAndroid.addedToCartItem.should.equal( - JSON.stringify([product]) - ); - window.mParticleAndroid.clearCart(); - - mParticle.eCommerce.Cart.add([product, product2]); - - window.mParticleAndroid.addedToCartItem.should.equal( - JSON.stringify([product, product2]) - ); - - done(); - }); - - it('should invoke native sdk method removeFromCart', function(done) { - const product = mParticle.eCommerce.createProduct( - 'name', - 'sku', - 10, - 1 - ); - - mParticle.eCommerce.Cart.add(product); - mParticle.eCommerce.Cart.remove(product); - - window.mParticleAndroid.should.have.property( - 'removeFromCartCalled', - true - ); - window.mParticleAndroid.removedFromCartItem.should.equal( - JSON.stringify(product) - ); - - done(); - }); - - it('should invoke native sdk method clearCart', function(done) { - mParticle.eCommerce.Cart.clear(); - - window.mParticleAndroid.should.have.property( - 'clearCartCalled', - true - ); - - done(); - }); - it('should not sync cookies when in a mobile web view for Android', function(done) { const pixelSettings = { name: 'AdobeEventForwarder', @@ -723,79 +655,6 @@ describe('native-sdk methods', function() { done(); }); - it('should invoke Android method addToCart', function(done) { - const product = mParticle.eCommerce.createProduct( - 'name', - 'sku', - 10, - 1 - ); - const product2 = mParticle.eCommerce.createProduct( - 'name', - 'sku', - 10, - 1 - ); - - mParticle.eCommerce.Cart.add(product); - - mParticleAndroidV2Bridge.should.have.property( - 'addToCartCalled', - true - ); - mParticleAndroidV2Bridge.addedToCartItem.should.equal( - JSON.stringify([product]) - ); - - mParticleAndroidV2Bridge.clearCart(); - - mParticle.eCommerce.Cart.add([product, product2]); - - mParticleAndroidV2Bridge.addedToCartItem.should.equal( - JSON.stringify([product, product2]) - ); - - done(); - }); - - it('should invoke Android method removeFromCart', function(done) { - const product = mParticle.eCommerce.createProduct( - 'name', - 'sku', - 10, - 1 - ); - - mParticle.eCommerce.Cart.add(product); - mParticle.eCommerce.Cart.remove(product); - - mParticleAndroidV2Bridge.should.have.property( - 'removeFromCartCalled', - true - ); - mParticleAndroidV2Bridge.removedFromCartItem.should.equal( - JSON.stringify(product) - ); - - mParticleAndroidV2Bridge.should.have.property( - 'removeFromCartCalled', - true - ); - - done(); - }); - - it('should invoke Android method clearCart', function(done) { - mParticle.eCommerce.Cart.clear(); - - mParticleAndroidV2Bridge.should.have.property( - 'clearCartCalled', - true - ); - - done(); - }); - it('should not sync cookies when in a mobile web view for Android', function(done) { const pixelSettings = { name: 'AdobeEventForwarder', @@ -1117,83 +976,6 @@ describe('native-sdk methods', function() { done(); }); - it('should invoke ios sdk method addToCart', function(done) { - const product = mParticle.eCommerce.createProduct( - 'name', - 'sku', - 10, - 1 - ); - const product2 = mParticle.eCommerce.createProduct( - 'name', - 'sku', - 10, - 1 - ); - - mParticle.eCommerce.Cart.add(product); - - JSON.parse(mParticleIOSV2Bridge.data[0]).should.have.properties( - ['path', 'value'] - ); - JSON.parse(mParticleIOSV2Bridge.data[0]).path.should.equal( - 'addToCart' - ); - JSON.stringify( - JSON.parse(mParticleIOSV2Bridge.data[0]).value - ).should.equal(JSON.stringify([product])); - mParticleIOSV2Bridge.reset(); - - mParticle.eCommerce.Cart.add([product, product2]); - JSON.parse(mParticleIOSV2Bridge.data[0]).should.have.properties( - ['path', 'value'] - ); - JSON.parse(mParticleIOSV2Bridge.data[0]).path.should.equal( - 'addToCart' - ); - JSON.stringify( - JSON.parse(mParticleIOSV2Bridge.data[0]).value - ).should.equal(JSON.stringify([product, product2])); - - done(); - }); - - it('should invoke ios sdk method removeFromCart', function(done) { - const product = mParticle.eCommerce.createProduct( - 'name', - 'sku', - 10, - 1 - ); - - mParticle.eCommerce.Cart.remove(product); - - JSON.parse(mParticleIOSV2Bridge.data[0]).should.have.properties( - ['path', 'value'] - ); - JSON.parse(mParticleIOSV2Bridge.data[0]).path.should.equal( - 'removeFromCart' - ); - JSON.stringify( - JSON.parse(mParticleIOSV2Bridge.data[0]).value - ).should.equal(JSON.stringify(product)); - - done(); - }); - - it('should invoke ios sdk method clearCart', function(done) { - mParticle.eCommerce.Cart.clear(); - - JSON.parse(mParticleIOSV2Bridge.data[0]).should.have.properties( - ['path', 'value'] - ); - JSON.parse(mParticleIOSV2Bridge.data[0]).path.should.equal( - 'clearCart' - ); - - done(); - }); - it('should not sync cookies when in a mobile web view', function(done) { const pixelSettings = { name: 'AdobeEventForwarder', @@ -1336,17 +1118,7 @@ describe('native-sdk methods', function() { 10, 1 ); - - mParticle.eCommerce.Cart.add([product, product2]); - JSON.parse(mParticleIOSV2Bridge.data[0]).should.have.properties( - ['path', 'value'] - ); - JSON.parse(mParticleIOSV2Bridge.data[0]).path.should.equal( - 'addToCart' - ); - JSON.stringify( - JSON.parse(mParticleIOSV2Bridge.data[0]).value - ).should.equal(JSON.stringify([product, product2])); + mParticle.eCommerce.logProductAction(mParticle.ProductActionType.AddToCart, [product, product2]); const transactionAttributes = mParticle.eCommerce.createTransactionAttributes( 'TAid1', diff --git a/test/src/tests-persistence.ts b/test/src/tests-persistence.ts index 8d841e332..ce3c6f93e 100644 --- a/test/src/tests-persistence.ts +++ b/test/src/tests-persistence.ts @@ -8,8 +8,6 @@ import { testMPID, mParticle, MPConfig, - localStorageProductsV4, - LocalStorageProductsV4WithWorkSpaceName, workspaceCookieName, v4LSKey } from './config/constants'; @@ -23,7 +21,6 @@ import { const { findCookie, getLocalStorage, - getLocalStorageProducts, setCookie, setLocalStorage, findBatch, @@ -1613,54 +1610,6 @@ describe('persistence', () => { cgid.should.not.equal('4ebad5b4-8ed1-4275-8455-838a2e3aa5c0'); }); - it('integration test - clears LS products on reload if LS products are corrupt', async () => { - // randomly added gibberish to a Base64 encoded cart product array to force a corrupt product array - const products = - 'eyItOTE4MjY2NTAzNTA1ODg1NjAwMyI6eyasdjfiojasdifojfsdfJjcCI6W3siTmFtZSI6ImFuZHJvaWQiLCJTa3UiOiI1MTg3MDkiLCJQcmljZSI6MjM0LCJRdWFudGl0eSI6MSwiQnJhbmQiOm51bGwsIlZhcmlhbnQiOm51bGwsIkNhdGVnb3J5IjpudWxsLCJQb3NpdGlvbiI6bnVsbCwiQ291cG9uQ29kZSI6bnVsbCwiVG90YWxBbW91bnQiOjIzNCwiQXR0cmlidXRlcyI6eyJwcm9kYXR0cjEiOiJoaSJ9fSx7Ik5hbWUiOiJ3aW5kb3dzIiwiU2t1IjoiODMzODYwIiwiUHJpY2UiOjM0NSwiUXVhbnRpdHkiOjEsIlRvdGFsQW1vdW50IjozNDUsIkF0dHJpYnV0ZXMiOm51bGx9XX19'; - - localStorage.setItem(localStorageProductsV4, products); - mParticle.init(apiKey, mParticle.config); - await waitForCondition(hasIdentifyReturned); - - const productsAfterInit = getLocalStorageProducts().testMPID; - expect(productsAfterInit.length).to.not.be.ok; - }); - - it('should save products to persistence correctly when adding and removing products', async () => { - mParticle.init(apiKey, mParticle.config); - await waitForCondition(hasIdentifyReturned); - - const iphone = mParticle.eCommerce.createProduct( - 'iphone', - 'iphonesku', - 599, - 1, - 'iphone variant', - 'iphonecategory', - 'iphonebrand', - null, - 'iphonecoupon', - { iphoneattr1: 'value1', iphoneattr2: 'value2' } - ); - mParticle.eCommerce.Cart.add(iphone, true); - - let ls = localStorage.getItem(LocalStorageProductsV4WithWorkSpaceName); - const parsedProducts = JSON.parse(atob(ls)); - // parsedProducts should just have key of testMPID with value of cp with a single product - Object.keys(parsedProducts).length.should.equal(1); - parsedProducts['testMPID'].should.have.property('cp'); - parsedProducts['testMPID'].cp.length.should.equal(1); - - mParticle.eCommerce.Cart.remove(iphone, true); - ls = localStorage.getItem(LocalStorageProductsV4WithWorkSpaceName); - const parsedProductsAfter = JSON.parse(atob(ls)); - // parsedProducts should just have key of testMPID with value of cp with no products - - Object.keys(parsedProductsAfter).length.should.equal(1); - parsedProductsAfter['testMPID'].should.have.property('cp'); - parsedProductsAfter['testMPID'].cp.length.should.equal(0); - }); - it('should only set setFirstSeenTime() once', async () => { const cookies = JSON.stringify({ gs: { diff --git a/test/src/tests-session-manager.ts b/test/src/tests-session-manager.ts index 83750f7b6..94b97b43c 100644 --- a/test/src/tests-session-manager.ts +++ b/test/src/tests-session-manager.ts @@ -144,7 +144,7 @@ describe('SessionManager', () => { mpInstance._SessionManager.getSession(); expect(consoleSpy.lastCall.firstArg).to.equal( - 'SessionManager.getSession() is a deprecated method and will be removed in future releases SessionManager.getSessionId() is a deprecated method and will be removed in future releases' + 'SessionManager.getSession() is a deprecated method and will be removed in future releases. Please use the alternate method: SessionManager.getSessionId().' ); consoleSpy.restore(); diff --git a/test/src/tests-store.ts b/test/src/tests-store.ts index c3ca59671..60f962062 100644 --- a/test/src/tests-store.ts +++ b/test/src/tests-store.ts @@ -162,7 +162,6 @@ describe('Store', () => { 'isLocalStorageAvailable' ).to.eq(null); expect(store.storageName, 'storageName').to.eq(null); - expect(store.prodStorageName, 'prodStorageName').to.eq(null); expect(store.activeForwarders.length, 'activeForwarders').to.eq(0); expect(store.kits, 'kits').to.be.ok; expect(store.sideloadedKits, 'sideloaded kits').to.be.ok; @@ -1417,9 +1416,6 @@ describe('Store', () => { store.processConfig(config); expect(store.storageName, 'storageName').to.equal('mprtcl-v4_foo'); - expect(store.prodStorageName, 'prodStorageName').to.equal( - 'mprtcl-prodv4_foo' - ); expect(store.SDKConfig.workspaceToken, 'workspace token').to.equal( 'foo' );