diff --git a/src/Rokt-Kit.js b/src/Rokt-Kit.js index ed237c1..9eb7876 100644 --- a/src/Rokt-Kit.js +++ b/src/Rokt-Kit.js @@ -50,29 +50,22 @@ var constructor = function () { _service, testMode, _trackerId, - filteredUserAttributes, - filteredUserIdentities, - appVersion, - appName, - customFlags + filteredUserAttributes ) { var accountId = settings.accountId; self.userAttributes = filteredUserAttributes; self.onboardingExpProvider = settings.onboardingExpProvider; - var integrationName = - customFlags && customFlags['Rokt.integrationName']; - var noFunctional = customFlags && customFlags['Rokt.noFunctional']; - var noTargeting = customFlags && customFlags['Rokt.noTargeting']; + var managerOptions = window.mParticle.Rokt.managerOptions || {}; + var sandbox = managerOptions.sandbox || false; - var launcherOptions = { - integrationName: generateIntegrationName(integrationName), - noFunctional: noFunctional, - noTargeting: noTargeting, - }; + var launcherOptions = window.mParticle.Rokt.launcherOptions || {}; + launcherOptions.integrationName = generateIntegrationName( + launcherOptions.integrationName + ); if (testMode) { - attachLauncher(accountId, launcherOptions); + attachLauncher(accountId, sandbox, launcherOptions); return; } @@ -93,7 +86,7 @@ var constructor = function () { typeof window.Rokt.createLauncher === 'function' && window.Rokt.currentLauncher === undefined ) { - attachLauncher(accountId, launcherOptions); + attachLauncher(accountId, sandbox, launcherOptions); } else { console.error( 'Rokt object is not available after script load.' @@ -183,9 +176,12 @@ var constructor = function () { delete self.userAttributes[key]; } - function attachLauncher(accountId, launcherOptions) { + function attachLauncher(accountId, sandbox, launcherOptions) { var options = mergeObjects( - { accountId: accountId }, + { + accountId: accountId, + sandbox: sandbox, + }, launcherOptions || {} ); diff --git a/test/src/tests.js b/test/src/tests.js index c07b09a..733b240 100644 --- a/test/src/tests.js +++ b/test/src/tests.js @@ -78,6 +78,7 @@ describe('Rokt Forwarder', () => { self.noTargeting = options.noTargeting; self.createLauncherCalled = true; self.isInitialized = true; + self.sandbox = options.sandbox; return Promise.resolve({ then: function (callback) { @@ -98,6 +99,8 @@ describe('Rokt Forwarder', () => { afterEach(() => { window.mParticle.forwarder.userAttributes = {}; + delete window.mParticle.forwarder.launcherOptions; + delete window.mParticle.Rokt.launcherOptions; }); describe('#initForwarder', () => { @@ -138,38 +141,47 @@ describe('Rokt Forwarder', () => { window.Rokt.createLauncherCalled.should.equal(true); }); - it('should set optional settings from customFlags', async () => { + it('should set sandbox to true if sandbox is true in managerOptions', async () => { + window.mParticle.Rokt.managerOptions = { + sandbox: true, + }; + await mParticle.forwarder.init( { accountId: '123456', }, reportService.cb, - true, - null, - {}, - null, - null, - null, - { - 'Rokt.integrationName': 'customName', - 'Rokt.noFunctional': true, - 'Rokt.noTargeting': true, - } + true ); - var expectedIntegrationName = - 'mParticle_wsdkv_1.2.3_kitv_' + - require('../../package.json').version + - '_customName'; + window.Rokt.createLauncherCalled.should.equal(true); + window.Rokt.sandbox.should.equal(true); + }); + + it('should set sandbox to false if sandbox is false in managerOptions', async () => { + window.mParticle.Rokt.managerOptions = { + sandbox: false, + }; + + await mParticle.forwarder.init( + { + accountId: '123456', + }, + reportService.cb, + true + ); window.Rokt.createLauncherCalled.should.equal(true); - window.Rokt.accountId.should.equal('123456'); - window.Rokt.integrationName.should.equal(expectedIntegrationName); - window.Rokt.noFunctional.should.equal(true); - window.Rokt.noTargeting.should.equal(true); + window.Rokt.sandbox.should.equal(false); }); - it('should not set optional settings when not in customFlags', async () => { + it('should set optional settings from launcherOptions', async () => { + window.mParticle.Rokt.launcherOptions = { + integrationName: 'customName', + noFunctional: true, + noTargeting: true, + }; + await mParticle.forwarder.init( { accountId: '123456', @@ -177,18 +189,22 @@ describe('Rokt Forwarder', () => { reportService.cb, true, null, - {} + {}, + null, + null, + null ); var expectedIntegrationName = 'mParticle_wsdkv_1.2.3_kitv_' + - require('../../package.json').version; + require('../../package.json').version + + '_customName'; window.Rokt.createLauncherCalled.should.equal(true); window.Rokt.accountId.should.equal('123456'); window.Rokt.integrationName.should.equal(expectedIntegrationName); - (window.Rokt.noFunctional === undefined).should.equal(true); - (window.Rokt.noTargeting === undefined).should.equal(true); + window.Rokt.noFunctional.should.equal(true); + window.Rokt.noTargeting.should.equal(true); }); it('should set the filters on the forwarder', async () => { @@ -244,7 +260,7 @@ describe('Rokt Forwarder', () => { ); }); - it('should append custom integration name to integrationName if customFlags is passed', async () => { + it('should append custom integration name to integrationName if passed in launcherOptions', async () => { const packageVersion = require('../../package.json').version; const customIntegrationName = 'myCustomIntegration'; @@ -255,6 +271,9 @@ describe('Rokt Forwarder', () => { window.mParticle.Rokt.attachKitCalled = true; return Promise.resolve(); }; + window.mParticle.Rokt.launcherOptions = { + integrationName: customIntegrationName, + }; // Simulate the forwarder appending the custom integration name window.Rokt.integrationName = @@ -273,8 +292,7 @@ describe('Rokt Forwarder', () => { {}, null, null, - null, - { 'Rokt.integrationName': customIntegrationName } + null ); window.Rokt.integrationName.should.equal(