@@ -20,6 +20,7 @@ import {
20
20
IPersistenceMinified ,
21
21
} from '../../src/persistence.interfaces' ;
22
22
import { ConsentState } from '@mparticle/web-sdk' ;
23
+ import { MParticleUser } from '../../src/sdkRuntimeModels' ;
23
24
24
25
const {
25
26
findCookie,
@@ -1483,6 +1484,72 @@ describe('persistence', () => {
1483
1484
done ( ) ;
1484
1485
} ) ;
1485
1486
1487
+ it ( 'get/set isLoggedIn for localStorage' , done => {
1488
+ mParticle . _resetForTests ( MPConfig ) ;
1489
+
1490
+ mockServer . respondWith ( urls . login , [
1491
+ 200 ,
1492
+ { } ,
1493
+ JSON . stringify ( { mpid : 'mpid1' , is_logged_in : true } ) ,
1494
+ ] ) ;
1495
+
1496
+
1497
+ mParticle . init ( apiKey , mParticle . config ) ;
1498
+ let user : MParticleUser = mParticle
1499
+ . getInstance ( )
1500
+ . Identity . getCurrentUser ( )
1501
+ expect ( user ) . to . be . ok ;
1502
+ expect ( user . isLoggedIn ( ) ) . to . be . false ;
1503
+
1504
+ let localStorageData = mParticle . getInstance ( ) . _Persistence . getPersistence ( ) ;
1505
+
1506
+ // The `l` property of Persistence is a boolean, but when saved
1507
+ // to local storage, Persistence encodes this as a 0 or 1.
1508
+ // It is then re-encoded as a boolean when retrieved from local storage.
1509
+ expect ( localStorageData . l ) . to . equal ( false ) ;
1510
+
1511
+ mParticle . Identity . login ( ) ;
1512
+
1513
+ localStorageData = mParticle . getInstance ( ) . _Persistence . getPersistence ( ) ;
1514
+ expect ( localStorageData . l ) . to . equal ( true ) ;
1515
+
1516
+ done ( ) ;
1517
+ } ) ;
1518
+
1519
+
1520
+ it ( 'get/set isLoggedIn for cookies' , done => {
1521
+ mParticle . _resetForTests ( MPConfig ) ;
1522
+ mParticle . config . useCookieStorage = true ;
1523
+
1524
+ mockServer . respondWith ( urls . login , [
1525
+ 200 ,
1526
+ { } ,
1527
+ JSON . stringify ( { mpid : 'mpid1' , is_logged_in : true } ) ,
1528
+ ] ) ;
1529
+
1530
+ mParticle . init ( apiKey , mParticle . config ) ;
1531
+
1532
+ let user : MParticleUser = mParticle
1533
+ . getInstance ( )
1534
+ . Identity . getCurrentUser ( )
1535
+ expect ( user ) . to . be . ok ;
1536
+ expect ( user . isLoggedIn ( ) ) . to . be . false ;
1537
+
1538
+ let cookieData = findCookie ( ) ;
1539
+
1540
+ // The `l` property of Persistence is a boolean, but when saved
1541
+ // to cookie storage, Persistence encodes this as a 0 or 1.
1542
+ // It is then re-encoded as a boolean when retrieved from cookies storage
1543
+ cookieData . l . should . equal ( false ) ;
1544
+
1545
+ mParticle . Identity . login ( ) ;
1546
+
1547
+ cookieData = findCookie ( ) ;
1548
+ cookieData . l . should . equal ( true ) ;
1549
+
1550
+ done ( ) ;
1551
+ } ) ;
1552
+
1486
1553
it ( 'get/set consent state for single user' , done => {
1487
1554
mParticle . _resetForTests ( MPConfig ) ;
1488
1555
0 commit comments