Skip to content

Commit 9235483

Browse files
jaissica12Jaissica Hora
andauthored
feat: added noFunctional and noTargeting flags (#1059)
* feat: added noFunctional and noTargeting flags * test: added jest and chai test for privacy flags * chore: removed extra parentheses, updated test * chore: updated test content --------- Co-authored-by: Jaissica Hora <[email protected]>
1 parent 77a04ee commit 9235483

File tree

4 files changed

+139
-0
lines changed

4 files changed

+139
-0
lines changed

src/sdkRuntimeModels.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ export interface SDKInitConfig
270270
extends Omit<MPConfiguration, 'dataPlan' | 'logLevel'> {
271271
dataPlan?: DataPlanConfig | KitBlockerDataPlan; // TODO: These should be eventually split into two different attributes
272272
logLevel?: LogLevelType;
273+
274+
noFunctional?: boolean;
275+
noTargeting?: boolean;
273276

274277
kitConfigs?: IKitConfigs[];
275278
kits?: Dictionary<UnregisteredKit>;

src/store.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ export interface IFeatureFlags {
152152
export interface IStore {
153153
isEnabled: boolean;
154154
isInitialized: boolean;
155+
noFunctional: boolean;
156+
noTargeting: boolean;
155157

156158
// Session Attributes are persistent attributes that are tied to the current session and
157159
// are uploaded then cleared when the session ends.
@@ -209,6 +211,11 @@ export interface IStore {
209211
_getFromPersistence?<T>(mpid: MPID, key: string): T;
210212
_setPersistence?<T>(mpid: MPID, key: string, value: T): void;
211213

214+
getNoFunctional?(): boolean;
215+
setNoFunctional?(noFunctional: boolean): void;
216+
getNoTargeting?(): boolean;
217+
setNoTargeting?(noTargeting: boolean): void;
218+
212219
getDeviceId?(): string;
213220
setDeviceId?(deviceId: string): void;
214221
getFirstSeenTime?(mpid: MPID): number;
@@ -245,6 +252,8 @@ export default function Store(
245252

246253
const defaultStore: Partial<IStore> = {
247254
isEnabled: true,
255+
noFunctional: false,
256+
noTargeting: false,
248257
sessionAttributes: {},
249258
localSessionAttributes: {},
250259
currentSessionMPIDs: [],
@@ -588,6 +597,16 @@ export default function Store(
588597
}
589598
};
590599

600+
this.getNoFunctional = (): boolean => this.noFunctional;
601+
this.setNoFunctional = (noFunctional: boolean): void => {
602+
this.noFunctional = noFunctional;
603+
};
604+
605+
this.getNoTargeting = (): boolean => this.noTargeting;
606+
this.setNoTargeting = (noTargeting: boolean): void => {
607+
this.noTargeting = noTargeting;
608+
};
609+
591610
this.getDeviceId = () => this.deviceId;
592611
this.setDeviceId = (deviceId: string) => {
593612
this.deviceId = deviceId;
@@ -720,6 +739,15 @@ export default function Store(
720739
this.storageName = createMainStorageName(workspaceToken);
721740
this.prodStorageName = createProductStorageName(workspaceToken);
722741

742+
// Extract privacy flags directly from config into Store
743+
if (config.hasOwnProperty('noFunctional')) {
744+
this.setNoFunctional(config.noFunctional);
745+
}
746+
747+
if (config.hasOwnProperty('noTargeting')) {
748+
this.setNoTargeting(config.noTargeting);
749+
}
750+
723751
this.SDKConfig.requiredWebviewBridgeName =
724752
requiredWebviewBridgeName || workspaceToken;
725753

test/jest/store.flags.spec.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import Store, { IStore } from '../../src/store';
2+
import { IMParticleWebSDKInstance } from '../../src/mp-instance';
3+
import { SDKInitConfig } from '../../src/sdkRuntimeModels';
4+
5+
describe('Store privacy flags', () => {
6+
let store: IStore & Record<string, any>;
7+
let mockMPInstance: IMParticleWebSDKInstance & Record<string, any>;
8+
9+
beforeEach(() => {
10+
mockMPInstance = {
11+
_Helpers: {
12+
createMainStorageName: () => 'mprtcl-v4',
13+
createProductStorageName: () => 'mprtcl-prodv4',
14+
Validators: { isFunction: () => true },
15+
extend: Object.assign,
16+
},
17+
_NativeSdkHelpers: {
18+
isWebviewEnabled: () => false,
19+
},
20+
_Persistence: {
21+
update: () => {},
22+
savePersistence: () => {},
23+
getPersistence: () => ({ gs: {} }),
24+
},
25+
Logger: {
26+
verbose: () => {},
27+
warning: () => {},
28+
error: () => {},
29+
},
30+
Identity: {
31+
getCurrentUser: () => ({ getMPID: () => 'mpid' }),
32+
},
33+
} as any;
34+
35+
store = {} as any;
36+
// Construct Store with our mock 'this'
37+
(Store as any).call(store, {} as SDKInitConfig, mockMPInstance, 'apikey');
38+
});
39+
40+
it('should default noFunctional and noTargeting to false when not provided', () => {
41+
const cfg: SDKInitConfig = { flags: {} } as any;
42+
store.processConfig(cfg);
43+
expect(store.getNoFunctional()).toBe(false);
44+
expect(store.getNoTargeting()).toBe(false);
45+
});
46+
47+
it('should set noFunctional as true and noTargeting as true from config', () => {
48+
const cfg: SDKInitConfig = {
49+
noFunctional: true,
50+
noTargeting: true,
51+
flags: {},
52+
} as any;
53+
54+
store.processConfig(cfg);
55+
56+
expect(store.getNoFunctional()).toBe(true);
57+
expect(store.getNoTargeting()).toBe(true);
58+
});
59+
60+
it('should set noFunctional as true and noTargeting as false from config', () => {
61+
const cfg: SDKInitConfig = {
62+
noFunctional: true,
63+
noTargeting: false,
64+
flags: {},
65+
} as any;
66+
67+
store.processConfig(cfg);
68+
69+
expect(store.getNoFunctional()).toBe(true);
70+
expect(store.getNoTargeting()).toBe(false);
71+
});
72+
73+
it('should set noFunctional as false and noTargeting as true from config', () => {
74+
const cfg: SDKInitConfig = {
75+
noFunctional: false,
76+
noTargeting: true,
77+
flags: {},
78+
} as any;
79+
80+
store.processConfig(cfg);
81+
82+
expect(store.getNoFunctional()).toBe(false);
83+
expect(store.getNoTargeting()).toBe(true);
84+
});
85+
});

test/src/tests-store.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,4 +1801,27 @@ describe('Store', () => {
18011801
});
18021802
});
18031803
});
1804+
1805+
describe('#privacy flags', () => {
1806+
it('should set noFunctional and noTargeting to false when not provided', () => {
1807+
const inst = window.mParticle.getInstance();
1808+
const store = (inst as any)._Store;
1809+
expect(store.getNoFunctional()).to.equal(false);
1810+
expect(store.getNoTargeting()).to.equal(false);
1811+
});
1812+
1813+
it('should set noFunctional and noTargeting from init config', () => {
1814+
window.mParticle._resetForTests(MPConfig);
1815+
window.mParticle.config = window.mParticle.config || {};
1816+
window.mParticle.config.noFunctional = true;
1817+
window.mParticle.config.noTargeting = true;
1818+
1819+
window.mParticle.init(apiKey, window.mParticle.config);
1820+
1821+
const inst = window.mParticle.getInstance();
1822+
const store = (inst as any)._Store;
1823+
expect(store.getNoFunctional()).to.equal(true);
1824+
expect(store.getNoTargeting()).to.equal(true);
1825+
});
1826+
});
18041827
});

0 commit comments

Comments
 (0)