11import { Batch } from '@mparticle/event-models' ;
22import { expect } from 'chai' ;
33import { Dictionary } from '../../src/utils' ;
4- import { SessionStorageVault , LocalStorageVault } from '../../src/vault' ;
4+ import { SessionStorageVault , LocalStorageVault , DisabledVault } from '../../src/vault' ;
55
66const testObject : Dictionary < Dictionary < string > > = {
77 foo : { foo : 'bar' , buzz : 'bazz' } ,
@@ -419,4 +419,76 @@ describe('Vault', () => {
419419 ) ;
420420 } ) ;
421421 } ) ;
422+
423+ describe ( 'DisabledVault' , ( ) => {
424+ afterEach ( ( ) => {
425+ window . localStorage . clear ( ) ;
426+ } ) ;
427+
428+ describe ( '#store' , ( ) => {
429+ it ( 'should NOT write to localStorage' , ( ) => {
430+ const storageKey = 'test-disabled-store-empty' ;
431+ const vault = new DisabledVault < string > ( storageKey ) ;
432+
433+ vault . store ( 'testString' ) ;
434+
435+ expect ( vault . contents ) . to . equal ( null ) ;
436+ expect ( window . localStorage . getItem ( storageKey ) ) . to . equal ( null ) ;
437+ } ) ;
438+
439+ it ( 'should NOT overwrite existing localStorage value and keep contents null' , ( ) => {
440+ const storageKey = 'test-disabled-store-existing' ;
441+ window . localStorage . setItem ( storageKey , 'existingItem' ) ;
442+
443+ const vault = new DisabledVault < string > ( storageKey ) ;
444+
445+ vault . store ( 'newValue' ) ;
446+
447+ expect ( vault . contents ) . to . equal ( null ) ;
448+ expect ( window . localStorage . getItem ( storageKey ) ) . to . equal ( 'existingItem' ) ;
449+ } ) ;
450+ } ) ;
451+
452+ describe ( '#retrieve' , ( ) => {
453+ it ( 'should return null when nothing is stored' , ( ) => {
454+ const storageKey = 'test-disabled-retrieve-empty' ;
455+ const vault = new DisabledVault < string > ( storageKey ) ;
456+ const retrievedItem = vault . retrieve ( ) ;
457+ expect ( retrievedItem ) . to . equal ( null ) ;
458+ } ) ;
459+
460+ it ( 'should return null even if localStorage has a value' , ( ) => {
461+ const storageKey = 'test-disabled-retrieve-existing' ;
462+ window . localStorage . setItem ( storageKey , 'existingItem' ) ;
463+
464+ const vault = new DisabledVault < string > ( storageKey ) ;
465+ const retrievedItem = vault . retrieve ( ) ;
466+ expect ( retrievedItem ) . to . equal ( null ) ;
467+ expect ( window . localStorage . getItem ( storageKey ) ) . to . equal ( 'existingItem' ) ;
468+ } ) ;
469+ } ) ;
470+
471+ describe ( '#purge' , ( ) => {
472+ it ( 'should keep contents null when purging' , ( ) => {
473+ const storageKey = 'test-disabled-purge-existing' ;
474+ window . localStorage . setItem ( storageKey , 'existing' ) ;
475+
476+ const vault = new DisabledVault < string > ( storageKey ) ;
477+
478+ vault . purge ( ) ;
479+
480+ expect ( vault . contents ) . to . equal ( null ) ;
481+ expect ( window . localStorage . getItem ( storageKey ) ) . to . equal ( null ) ;
482+ } ) ;
483+
484+ it ( 'should keep contents null when purging an empty key' , ( ) => {
485+ const storageKey = 'test-disabled-purge-empty' ;
486+ const vault = new DisabledVault < string > ( storageKey ) ;
487+
488+ vault . purge ( ) ;
489+ expect ( vault . contents ) . to . equal ( null ) ;
490+ expect ( window . localStorage . getItem ( storageKey ) ) . to . equal ( null ) ;
491+ } ) ;
492+ } ) ;
493+ } ) ;
422494} ) ;
0 commit comments