1+ import {
2+ mParticle ,
3+ MPConfig ,
4+ testMPID ,
5+ } from '../src/config/constants' ;
6+ import { Product } from '@mparticle/web-sdk' ;
7+
8+ describe ( 'Products Persistence' , ( ) => {
9+ let mpInstance = mParticle . getInstance ( ) ;
10+ beforeEach ( ( ) => {
11+ mParticle . _resetForTests ( MPConfig ) ;
12+ mpInstance . _Persistence . resetPersistence ( ) ;
13+ } ) ;
14+
15+ it ( 'should save products to localStorage when noTargeting is false by default' , ( ) => {
16+ const product = { Name : 'iphone' , Sku : 'iphonesku' , Price : 599 , Quantity : 1 } ;
17+ mpInstance . _Persistence . setCartProducts ( { [ testMPID ] : { cp : [ product ] } } as unknown as Product [ ] ) ;
18+ expect ( mpInstance . _Persistence . getCartProducts ( testMPID ) . length ) . toBe ( 1 ) ;
19+ } ) ;
20+
21+ it ( 'should NOT save products to localStorage when noTargeting is true' , ( ) => {
22+ mpInstance . _Store . setNoTargeting ( true ) ;
23+ const product = { Name : 'iphone' , Sku : 'iphonesku' , Price : 599 , Quantity : 1 } ;
24+ mpInstance . _Persistence . setCartProducts ( { [ testMPID ] : { cp : [ product ] } } as unknown as Product [ ] ) ;
25+ expect ( mpInstance . _Persistence . getCartProducts ( testMPID ) . length ) . toBe ( 0 ) ;
26+ } ) ;
27+
28+ it ( 'should save products to localStorage when noTargeting is false' , ( ) => {
29+ mpInstance . _Store . setNoTargeting ( false ) ;
30+ const product = { Name : 'iphone' , Sku : 'iphonesku' , Price : 599 , Quantity : 1 } ;
31+ mpInstance . _Persistence . setCartProducts ( { [ testMPID ] : { cp : [ product ] } } as unknown as Product [ ] ) ;
32+ expect ( mpInstance . _Persistence . getCartProducts ( testMPID ) . length ) . toBe ( 1 ) ;
33+ } ) ;
34+ } ) ;
0 commit comments