@@ -1202,6 +1202,7 @@ describe('batch uploader', () => {
12021202 } ) ;
12031203
12041204 window . sessionStorage . clear ( ) ;
1205+ window . localStorage . clear ( ) ;
12051206 } ) ;
12061207
12071208 afterEach ( ( ) => {
@@ -1715,5 +1716,99 @@ describe('batch uploader', () => {
17151716 . catch ( ( e ) => {
17161717 } )
17171718 } ) ;
1719+
1720+ describe ( 'noFunctional' , ( ) => {
1721+ const eventStorageKey = 'mprtcl-v4_abcdef-events' ;
1722+ const batchStorageKey = 'mprtcl-v4_abcdef-batches' ;
1723+ beforeEach ( ( ) => {
1724+ window . mParticle . _resetForTests ( MPConfig ) ;
1725+ window . localStorage . clear ( ) ;
1726+ window . sessionStorage . clear ( ) ;
1727+ } ) ;
1728+
1729+ it ( 'should store batches in session storage when noFunctional is false by default' , async ( ) => {
1730+ window . mParticle . config . flags = {
1731+ offlineStorage : '100' ,
1732+ ...enableBatchingConfigFlags ,
1733+ } ;
1734+ window . mParticle . init ( apiKey , window . mParticle . config ) ;
1735+ await waitForCondition ( hasIdentifyReturned ) ;
1736+ const mpInstance = window . mParticle . getInstance ( ) ;
1737+ const uploader = mpInstance . _APIClient . uploader ;
1738+ uploader . queueEvent ( event0 ) ;
1739+ expect ( window . sessionStorage . getItem ( eventStorageKey ) ) . to . not . equal ( null ) ;
1740+ } ) ;
1741+
1742+ it ( 'should NOT store events in session storage when noFunctional is true' , async ( ) => {
1743+ window . mParticle . config . flags = {
1744+ offlineStorage : '100' ,
1745+ ...enableBatchingConfigFlags ,
1746+ } ;
1747+ window . mParticle . config . noFunctional = true ;
1748+ window . mParticle . init ( apiKey , window . mParticle . config ) ;
1749+ await waitForCondition ( hasIdentifyReturned ) ;
1750+ const mpInstance = window . mParticle . getInstance ( ) ;
1751+ const uploader = mpInstance . _APIClient . uploader ;
1752+ uploader . queueEvent ( event0 ) ;
1753+ expect ( window . sessionStorage . getItem ( eventStorageKey ) ) . to . equal ( null ) ;
1754+ } ) ;
1755+
1756+ it ( 'should store events in session storage when noFunctional is false' , async ( ) => {
1757+ window . mParticle . config . flags = {
1758+ offlineStorage : '100' ,
1759+ ...enableBatchingConfigFlags ,
1760+ } ;
1761+ window . mParticle . config . noFunctional = false ;
1762+ window . mParticle . init ( apiKey , window . mParticle . config ) ;
1763+ await waitForCondition ( hasIdentifyReturned ) ;
1764+ const mpInstance = window . mParticle . getInstance ( ) ;
1765+ const uploader = mpInstance . _APIClient . uploader ;
1766+ uploader . queueEvent ( event0 ) ;
1767+ expect ( window . sessionStorage . getItem ( eventStorageKey ) ) . to . not . equal ( null ) ;
1768+ } ) ;
1769+
1770+ it ( 'should store batches in local storage when noFunctional is false by default' , async ( ) => {
1771+ window . mParticle . init ( apiKey , window . mParticle . config ) ;
1772+ await waitForCondition ( hasIdentifyReturned ) ;
1773+ const mpInstance = window . mParticle . getInstance ( ) ;
1774+ const uploader = mpInstance . _APIClient . uploader ;
1775+ fetchMock . post ( urls . events , 500 , { overwriteRoutes : true } ) ;
1776+ uploader . queueEvent ( event0 ) ;
1777+ await window . mParticle . getInstance ( ) . _APIClient . uploader . prepareAndUpload ( ) ;
1778+ expect ( window . localStorage . getItem ( batchStorageKey ) ) . to . not . equal ( null ) ;
1779+ } ) ;
1780+
1781+ it ( 'should NOT store batches in local storage when noFunctional is true' , async ( ) => {
1782+ window . mParticle . config . flags = {
1783+ offlineStorage : '100' ,
1784+ ...enableBatchingConfigFlags ,
1785+ } ;
1786+ window . mParticle . config . noFunctional = true ;
1787+ window . mParticle . init ( apiKey , window . mParticle . config ) ;
1788+ await waitForCondition ( hasIdentifyReturned ) ;
1789+ const mpInstance = window . mParticle . getInstance ( ) ;
1790+ const uploader = mpInstance . _APIClient . uploader ;
1791+ uploader . queueEvent ( event0 ) ;
1792+ await window . mParticle . getInstance ( ) . _APIClient . uploader . prepareAndUpload ( ) ;
1793+ expect ( window . localStorage . getItem ( batchStorageKey ) ) . to . equal ( null ) ;
1794+ } ) ;
1795+
1796+ it ( 'should store batches in local storage when noFunctional is false' , async ( ) => {
1797+ window . mParticle . config . flags = {
1798+ offlineStorage : '100' ,
1799+ ...enableBatchingConfigFlags ,
1800+ } ;
1801+ window . mParticle . config . noFunctional = false ;
1802+ window . mParticle . init ( apiKey , window . mParticle . config ) ;
1803+ await waitForCondition ( hasIdentifyReturned ) ;
1804+ const mpInstance = window . mParticle . getInstance ( ) ;
1805+ const uploader = mpInstance . _APIClient . uploader ;
1806+ fetchMock . post ( urls . events , 500 , { overwriteRoutes : true } ) ;
1807+ uploader . queueEvent ( event0 ) ;
1808+ await window . mParticle . getInstance ( ) . _APIClient . uploader . prepareAndUpload ( ) ;
1809+ expect ( window . localStorage . getItem ( batchStorageKey ) ) . to . not . equal ( null ) ;
1810+ } ) ;
1811+
1812+ } ) ;
17181813 } ) ;
17191814} ) ;
0 commit comments