From 3e4a73db685267e9a010d975ff597c7e86bfeec5 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Fri, 26 Sep 2025 13:59:04 -0400 Subject: [PATCH 1/6] chore: remove Products from StoragePrivacyMap --- src/constants.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 456b10539..003c78c3f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -232,11 +232,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', From b62107d2756391f08e544d4d81d2dd97ff2b1120 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Mon, 29 Sep 2025 16:24:11 -0400 Subject: [PATCH 2/6] chore: remove products cart related functionalities and update tests --- src/helpers.js | 10 - src/identity.js | 138 +----------- src/mp-instance.ts | 28 +-- src/persistence.interfaces.ts | 5 - src/persistence.js | 166 +------------- src/sdkRuntimeModels.ts | 1 - src/store.ts | 4 - test/src/config/utils.js | 12 - test/src/tests-eCommerce.js | 179 +-------------- test/src/tests-helpers.js | 17 -- test/src/tests-identities-attributes.ts | 24 -- test/src/tests-identity.ts | 248 +-------------------- test/src/tests-native-sdk.js | 283 ------------------------ test/src/tests-persistence.ts | 51 ----- test/src/tests-store.ts | 4 - 15 files changed, 21 insertions(+), 1149 deletions(-) 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.js b/src/identity.js index 795549546..73d34b9e6 100644 --- a/src/identity.js +++ b/src/identity.js @@ -1286,6 +1286,7 @@ export default function Identity(mpInstance) { * @class mParticle.Identity.getCurrentUser().getCart() * @deprecated */ + // eslint-disable-next-line no-unused-vars this.mParticleUserCart = function(mpid) { return { /** @@ -1295,66 +1296,11 @@ export default function Identity(mpInstance) { * @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs. * @deprecated */ + // eslint-disable-next-line no-unused-vars add: function(product, logEvent) { mpInstance.Logger.warning( - 'Deprecated function Identity.getCurrentUser().getCart().add() will be removed in future releases' + 'Deprecated function Identity.getCurrentUser().getCart().add()' ); - 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 @@ -1363,56 +1309,11 @@ export default function Identity(mpInstance) { * @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs. * @deprecated */ + // eslint-disable-next-line no-unused-vars remove: function(product, logEvent) { mpInstance.Logger.warning( - 'Deprecated function Identity.getCurrentUser().getCart().remove() will be removed in future releases' + 'Deprecated function Identity.getCurrentUser().getCart().remove()' ); - 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 +1322,8 @@ export default function Identity(mpInstance) { */ clear: function() { mpInstance.Logger.warning( - 'Deprecated function Identity.getCurrentUser().getCart().clear() will be removed in future releases' + 'Deprecated function Identity.getCurrentUser().getCart().clear()' ); - - 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 +1333,9 @@ export default function Identity(mpInstance) { */ getCartProducts: function() { mpInstance.Logger.warning( - 'Deprecated function Identity.getCurrentUser().getCart().getCartProducts() will be removed in future releases' + 'Deprecated function Identity.getCurrentUser().getCart().getCartProducts()' ); - return mpInstance._Persistence.getCartProducts(mpid); + return []; }, }; }; diff --git a/src/mp-instance.ts b/src/mp-instance.ts index 34d973a25..5da84a6dd 100644 --- a/src/mp-instance.ts +++ b/src/mp-instance.ts @@ -706,16 +706,8 @@ 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' + 'Deprecated function eCommerce.Cart.add()' ); - 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 +718,8 @@ 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' + 'Deprecated function eCommerce.Cart.remove()' ); - let mpid; - const currentUser = self.Identity.getCurrentUser(); - if (currentUser) { - mpid = currentUser.getMPID(); - } - self._Identity - .mParticleUserCart(mpid) - .remove(product, logEventBoolean); }, /** * Clears the cart @@ -744,14 +728,8 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan */ clear: function() { self.Logger.warning( - 'Deprecated function eCommerce.Cart.clear() will be removed in future releases' + 'Deprecated function eCommerce.Cart.clear()' ); - 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 cb40e2f8e..56442e04a 100644 --- a/src/persistence.js +++ b/src/persistence.js @@ -86,35 +86,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) { @@ -151,21 +122,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 { @@ -268,64 +224,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) { @@ -333,30 +231,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 || {}; @@ -893,42 +770,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(); @@ -1098,7 +939,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); @@ -1106,7 +946,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) { @@ -1117,9 +956,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/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/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..111c1d16f 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,7 +1521,7 @@ 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' + 'Deprecated function eCommerce.Cart.add()' ); }) }); @@ -1709,7 +1540,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' + 'Deprecated function eCommerce.Cart.remove()' ); }) }); @@ -1723,7 +1554,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' + 'Deprecated function eCommerce.Cart.clear()' ); }) }); 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..de0b20d5d 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, @@ -2059,159 +2058,6 @@ describe('identity', function() { done(); }); - it("should find the related MPID's cookies when given a UI with fewer IDs when passed to login, logout, and identify, and then log events with updated cookies", async () => { - mParticle._resetForTests(MPConfig); - fetchMock.restore(); - const user1: IdentityApiData = { - userIdentities: { - customerid: 'customerid1', - }, - }; - - const user1modified: IdentityApiData = { - userIdentities: { - email: 'email2@test.com', - }, - }; - - fetchMockSuccess(urls.events, {}); - fetchMockSuccess(urls.identify, { - context: null, - matched_identities: { - device_application_stamp: 'my-das', - }, - is_ephemeral: true, - mpid: testMPID, - is_logged_in: false, - }); - - mParticle.config.identifyRequest = user1; - - mParticle.init(apiKey, window.mParticle.config); - - fetchMockSuccess(urls.modify, { - change_results: [ - { - identity_type: 'email', - modified_mpid: testMPID, - }, - ], - }); - - await waitForCondition(hasIdentifyReturned) - mParticle.Identity.modify(user1modified); - // Should contain the following calls: - // 1 for the initial identify - // 3 for the events (Session Start, UAT and UIC) - // 1 for the modify - // 1 for the UIC event - await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(6); - - // This will add a new UAC Event to the call - 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); - - const testEvent1Batch = JSON.parse(fetchMock.calls()[7][1].body as string); - - expect(testEvent1Batch.user_attributes).to.deep.equal({ 'foo1': 'bar1' }); - expect(testEvent1Batch.user_identities).to.deep.equal({ - 'customer_id': 'customerid1', - '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', - }, - }; - - fetchMockSuccess(urls.logout, { - mpid: 'logged-out-user', - is_logged_in: true, - }); - - mParticle.Identity.logout(user2); - - await waitForCondition(hasLogOutReturned) - - // This will add the following new calls: - // 1 for the logout - // 1 for the UIC event - // 1 for Test Event 2 - mParticle.logEvent('Test Event 2'); - - expect(fetchMock.calls().length).to.equal(11); - - const testEvent2Batch = JSON.parse(fetchMock.calls()[10][1].body as string); - - Object.keys(testEvent2Batch.user_attributes).length.should.equal(0); - testEvent2Batch.user_identities.should.have.property( - 'customer_id', - 'customerid2' - ); - - fetchMockSuccess(urls.login, { - mpid: 'testMPID', - is_logged_in: true, - }); - - mParticle.Identity.login(user1); - await waitForCondition(() => { - return mParticle.Identity.getCurrentUser().getMPID() === 'testMPID'; - }) - - // This will add the following new calls: - // 1 for the login - // 1 for Test Event 3 - mParticle.logEvent('Test Event 3'); - expect(fetchMock.calls().length).to.equal(13); - - const testEvent3Batch = JSON.parse(fetchMock.calls()[12][1].body as string); - - expect(testEvent3Batch.user_attributes).to.deep.equal({'foo1': 'bar1'}); - expect(testEvent3Batch.user_identities).to.deep.equal({ - '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 () => { mParticle._resetForTests(MPConfig); @@ -2496,92 +2342,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 +4566,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' + 'Deprecated function Identity.getCurrentUser().getCart().add()' ); }); @@ -4835,7 +4595,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' + 'Deprecated function Identity.getCurrentUser().getCart().remove()' ); }); @@ -4857,7 +4617,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' + 'Deprecated function Identity.getCurrentUser().getCart().clear()' ); }); @@ -4880,7 +4640,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' + 'Deprecated function Identity.getCurrentUser().getCart().getCartProducts()' ); }); }); diff --git a/test/src/tests-native-sdk.js b/test/src/tests-native-sdk.js index 8b98c87fa..f64030925 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', @@ -1323,71 +1105,6 @@ describe('native-sdk methods', function() { done(); }); - it('should send an event with a product list when calling logPurchase', function(done) { - const product = mParticle.eCommerce.createProduct( - 'product1', - 'sku', - 10, - 1 - ); - const product2 = mParticle.eCommerce.createProduct( - 'product2', - 'sku', - 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])); - - const transactionAttributes = mParticle.eCommerce.createTransactionAttributes( - 'TAid1', - 'aff1', - 'coupon', - 1798, - 10, - 5 - ); - const clearCartBoolean = true; - const customAttributes = { value: 10 }; - const customFlags = { foo: 'bar' }; - mParticleIOSV2Bridge.data = []; - mParticle.eCommerce.logPurchase( - transactionAttributes, - [product, product2], - clearCartBoolean, - customAttributes, - customFlags - ); - - JSON.parse(mParticleIOSV2Bridge.data[0]).path.should.equal( - 'logEvent' - ); - JSON.parse( - mParticleIOSV2Bridge.data[0] - ).value.ProductAction.ProductList.length.should.equal(2); - JSON.parse( - mParticleIOSV2Bridge.data[0] - ).value.ProductAction.ProductList[0].Name.should.equal( - 'product1' - ); - JSON.parse( - mParticleIOSV2Bridge.data[0] - ).value.ProductAction.ProductList[1].Name.should.equal( - 'product2' - ); - - done(); - }); - it('should invoke upload on iOS SDK', function(done) { mParticle.upload(); diff --git a/test/src/tests-persistence.ts b/test/src/tests-persistence.ts index 424f4d616..52582dd27 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-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' ); From f17a1118efe8f2a2e10bbc6856d4da2db9d979d2 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Wed, 1 Oct 2025 17:09:06 -0400 Subject: [PATCH 3/6] chore: update deprecated content in generateDeprecationMessage --- src/constants.ts | 5 +++-- src/identity.js | 28 ++++++++++++++++++++++++---- src/mp-instance.ts | 23 +++++++++++++++++++---- src/sessionManager.ts | 2 +- src/utils.ts | 25 ++++++++++++++++--------- test/src/tests-identity.ts | 8 ++++---- test/src/tests-session-manager.ts | 2 +- 7 files changed, 68 insertions(+), 25 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 003c78c3f..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: { diff --git a/src/identity.js b/src/identity.js index 73d34b9e6..f4b62e72c 100644 --- a/src/identity.js +++ b/src/identity.js @@ -1299,7 +1299,12 @@ export default function Identity(mpInstance) { // eslint-disable-next-line no-unused-vars add: function(product, logEvent) { mpInstance.Logger.warning( - 'Deprecated function Identity.getCurrentUser().getCart().add()' + generateDeprecationMessage( + 'Identity.getCurrentUser().getCart().add()', + true, + 'eCommerce.logProductAction()', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); }, /** @@ -1312,7 +1317,12 @@ export default function Identity(mpInstance) { // eslint-disable-next-line no-unused-vars remove: function(product, logEvent) { mpInstance.Logger.warning( - 'Deprecated function Identity.getCurrentUser().getCart().remove()' + generateDeprecationMessage( + 'Identity.getCurrentUser().getCart().remove()', + true, + 'eCommerce.logProductAction()', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); }, /** @@ -1322,7 +1332,12 @@ export default function Identity(mpInstance) { */ clear: function() { mpInstance.Logger.warning( - 'Deprecated function Identity.getCurrentUser().getCart().clear()' + generateDeprecationMessage( + 'Identity.getCurrentUser().getCart().clear()', + true, + '', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); }, /** @@ -1333,7 +1348,12 @@ export default function Identity(mpInstance) { */ getCartProducts: function() { mpInstance.Logger.warning( - 'Deprecated function Identity.getCurrentUser().getCart().getCartProducts()' + generateDeprecationMessage( + 'Identity.getCurrentUser().getCart().getCartProducts()', + true, + 'eCommerce.logProductAction()', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); return []; }, diff --git a/src/mp-instance.ts b/src/mp-instance.ts index 5da84a6dd..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,7 +706,12 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan */ add: function(product, logEventBoolean) { self.Logger.warning( - 'Deprecated function eCommerce.Cart.add()' + generateDeprecationMessage( + 'eCommerce.Cart.add()', + true, + 'eCommerce.logProductAction()', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); }, /** @@ -718,7 +723,12 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan */ remove: function(product, logEventBoolean) { self.Logger.warning( - 'Deprecated function eCommerce.Cart.remove()' + generateDeprecationMessage( + 'eCommerce.Cart.remove()', + true, + 'eCommerce.logProductAction()', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); }, /** @@ -728,7 +738,12 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan */ clear: function() { self.Logger.warning( - 'Deprecated function eCommerce.Cart.clear()' + generateDeprecationMessage( + 'eCommerce.Cart.clear()', + true, + '', + 'https://docs.mparticle.com/developers/sdk/web/commerce-tracking' + ) ); }, }, 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/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/src/tests-identity.ts b/test/src/tests-identity.ts index de0b20d5d..5f43ce4f1 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -4566,7 +4566,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()' + 'Identity.getCurrentUser().getCart().add() has been deprecated. Please use the alternate method: eCommerce.logProductAction(). See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking' ); }); @@ -4595,7 +4595,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()' + 'Identity.getCurrentUser().getCart().remove() has been deprecated. Please use the alternate method: eCommerce.logProductAction(). See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking' ); }); @@ -4617,7 +4617,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()' + 'Identity.getCurrentUser().getCart().clear() has been deprecated. See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking' ); }); @@ -4640,7 +4640,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()' + '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-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(); From b9179e1a4db79ecc079d8495c1e8e99872d513d6 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Thu, 2 Oct 2025 11:51:52 -0400 Subject: [PATCH 4/6] chore: reverted tests for identity and native sdk, removed unused arguments from mParticleUserCart --- src/identity-user-interfaces.ts | 4 +- src/identity.interfaces.ts | 2 +- src/identity.js | 15 ++-- test/src/tests-eCommerce.js | 7 +- test/src/tests-identity.ts | 121 ++++++++++++++++++++++++++++++++ test/src/tests-native-sdk.js | 55 +++++++++++++++ 6 files changed, 187 insertions(+), 17 deletions(-) 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 f4b62e72c..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,18 +1286,14 @@ export default function Identity(mpInstance) { * @class mParticle.Identity.getCurrentUser().getCart() * @deprecated */ - // eslint-disable-next-line no-unused-vars - 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 */ - // eslint-disable-next-line no-unused-vars - add: function(product, logEvent) { + add: function() { mpInstance.Logger.warning( generateDeprecationMessage( 'Identity.getCurrentUser().getCart().add()', @@ -1310,12 +1306,9 @@ export default function Identity(mpInstance) { /** * 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 */ - // eslint-disable-next-line no-unused-vars - remove: function(product, logEvent) { + remove: function() { mpInstance.Logger.warning( generateDeprecationMessage( 'Identity.getCurrentUser().getCart().remove()', diff --git a/test/src/tests-eCommerce.js b/test/src/tests-eCommerce.js index 111c1d16f..de8044b98 100644 --- a/test/src/tests-eCommerce.js +++ b/test/src/tests-eCommerce.js @@ -1521,10 +1521,11 @@ describe('eCommerce', function() { bond.called.should.eql(true); bond.getCalls()[0].args[0].should.eql( - 'Deprecated function eCommerce.Cart.add()' + '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(() => { @@ -1540,7 +1541,7 @@ describe('eCommerce', function() { bond.called.should.eql(true); bond.getCalls()[0].args[0].should.eql( - 'Deprecated function eCommerce.Cart.remove()' + 'eCommerce.Cart.remove() has been deprecated. Please use the alternate method: eCommerce.logProductAction(). See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking' ); }) }); @@ -1554,7 +1555,7 @@ describe('eCommerce', function() { bond.called.should.eql(true); bond.getCalls()[0].args[0].should.eql( - 'Deprecated function eCommerce.Cart.clear()' + 'eCommerce.Cart.clear() has been deprecated. See - https://docs.mparticle.com/developers/sdk/web/commerce-tracking' ); }) }); diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 5f43ce4f1..2e4a99d41 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -2058,6 +2058,127 @@ describe('identity', function() { done(); }); + it("should find the related MPID's cookies when given a UI with fewer IDs when passed to login, logout, and identify, and then log events with updated cookies", async () => { + mParticle._resetForTests(MPConfig); + fetchMock.restore(); + const user1: IdentityApiData = { + userIdentities: { + customerid: 'customerid1', + }, + }; + + const user1modified: IdentityApiData = { + userIdentities: { + email: 'email2@test.com', + }, + }; + + fetchMockSuccess(urls.events, {}); + fetchMockSuccess(urls.identify, { + context: null, + matched_identities: { + device_application_stamp: 'my-das', + }, + is_ephemeral: true, + mpid: testMPID, + is_logged_in: false, + }); + + mParticle.config.identifyRequest = user1; + + mParticle.init(apiKey, window.mParticle.config); + + fetchMockSuccess(urls.modify, { + change_results: [ + { + identity_type: 'email', + modified_mpid: testMPID, + }, + ], + }); + + await waitForCondition(hasIdentifyReturned) + mParticle.Identity.modify(user1modified); + // Should contain the following calls: + // 1 for the initial identify + // 3 for the events (Session Start, UAT and UIC) + // 1 for the modify + // 1 for the UIC event + await waitForCondition(hasIdentityCallInflightReturned) + expect(fetchMock.calls().length).to.equal(6); + + // This will add a new UAC Event to the call + mParticle.Identity.getCurrentUser().setUserAttribute('foo1', 'bar1'); + expect(fetchMock.calls().length).to.equal(7); + + // This will add a new custom event to the call + mParticle.logEvent('Test Event 1'); + expect(fetchMock.calls().length).to.equal(8); + + const testEvent1Batch = JSON.parse(fetchMock.calls()[7][1].body as string); + + expect(testEvent1Batch.user_attributes).to.deep.equal({ 'foo1': 'bar1' }); + expect(testEvent1Batch.user_identities).to.deep.equal({ + 'customer_id': 'customerid1', + 'email': 'email2@test.com' + }); + + const user2 = { + userIdentities: { + customerid: 'customerid2', + }, + }; + + fetchMockSuccess(urls.logout, { + mpid: 'logged-out-user', + is_logged_in: true, + }); + + mParticle.Identity.logout(user2); + + await waitForCondition(hasLogOutReturned) + + // This will add the following new calls: + // 1 for the logout + // 1 for the UIC event + // 1 for Test Event 2 + mParticle.logEvent('Test Event 2'); + + expect(fetchMock.calls().length).to.equal(11); + + const testEvent2Batch = JSON.parse(fetchMock.calls()[10][1].body as string); + + Object.keys(testEvent2Batch.user_attributes).length.should.equal(0); + testEvent2Batch.user_identities.should.have.property( + 'customer_id', + 'customerid2' + ); + + fetchMockSuccess(urls.login, { + mpid: 'testMPID', + is_logged_in: true, + }); + + mParticle.Identity.login(user1); + await waitForCondition(() => { + return mParticle.Identity.getCurrentUser().getMPID() === 'testMPID'; + }) + + // This will add the following new calls: + // 1 for the login + // 1 for Test Event 3 + mParticle.logEvent('Test Event 3'); + expect(fetchMock.calls().length).to.equal(13); + + const testEvent3Batch = JSON.parse(fetchMock.calls()[12][1].body as string); + + expect(testEvent3Batch.user_attributes).to.deep.equal({'foo1': 'bar1'}); + expect(testEvent3Batch.user_identities).to.deep.equal({ + 'customer_id': 'customerid1', + 'email': 'email2@test.com' + }); + }); + it('should add new MPIDs to cookie structure when initializing new identity requests, returning an existing mpid when reinitializing with a previous identity', async () => { mParticle._resetForTests(MPConfig); diff --git a/test/src/tests-native-sdk.js b/test/src/tests-native-sdk.js index f64030925..a6801958e 100644 --- a/test/src/tests-native-sdk.js +++ b/test/src/tests-native-sdk.js @@ -1105,6 +1105,61 @@ describe('native-sdk methods', function() { done(); }); + it('should send an event with a product list when calling logPurchase', function(done) { + const product = mParticle.eCommerce.createProduct( + 'product1', + 'sku', + 10, + 1 + ); + const product2 = mParticle.eCommerce.createProduct( + 'product2', + 'sku', + 10, + 1 + ); + mParticle.eCommerce.logProductAction(mParticle.ProductActionType.AddToCart, [product, product2]); + + const transactionAttributes = mParticle.eCommerce.createTransactionAttributes( + 'TAid1', + 'aff1', + 'coupon', + 1798, + 10, + 5 + ); + const clearCartBoolean = true; + const customAttributes = { value: 10 }; + const customFlags = { foo: 'bar' }; + mParticleIOSV2Bridge.data = []; + mParticle.eCommerce.logPurchase( + transactionAttributes, + [product, product2], + clearCartBoolean, + customAttributes, + customFlags + ); + + JSON.parse(mParticleIOSV2Bridge.data[0]).path.should.equal( + 'logEvent' + ); + JSON.parse( + mParticleIOSV2Bridge.data[0] + ).value.ProductAction.ProductList.length.should.equal(2); + JSON.parse( + mParticleIOSV2Bridge.data[0] + ).value.ProductAction.ProductList[0].Name.should.equal( + 'product1' + ); + JSON.parse( + mParticleIOSV2Bridge.data[0] + ).value.ProductAction.ProductList[1].Name.should.equal( + 'product2' + ); + + done(); + }); + it('should invoke upload on iOS SDK', function(done) { mParticle.upload(); From c5ece6f66c3aab6ac26f7192bbd0173eab92da8c Mon Sep 17 00:00:00 2001 From: Jaissica Date: Thu, 2 Oct 2025 15:22:22 -0400 Subject: [PATCH 5/6] test: updated jest test for persitence --- test/jest/persistence.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/jest/persistence.spec.ts b/test/jest/persistence.spec.ts index c951b9587..116a8143b 100644 --- a/test/jest/persistence.spec.ts +++ b/test/jest/persistence.spec.ts @@ -13,7 +13,7 @@ describe('Persistence', () => { store = {} as IStore; mockMPInstance = { _Helpers: { - createMainStorageName: () => 'mprtcl-v4', + createMainStorageName: () => 'mprtcl-v4_'+ 'test-workspace-token', isObject, }, _NativeSdkHelpers: { @@ -33,6 +33,7 @@ describe('Persistence', () => { } as unknown as IMParticleWebSDKInstance; Store.call(store, {} as SDKInitConfig, mockMPInstance, 'apikey'); + store.processConfig({ workspaceToken: 'test-workspace-token' } as SDKInitConfig); store.isLocalStorageAvailable = true; store.SDKConfig.useCookieStorage = true; @@ -94,7 +95,7 @@ describe('Persistence', () => { expect(setCookieSpy).toHaveBeenCalled(); expect(setLocalStorageSpy).toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).not.toBeNull(); + expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).toBeNull(); }); it('should write to localStorage when useCookieStorage is false', () => { @@ -129,7 +130,7 @@ describe('Persistence', () => { expect(setCookieSpy).toHaveBeenCalled(); expect(setLocalStorageSpy).toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).not.toBeNull(); + expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).toBeNull(); }); it('should write to localStorage by default when useCookieStorage is false', () => { From 1365c498625933c54468da71dc2ead97aec4d8f8 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Thu, 2 Oct 2025 16:57:32 -0400 Subject: [PATCH 6/6] test: updated jest test for persistence state --- test/jest/persistence.spec.ts | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/test/jest/persistence.spec.ts b/test/jest/persistence.spec.ts index 116a8143b..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_'+ 'test-workspace-token', isObject, }, - _NativeSdkHelpers: { - isWebviewEnabled: () => false, - }, + _NativeSdkHelpers: {}, _Store: store, Identity: { getCurrentUser: jest.fn().mockReturnValue({ @@ -33,14 +30,12 @@ describe('Persistence', () => { } as unknown as IMParticleWebSDKInstance; Store.call(store, {} as SDKInitConfig, mockMPInstance, 'apikey'); - store.processConfig({ workspaceToken: 'test-workspace-token' } as SDKInitConfig); store.isLocalStorageAvailable = true; store.SDKConfig.useCookieStorage = true; store.webviewBridgeEnabled = false; persistence = new Persistence(mockMPInstance); - window.localStorage.removeItem(encodeURIComponent(store.storageName)); }); describe('#update', () => { @@ -60,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', () => { @@ -73,7 +67,6 @@ describe('Persistence', () => { expect(setCookieSpy).not.toHaveBeenCalled(); expect(setLocalStorageSpy).not.toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).toBeNull(); }); }); @@ -95,7 +88,6 @@ describe('Persistence', () => { expect(setCookieSpy).toHaveBeenCalled(); expect(setLocalStorageSpy).toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).toBeNull(); }); it('should write to localStorage when useCookieStorage is false', () => { @@ -108,7 +100,6 @@ describe('Persistence', () => { expect(setCookieSpy).not.toHaveBeenCalled(); expect(setLocalStorageSpy).toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).not.toBeNull(); }); }); @@ -130,7 +121,6 @@ describe('Persistence', () => { expect(setCookieSpy).toHaveBeenCalled(); expect(setLocalStorageSpy).toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).toBeNull(); }); it('should write to localStorage by default when useCookieStorage is false', () => { @@ -143,7 +133,6 @@ describe('Persistence', () => { expect(setCookieSpy).not.toHaveBeenCalled(); expect(setLocalStorageSpy).toHaveBeenCalled(); - expect(window.localStorage.getItem(encodeURIComponent(store.storageName))).not.toBeNull(); }); }); @@ -159,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