diff --git a/src/batchUploader.ts b/src/batchUploader.ts index 9f456dad..54acfb5a 100644 --- a/src/batchUploader.ts +++ b/src/batchUploader.ts @@ -72,9 +72,7 @@ export class BatchUploader { // Cache Offline Storage Availability boolean // so that we don't have to check it every time - this.offlineStorageEnabled = - this.isOfflineStorageAvailable() && - !mpInstance._Store.getPrivacyFlag('OfflineEvents'); + this.offlineStorageEnabled = this.isOfflineStorageAvailable(); if (this.offlineStorageEnabled) { this.eventVault = new SessionStorageVault( diff --git a/src/constants.ts b/src/constants.ts index 43a697a2..bf513a5d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -233,14 +233,3 @@ export const HTTP_UNAUTHORIZED = 401 as const; export const HTTP_FORBIDDEN = 403 as const; export const HTTP_NOT_FOUND = 404 as const; export const HTTP_SERVER_ERROR = 500 as const; - -export type PrivacyControl = 'functional' | 'targeting'; - -export type StorageTypes = 'SDKState' | 'OfflineEvents' | 'IdentityCache' | 'TimeOnSite'; - -export const StoragePrivacyMap: Record = { - SDKState: 'functional', - OfflineEvents: 'functional', - IdentityCache: 'functional', - TimeOnSite: 'targeting', -}; diff --git a/src/mp-instance.ts b/src/mp-instance.ts index fd32ef2b..661e4a63 100644 --- a/src/mp-instance.ts +++ b/src/mp-instance.ts @@ -37,7 +37,7 @@ import KitBlocker from './kitBlocking'; import ConfigAPIClient, { IKitConfigs } from './configAPIClient'; import IdentityAPIClient from './identityApiClient'; import { isFunction, parseConfig, valueof, generateDeprecationMessage } from './utils'; -import { DisabledVault, LocalStorageVault } from './vault'; +import { LocalStorageVault } from './vault'; import { removeExpiredIdentityCacheDates } from './identity-utils'; import IntegrationCapture from './integrationCapture'; import { IPreInit, processReadyQueue } from './pre-init-utils'; @@ -1543,11 +1543,9 @@ function createKitBlocker(config, mpInstance) { } function createIdentityCache(mpInstance) { - const cacheKey = `${mpInstance._Store.storageName}-id-cache`; - if (mpInstance._Store.getPrivacyFlag('IdentityCache')) { - return new DisabledVault(cacheKey, { logger: mpInstance.Logger }); - } - return new LocalStorageVault(cacheKey, { logger: mpInstance.Logger }); + return new LocalStorageVault(`${mpInstance._Store.storageName}-id-cache`, { + logger: mpInstance.Logger, + }); } function runPreConfigFetchInitialization(mpInstance, apiKey, config) { diff --git a/src/persistence.js b/src/persistence.js index fb0aec71..7a30d754 100644 --- a/src/persistence.js +++ b/src/persistence.js @@ -35,10 +35,6 @@ export default function _Persistence(mpInstance) { mpInstance._Store.isFirstRun = false; } - if (mpInstance._Store.getPrivacyFlag('SDKState')) { - return; - } - // https://go.mparticle.com/work/SQDSDKS-6045 if (!mpInstance._Store.isLocalStorageAvailable) { mpInstance._Store.SDKConfig.useCookieStorage = true; @@ -117,10 +113,7 @@ export default function _Persistence(mpInstance) { }; this.update = function() { - if ( - !mpInstance._Store.webviewBridgeEnabled && - !mpInstance._Store.getPrivacyFlag('SDKState') - ) { + if (!mpInstance._Store.webviewBridgeEnabled) { if (mpInstance._Store.SDKConfig.useCookieStorage) { self.setCookie(); } @@ -810,9 +803,6 @@ export default function _Persistence(mpInstance) { // https://go.mparticle.com/work/SQDSDKS-6021 this.savePersistence = function(persistence) { - if (mpInstance._Store.getPrivacyFlag('SDKState')) { - return; - } var encodedPersistence = self.encodePersistence( JSON.stringify(persistence) ), @@ -857,9 +847,6 @@ export default function _Persistence(mpInstance) { }; this.getPersistence = function() { - if (mpInstance._Store.getPrivacyFlag('SDKState')) { - return null; - } var persistence = this.useLocalStorage() ? this.getLocalStorage() : this.getCookie(); diff --git a/src/sdkRuntimeModels.ts b/src/sdkRuntimeModels.ts index 6e73ebc4..decab8a1 100644 --- a/src/sdkRuntimeModels.ts +++ b/src/sdkRuntimeModels.ts @@ -271,9 +271,6 @@ export interface SDKInitConfig extends Omit { dataPlan?: DataPlanConfig | KitBlockerDataPlan; // TODO: These should be eventually split into two different attributes logLevel?: LogLevelType; - - noFunctional?: boolean; - noTargeting?: boolean; kitConfigs?: IKitConfigs[]; kits?: Dictionary; diff --git a/src/store.ts b/src/store.ts index 43e1b413..64d560dc 100644 --- a/src/store.ts +++ b/src/store.ts @@ -8,7 +8,7 @@ import { UserIdentities, } from '@mparticle/web-sdk'; import { IKitConfigs } from './configAPIClient'; -import Constants, { PrivacyControl, StoragePrivacyMap, StorageTypes } from './constants'; +import Constants from './constants'; import { DataPlanResult, KitBlockerOptions, @@ -153,8 +153,6 @@ export interface IFeatureFlags { export interface IStore { isEnabled: boolean; isInitialized: boolean; - noFunctional: boolean; - noTargeting: boolean; // Session Attributes are persistent attributes that are tied to the current session and // are uploaded then cleared when the session ends. @@ -211,12 +209,6 @@ export interface IStore { _getFromPersistence?(mpid: MPID, key: string): T; _setPersistence?(mpid: MPID, key: string, value: T): void; - getNoFunctional?(): boolean; - setNoFunctional?(noFunctional: boolean): void; - getNoTargeting?(): boolean; - setNoTargeting?(noTargeting: boolean): void; - getPrivacyFlag?(storageType: StorageTypes): boolean; - getDeviceId?(): string; setDeviceId?(deviceId: string): void; getFirstSeenTime?(mpid: MPID): number; @@ -252,8 +244,6 @@ export default function Store( const defaultStore: Partial = { isEnabled: true, - noFunctional: false, - noTargeting: false, sessionAttributes: {}, localSessionAttributes: {}, currentSessionMPIDs: [], @@ -596,27 +586,6 @@ export default function Store( } }; - this.getNoFunctional = (): boolean => this.noFunctional; - this.setNoFunctional = (noFunctional: boolean): void => { - this.noFunctional = noFunctional; - }; - - this.getNoTargeting = (): boolean => this.noTargeting; - this.setNoTargeting = (noTargeting: boolean): void => { - this.noTargeting = noTargeting; - }; - - this.getPrivacyFlag = (storageType: StorageTypes): boolean => { - const privacyControl: PrivacyControl = StoragePrivacyMap[storageType]; - if (privacyControl === 'functional') { - return this.getNoFunctional(); - } - if (privacyControl === 'targeting') { - return this.getNoTargeting(); - } - return false; - }; - this.getDeviceId = () => this.deviceId; this.setDeviceId = (deviceId: string) => { this.deviceId = deviceId; @@ -737,21 +706,9 @@ export default function Store( this.SDKConfig[baseUrlKeys] = baseUrls[baseUrlKeys]; } - const { noFunctional, noTargeting } = config?.launcherOptions ?? {}; - - if (noFunctional != null) { - this.setNoFunctional(noFunctional); - } - - if (noTargeting != null) { - this.setNoTargeting(noTargeting); - } - if (workspaceToken) { this.SDKConfig.workspaceToken = workspaceToken; - if (!this.getPrivacyFlag('TimeOnSite')) { - mpInstance._timeOnSiteTimer = new ForegroundTimer(workspaceToken); - } + mpInstance._timeOnSiteTimer = new ForegroundTimer(workspaceToken); } else { mpInstance.Logger.warning( 'You should have a workspaceToken on your config object for security purposes.' diff --git a/src/vault.ts b/src/vault.ts index eb0bcafb..57d2a6dc 100644 --- a/src/vault.ts +++ b/src/vault.ts @@ -102,20 +102,4 @@ export class SessionStorageVault extends BaseVault { constructor(storageKey: string, options?: IVaultOptions) { super(storageKey, window.sessionStorage, options); } -} - -// DisabledVault is used when persistence is disabled by privacy flags. -export class DisabledVault extends BaseVault { - constructor(storageKey: string, options?: IVaultOptions) { - super(storageKey, window.localStorage, options); - this.contents = null; - } - - public store(_item: StorableItem): void { - this.contents = null; - } - - public retrieve(): StorableItem | null { - return this.contents; - } } \ No newline at end of file diff --git a/test/jest/batchUploader.spec.ts b/test/jest/batchUploader.spec.ts index 35f35c3f..03a8542d 100644 --- a/test/jest/batchUploader.spec.ts +++ b/test/jest/batchUploader.spec.ts @@ -1,8 +1,5 @@ import { BatchUploader } from '../../src/batchUploader'; import { IMParticleWebSDKInstance } from '../../src/mp-instance'; -import { IStore } from '../../src/store'; -import { StoragePrivacyMap, StorageTypes } from '../../src/constants'; -import { SDKEvent } from '../../src/sdkRuntimeModels'; describe('BatchUploader', () => { let batchUploader: BatchUploader; @@ -21,39 +18,18 @@ describe('BatchUploader', () => { // Create a mock mParticle instance with mocked methods for instantiating a BatchUploader mockMPInstance = { _Store: { - storageName: 'mprtcl-v4_abcdef', - getNoFunctional: function(this: IStore) { return this.noFunctional; }, - getNoTargeting: function(this: IStore) { return this.noTargeting; }, - getPrivacyFlag: function(this: IStore, storageType: StorageTypes) { - const privacyControl = StoragePrivacyMap[storageType]; - if (privacyControl === 'functional') { - return this.getNoFunctional(); - } - if (privacyControl === 'targeting') { - return this.getNoTargeting(); - } - return false; - }, - deviceId: 'device-1', SDKConfig: { flags: {} } }, _Helpers: { - getFeatureFlag: jest.fn().mockReturnValue('100'), + getFeatureFlag: jest.fn().mockReturnValue(false), createServiceUrl: jest.fn().mockReturnValue('https://mock-url.com'), - generateUniqueId: jest.fn().mockReturnValue('req-1'), }, Identity: { getCurrentUser: jest.fn().mockReturnValue({ - getMPID: () => 'test-mpid', - getConsentState: jest.fn().mockReturnValue(null), + getMPID: () => 'test-mpid' }) - }, - Logger: { - verbose: jest.fn(), - error: jest.fn(), - warning: jest.fn(), } } as unknown as IMParticleWebSDKInstance; @@ -132,50 +108,4 @@ describe('BatchUploader', () => { expect(secondCallTime).toBe(firstCallTime); }); }); - - describe('noFunctional', () => { - beforeEach(() => { - localStorage.clear(); - sessionStorage.clear(); - }); - - it('should disable offline storage when noFunctional is true', () => { - mockMPInstance._Store.noFunctional = true; - - const uploader = new BatchUploader(mockMPInstance, 1000); - expect(uploader['offlineStorageEnabled']).toBe(false); - - uploader.queueEvent({ EventDataType: 4 } as SDKEvent); - expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).toBeNull(); - expect(localStorage.getItem('mprtcl-v4_abcdef-batches')).toBeNull(); - }); - - it('should enable offline storage when noFunctional is false by default', async () => { - const uploader = new BatchUploader(mockMPInstance, 1000); - - expect(uploader['offlineStorageEnabled']).toBe(true); - - uploader.queueEvent({ EventDataType: 4 } as SDKEvent); - expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).not.toBeNull(); - - jest.advanceTimersByTime(1000); - await Promise.resolve(); - - expect(localStorage.getItem('mprtcl-v4_abcdef-batches')).not.toBeNull(); - }); - - it('should enable offline storage when noFunctional is false', async () => { - mockMPInstance._Store.noFunctional = false; - - const uploader = new BatchUploader(mockMPInstance, 1000); - - uploader.queueEvent({ EventDataType: 4 } as SDKEvent); - expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).not.toBeNull(); - - jest.advanceTimersByTime(1000); - await Promise.resolve(); - - expect(localStorage.getItem('mprtcl-v4_abcdef-batches')).not.toBeNull(); - }); - }); }); \ No newline at end of file diff --git a/test/jest/foregroundTimeTracker.spec.ts b/test/jest/foregroundTimeTracker.spec.ts index c4941bb9..7f4ab1ee 100644 --- a/test/jest/foregroundTimeTracker.spec.ts +++ b/test/jest/foregroundTimeTracker.spec.ts @@ -1,7 +1,4 @@ import ForegroundTimeTracker from '../../src/foregroundTimeTracker'; -import Store, { IStore } from '../../src/store'; -import { SDKInitConfig } from '../../src/sdkRuntimeModels'; -import { IMParticleWebSDKInstance } from '../../src/mp-instance'; describe('ForegroundTimeTracker', () => { let foregroundTimeTracker: ForegroundTimeTracker; @@ -493,65 +490,4 @@ describe('ForegroundTimeTracker', () => { expect(updatePersistenceSpy).toHaveBeenCalled(); }); }); - - describe('#privacy flags', () => { - const workspaceToken = 'abcdef'; - const tosKey = `mprtcl-tos-${workspaceToken}`; - let mockMPInstance: IMParticleWebSDKInstance; - let store: IStore; - - beforeEach(() => { - jest.useFakeTimers({ now: Date.now(), advanceTimers: true }); - localStorage.clear(); - - mockMPInstance = { - _Helpers: { - createMainStorageName: () => `mprtcl-v4_${workspaceToken}`, - createProductStorageName: () => `mprtcl-prodv4_${workspaceToken}`, - Validators: { isFunction: () => true }, - extend: Object.assign, - }, - _NativeSdkHelpers: { isWebviewEnabled: () => false }, - _Persistence: { - update: jest.fn(), - savePersistence: jest.fn(), - getPersistence: () => ({ gs: {} }), - }, - Logger: { verbose: jest.fn(), warning: jest.fn(), error: jest.fn() }, - Identity: { getCurrentUser: () => ({ getMPID: () => 'mpid' }) }, - _timeOnSiteTimer: undefined as any, - } as unknown as IMParticleWebSDKInstance; - - store = {} as IStore; - (Store as any).call(store, {} as SDKInitConfig, mockMPInstance, 'apikey'); - mockMPInstance._Store = store; - }); - - afterEach(() => { - jest.useRealTimers(); - localStorage.clear(); - }); - - it('should track time on site when noTargeting is false by default', () => { - store.processConfig({ workspaceToken } as SDKInitConfig); - expect(mockMPInstance._timeOnSiteTimer).toBeDefined(); - jest.advanceTimersByTime(1000); - mockMPInstance._timeOnSiteTimer.getTimeInForeground(); - expect(localStorage.getItem(tosKey)).not.toBeNull(); - }); - - it('should NOT track time on site when noTargeting is true', () => { - store.processConfig({ workspaceToken, launcherOptions: { noTargeting: true } } as SDKInitConfig); - expect(mockMPInstance._timeOnSiteTimer).toBeUndefined(); - expect(localStorage.getItem(tosKey)).toBeNull(); - }); - - it('should track time on site when noTargeting is false', () => { - store.processConfig({ workspaceToken, launcherOptions: { noTargeting: false } } as SDKInitConfig); - expect(mockMPInstance._timeOnSiteTimer).toBeDefined(); - jest.advanceTimersByTime(1000); - mockMPInstance._timeOnSiteTimer.getTimeInForeground(); - expect(localStorage.getItem(tosKey)).not.toBeNull(); - }); - }); }); \ No newline at end of file diff --git a/test/jest/persistence.spec.ts b/test/jest/persistence.spec.ts index c1f7e861..4e825008 100644 --- a/test/jest/persistence.spec.ts +++ b/test/jest/persistence.spec.ts @@ -39,105 +39,33 @@ describe('Persistence', () => { }); describe('#update', () => { - describe('noFunctional privacy flag set to true', () => { - beforeEach(() => { - store.setNoFunctional(true); - store.webviewBridgeEnabled = false; - }); - - it('should NOT write to cookie and localStorage when useCookieStorage is true', () => { - store.SDKConfig.useCookieStorage = true; - - const setCookieSpy = jest.spyOn(persistence, 'setCookie'); - const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); - - persistence.update(); - - expect(setCookieSpy).not.toHaveBeenCalled(); - expect(setLocalStorageSpy).not.toHaveBeenCalled(); - }); - - it('should NOT write to localStorage when useCookieStorage is false', () => { - store.SDKConfig.useCookieStorage = false; - - const setCookieSpy = jest.spyOn(persistence, 'setCookie'); - const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); - - persistence.update(); - - expect(setCookieSpy).not.toHaveBeenCalled(); - expect(setLocalStorageSpy).not.toHaveBeenCalled(); - }); - }); - - describe('noFunctional privacy flag set to false', () => { - beforeEach(() => { - store.setNoFunctional(false); - store.webviewBridgeEnabled = false; - }); - - it('should write to cookie and localStorage when useCookieStorage is true', () => { - store.SDKConfig.useCookieStorage = true; - - jest.spyOn(persistence, 'getCookie').mockReturnValue(null); - - const setCookieSpy = jest.spyOn(persistence, 'setCookie'); - const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); - - persistence.update(); - - expect(setCookieSpy).toHaveBeenCalled(); - expect(setLocalStorageSpy).toHaveBeenCalled(); - }); + it('should write to cookie and localStorage by default when useCookieStorage is true', () => { + store.SDKConfig.useCookieStorage = true; - it('should write to localStorage when useCookieStorage is false', () => { - store.SDKConfig.useCookieStorage = false; + jest.spyOn(persistence, 'getCookie').mockReturnValue(null); - const setCookieSpy = jest.spyOn(persistence, 'setCookie'); - const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); + const setCookieSpy = jest.spyOn(persistence, 'setCookie'); + const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); - persistence.update(); + persistence.update(); - expect(setCookieSpy).not.toHaveBeenCalled(); - expect(setLocalStorageSpy).toHaveBeenCalled(); - }); + expect(setCookieSpy).toHaveBeenCalled(); + expect(setLocalStorageSpy).toHaveBeenCalled(); }); - describe('noFunctional privacy flag set to false by default', () => { - beforeEach(() => { - // default is false - store.webviewBridgeEnabled = false; - }); - - it('should write to cookie and localStorage by default when useCookieStorage is true', () => { - store.SDKConfig.useCookieStorage = true; - - jest.spyOn(persistence, 'getCookie').mockReturnValue(null); - - const setCookieSpy = jest.spyOn(persistence, 'setCookie'); - const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); + it('should write to localStorage by default when useCookieStorage is false', () => { + store.SDKConfig.useCookieStorage = false; - persistence.update(); - - expect(setCookieSpy).toHaveBeenCalled(); - expect(setLocalStorageSpy).toHaveBeenCalled(); - }); - - it('should write to localStorage by default when useCookieStorage is false', () => { - store.SDKConfig.useCookieStorage = false; - - const setCookieSpy = jest.spyOn(persistence, 'setCookie'); - const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); + const setCookieSpy = jest.spyOn(persistence, 'setCookie'); + const setLocalStorageSpy = jest.spyOn(persistence, 'setLocalStorage'); - persistence.update(); + persistence.update(); - expect(setCookieSpy).not.toHaveBeenCalled(); - expect(setLocalStorageSpy).toHaveBeenCalled(); - }); + expect(setCookieSpy).not.toHaveBeenCalled(); + expect(setLocalStorageSpy).toHaveBeenCalled(); }); it('should NOT write to storage when webviewBridgeEnabled is true', () => { - store.setNoFunctional(false); store.webviewBridgeEnabled = true; store.SDKConfig.useCookieStorage = true; diff --git a/test/jest/roktManager.spec.ts b/test/jest/roktManager.spec.ts index 69085d04..45234218 100644 --- a/test/jest/roktManager.spec.ts +++ b/test/jest/roktManager.spec.ts @@ -310,8 +310,6 @@ describe('RoktManager', () => { it('should initialize the manager with launcher options from options', () => { const launcherOptions = { integrationName: 'customName', - noFunctional: true, - noTargeting: true }; roktManager.init( diff --git a/test/jest/store.flags.spec.ts b/test/jest/store.flags.spec.ts deleted file mode 100644 index ce383ce5..00000000 --- a/test/jest/store.flags.spec.ts +++ /dev/null @@ -1,82 +0,0 @@ -import Store, { IStore } from '../../src/store'; -import { IMParticleWebSDKInstance } from '../../src/mp-instance'; -import { SDKInitConfig } from '../../src/sdkRuntimeModels'; - -describe('Store privacy flags', () => { - let store: IStore & Record; - let mockMPInstance: IMParticleWebSDKInstance & Record; - - beforeEach(() => { - mockMPInstance = { - _Helpers: { - createMainStorageName: () => 'mprtcl-v4', - createProductStorageName: () => 'mprtcl-prodv4', - Validators: { isFunction: () => true }, - extend: Object.assign, - }, - _NativeSdkHelpers: { - isWebviewEnabled: () => false, - }, - _Persistence: { - update: () => {}, - savePersistence: () => {}, - getPersistence: () => ({ gs: {} }), - }, - Logger: { - verbose: () => {}, - warning: () => {}, - error: () => {}, - }, - Identity: { - getCurrentUser: () => ({ getMPID: () => 'mpid' }), - }, - } as any; - - store = {} as any; - // Construct Store with our mock 'this' - (Store as any).call(store, {} as SDKInitConfig, mockMPInstance, 'apikey'); - }); - - it('should default noFunctional and noTargeting to false when not provided', () => { - const cfg: SDKInitConfig = { flags: {} } as any; - store.processConfig(cfg); - expect(store.getNoFunctional()).toBe(false); - expect(store.getNoTargeting()).toBe(false); - }); - - it('should set noFunctional as true and noTargeting as true from config', () => { - const cfg: SDKInitConfig = { - launcherOptions: { noFunctional: true, noTargeting: true }, - flags: {}, - } as any; - - store.processConfig(cfg); - - expect(store.getNoFunctional()).toBe(true); - expect(store.getNoTargeting()).toBe(true); - }); - - it('should set noFunctional as true and noTargeting as false from config', () => { - const cfg: SDKInitConfig = { - launcherOptions: { noFunctional: true, noTargeting: false }, - flags: {}, - } as any; - - store.processConfig(cfg); - - expect(store.getNoFunctional()).toBe(true); - expect(store.getNoTargeting()).toBe(false); - }); - - it('should set noFunctional as false and noTargeting as true from config', () => { - const cfg: SDKInitConfig = { - launcherOptions: { noFunctional: false, noTargeting: true }, - flags: {}, - } as any; - - store.processConfig(cfg); - - expect(store.getNoFunctional()).toBe(false); - expect(store.getNoTargeting()).toBe(true); - }); -}); \ No newline at end of file diff --git a/test/src/tests-batchUploader.ts b/test/src/tests-batchUploader.ts index 681a0b0d..f2e95986 100644 --- a/test/src/tests-batchUploader.ts +++ b/test/src/tests-batchUploader.ts @@ -1381,94 +1381,5 @@ describe('batch uploader', () => { 'Batch 4: AST' ).to.equal('application_state_transition'); }); - - describe('noFunctional', () => { - const eventStorageKey = 'mprtcl-v4_abcdef-events'; - const batchStorageKey = 'mprtcl-v4_abcdef-batches'; - - it('should store batches in session storage when noFunctional is false by default', async () => { - window.mParticle.config.flags = { - offlineStorage: '100', - ...enableBatchingConfigFlags, - }; - window.mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned); - const mpInstance = window.mParticle.getInstance(); - const uploader = mpInstance._APIClient.uploader; - uploader.queueEvent(event0); - expect(window.sessionStorage.getItem(eventStorageKey)).to.not.equal(null); - }); - - it('should NOT store events in session storage when noFunctional is true', async () => { - window.mParticle.config.flags = { - offlineStorage: '100', - ...enableBatchingConfigFlags, - }; - window.mParticle.config.launcherOptions = { noFunctional: true }; - window.mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned); - const mpInstance = window.mParticle.getInstance(); - const uploader = mpInstance._APIClient.uploader; - uploader.queueEvent(event0); - expect(window.sessionStorage.getItem(eventStorageKey)).to.equal(null); - }); - - it('should store events in session storage when noFunctional is false', async () => { - window.mParticle.config.flags = { - offlineStorage: '100', - ...enableBatchingConfigFlags, - }; - window.mParticle.config.launcherOptions = { noFunctional: false }; - window.mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned); - const mpInstance = window.mParticle.getInstance(); - const uploader = mpInstance._APIClient.uploader; - uploader.queueEvent(event0); - expect(window.sessionStorage.getItem(eventStorageKey)).to.not.equal(null); - }); - - it('should store batches in local storage when noFunctional is false by default', async () => { - window.mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned); - const mpInstance = window.mParticle.getInstance(); - const uploader = mpInstance._APIClient.uploader; - fetchMock.post(urls.events, 500, { overwriteRoutes: true }); - uploader.queueEvent(event0); - await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload(); - expect(window.localStorage.getItem(batchStorageKey)).to.not.equal(null); - }); - - it('should NOT store batches in local storage when noFunctional is true', async () => { - window.mParticle.config.flags = { - offlineStorage: '100', - ...enableBatchingConfigFlags, - }; - window.mParticle.config.launcherOptions = { noFunctional: true }; - window.mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned); - const mpInstance = window.mParticle.getInstance(); - const uploader = mpInstance._APIClient.uploader; - uploader.queueEvent(event0); - await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload(); - expect(window.localStorage.getItem(batchStorageKey)).to.equal(null); - }); - - it('should store batches in local storage when noFunctional is false', async () => { - window.mParticle.config.flags = { - offlineStorage: '100', - ...enableBatchingConfigFlags, - }; - window.mParticle.config.launcherOptions = { noFunctional: false }; - window.mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned); - const mpInstance = window.mParticle.getInstance(); - const uploader = mpInstance._APIClient.uploader; - fetchMock.post(urls.events, 500, { overwriteRoutes: true }); - uploader.queueEvent(event0); - await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload(); - expect(window.localStorage.getItem(batchStorageKey)).to.not.equal(null); - }); - - }); }); }); \ No newline at end of file diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index ad52b9cb..48143d7c 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -643,35 +643,6 @@ describe('identity', function() { }); }); - describe('privacy flags', function() { - beforeEach(function() { - mParticle.config.flags.cacheIdentity = 'True'; - localStorage.clear(); - }); - - describe('#createIdentityCache', function() { - it('should save id cache to local storage when noFunctional is false by default', async () => { - mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned); - expect(localStorage.getItem('mprtcl-v4_abcdef-id-cache')).to.be.ok; - }); - - it('should NOT save id cache to local storage when noFunctional is true', async () => { - mParticle.config.launcherOptions = { noFunctional: true }; - mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned); - expect(localStorage.getItem('mprtcl-v4_abcdef-id-cache')).not.to.be.ok; - }); - - it('should save id cache to local storage when noFunctional is false', async () => { - mParticle.config.launcherOptions = { noFunctional: false }; - mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned); - expect(localStorage.getItem('mprtcl-v4_abcdef-id-cache')).to.be.ok; - }); - }); - }); - it('should respect consent rules on consent-change', async () => { await waitForCondition(hasIdentityCallInflightReturned); mParticle._resetForTests(MPConfig); diff --git a/test/src/tests-persistence.ts b/test/src/tests-persistence.ts index 045ff7f7..97516200 100644 --- a/test/src/tests-persistence.ts +++ b/test/src/tests-persistence.ts @@ -1876,86 +1876,4 @@ describe('persistence', () => { user2.getAllUserAttributes()['ua-list'][1].should.equal(''); user2.getAllUserAttributes()['ua-1'].should.equal('a'); }); - - describe('noFunctional privacy flag', () => { - describe('set to true', () => { - beforeEach(() => { - mParticle.config.launcherOptions = { noFunctional: true }; - }); - - it('should NOT store cookie when useCookieStorage = true', async () => { - mParticle.config.useCookieStorage = true; - - mParticle.init(apiKey, mParticle.config); - await waitForCondition(hasIdentifyReturned); - - mParticle.getInstance()._Persistence.update(); - - expect(findCookie()).to.not.be.ok; - }); - - it('should NOT write localStorage when useCookieStorage = false', async () => { - mParticle.config.useCookieStorage = false; - - mParticle.init(apiKey, mParticle.config); - await waitForCondition(hasIdentifyReturned); - - mParticle.getInstance()._Persistence.update(); - - expect(getLocalStorage()).to.not.be.ok; - }); - }); - - describe('set to false', () => { - beforeEach(() => { - mParticle.config.launcherOptions = { noFunctional: false }; - }); - - it('should store cookie when useCookieStorage = true', async () => { - mParticle.config.useCookieStorage = true; - - mParticle.init(apiKey, mParticle.config); - await waitForCondition(hasIdentifyReturned); - - mParticle.getInstance()._Persistence.update(); - - expect(findCookie()).to.be.ok; - }); - - it('should store localStorage when useCookieStorage = false', async () => { - mParticle.config.useCookieStorage = false; - - mParticle.init(apiKey, mParticle.config); - await waitForCondition(hasIdentifyReturned); - - mParticle.getInstance()._Persistence.update(); - - expect(getLocalStorage()).to.be.ok; - }); - }); - - describe('is false by default', () => { - it('should store cookie when useCookieStorage = true', async () => { - mParticle.config.useCookieStorage = true; - - mParticle.init(apiKey, mParticle.config); - await waitForCondition(hasIdentifyReturned); - - mParticle.getInstance()._Persistence.update(); - - expect(findCookie()).to.be.ok; - }); - - it('should store localStorage when useCookieStorage = false', async () => { - mParticle.config.useCookieStorage = false; - - mParticle.init(apiKey, mParticle.config); - await waitForCondition(hasIdentifyReturned); - - mParticle.getInstance()._Persistence.update(); - - expect(getLocalStorage()).to.be.ok; - }); - }); - }); }); \ No newline at end of file diff --git a/test/src/tests-store.ts b/test/src/tests-store.ts index 418b5499..774d0822 100644 --- a/test/src/tests-store.ts +++ b/test/src/tests-store.ts @@ -1805,25 +1805,4 @@ describe('Store', () => { }); }); }); - - describe('#privacy flags', () => { - it('should set noFunctional and noTargeting to false when not provided', () => { - const inst = window.mParticle.getInstance(); - const store = (inst as any)._Store; - expect(store.getNoFunctional()).to.equal(false); - expect(store.getNoTargeting()).to.equal(false); - }); - - it('should set noFunctional and noTargeting from init config', () => { - window.mParticle.config = window.mParticle.config || {}; - window.mParticle.config.launcherOptions = { noFunctional: true, noTargeting: true }; - - window.mParticle.init(apiKey, window.mParticle.config); - - const inst = window.mParticle.getInstance(); - const store = (inst as any)._Store; - expect(store.getNoFunctional()).to.equal(true); - expect(store.getNoTargeting()).to.equal(true); - }); - }); }); \ No newline at end of file diff --git a/test/src/vault.spec.ts b/test/src/vault.spec.ts index d264327c..c9ee5308 100644 --- a/test/src/vault.spec.ts +++ b/test/src/vault.spec.ts @@ -1,7 +1,7 @@ import { Batch } from '@mparticle/event-models'; import { expect } from 'chai'; import { Dictionary } from '../../src/utils'; -import { SessionStorageVault, LocalStorageVault, DisabledVault } from '../../src/vault'; +import { SessionStorageVault, LocalStorageVault } from '../../src/vault'; const testObject: Dictionary> = { foo: { foo: 'bar', buzz: 'bazz' }, @@ -419,76 +419,4 @@ describe('Vault', () => { ); }); }); - - describe('DisabledVault', () => { - afterEach(() => { - window.localStorage.clear(); - }); - - describe('#store', () => { - it('should NOT write to localStorage', () => { - const storageKey = 'test-disabled-store-empty'; - const vault = new DisabledVault(storageKey); - - vault.store('testString'); - - expect(vault.contents).to.equal(null); - expect(window.localStorage.getItem(storageKey)).to.equal(null); - }); - - it('should NOT overwrite existing localStorage value and keep contents null', () => { - const storageKey = 'test-disabled-store-existing'; - window.localStorage.setItem(storageKey, 'existingItem'); - - const vault = new DisabledVault(storageKey); - - vault.store('newValue'); - - expect(vault.contents).to.equal(null); - expect(window.localStorage.getItem(storageKey)).to.equal('existingItem'); - }); - }); - - describe('#retrieve', () => { - it('should return null when nothing is stored', () => { - const storageKey = 'test-disabled-retrieve-empty'; - const vault = new DisabledVault(storageKey); - const retrievedItem = vault.retrieve(); - expect(retrievedItem).to.equal(null); - }); - - it('should return null even if localStorage has a value', () => { - const storageKey = 'test-disabled-retrieve-existing'; - window.localStorage.setItem(storageKey, 'existingItem'); - - const vault = new DisabledVault(storageKey); - const retrievedItem = vault.retrieve(); - expect(retrievedItem).to.equal(null); - expect(window.localStorage.getItem(storageKey)).to.equal('existingItem'); - }); - }); - - describe('#purge', () => { - it('should keep contents null when purging', () => { - const storageKey = 'test-disabled-purge-existing'; - window.localStorage.setItem(storageKey, 'existing'); - - const vault = new DisabledVault(storageKey); - - vault.purge(); - - expect(vault.contents).to.equal(null); - expect(window.localStorage.getItem(storageKey)).to.equal(null); - }); - - it('should keep contents null when purging an empty key', () => { - const storageKey = 'test-disabled-purge-empty'; - const vault = new DisabledVault(storageKey); - - vault.purge(); - expect(vault.contents).to.equal(null); - expect(window.localStorage.getItem(storageKey)).to.equal(null); - }); - }); - }); }); \ No newline at end of file