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+ } ) ;
0 commit comments