Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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.'
Expand Down Expand Up @@ -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 || {}
);

Expand Down
74 changes: 46 additions & 28 deletions test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -98,6 +99,8 @@ describe('Rokt Forwarder', () => {

afterEach(() => {
window.mParticle.forwarder.userAttributes = {};
delete window.mParticle.forwarder.launcherOptions;
Comment thread
alexs-mparticle marked this conversation as resolved.
delete window.mParticle.Rokt.launcherOptions;
});

describe('#initForwarder', () => {
Expand Down Expand Up @@ -138,57 +141,70 @@ 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',
},
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 () => {
Expand Down Expand Up @@ -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';

Expand All @@ -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 =
Expand All @@ -273,8 +292,7 @@ describe('Rokt Forwarder', () => {
{},
null,
null,
null,
{ 'Rokt.integrationName': customIntegrationName }
null
);

window.Rokt.integrationName.should.equal(
Expand Down