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
18 changes: 16 additions & 2 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var moduleId = 181;

var constructor = function () {
var self = this;
var EMAIL_SHA256_IDENTITY = 'emailsha256';
var OTHER_IDENTITY = 'other';

self.name = name;
self.moduleId = moduleId;
Expand Down Expand Up @@ -136,7 +138,19 @@ var constructor = function () {
return {};
}

return filteredUser.getUserIdentities().userIdentities;
var userIdentities = filteredUser.getUserIdentities().userIdentities;

return replaceOtherWithEmailsha256(userIdentities);
}

function replaceOtherWithEmailsha256(_data) {
var data = mergeObjects({}, _data || {});
if (_data.hasOwnProperty(OTHER_IDENTITY)) {
data[EMAIL_SHA256_IDENTITY] = _data[OTHER_IDENTITY];
delete data[OTHER_IDENTITY];
}

return data;
}

/**
Expand Down Expand Up @@ -186,8 +200,8 @@ var constructor = function () {
var filteredUserIdentities = returnUserIdentities(filteredUser);

var selectPlacementsAttributes = mergeObjects(
filteredAttributes,
filteredUserIdentities,
replaceOtherWithEmailsha256(filteredAttributes),
optimizelyAttributes,
{
mpid: mpid,
Expand Down
191 changes: 191 additions & 0 deletions test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,197 @@ describe('Rokt Forwarder', () => {
}
);
});

it('should map other userIdentities to emailsha256', async () => {
window.mParticle.Rokt.filters = {
userAttributeFilters: [],
filterUserAttributes: function () {
return {};
},
filteredUser: {
getMPID: function () {
return '234';
},
getUserIdentities: function () {
return {
userIdentities: {
customerid: 'customer123',
other: 'sha256-test@gmail.com',
},
};
},
},
};

// Set up the createLauncher to properly resolve asynchronously
window.Rokt.createLauncher = async function () {
return Promise.resolve({
selectPlacements: function (options) {
window.mParticle.Rokt.selectPlacementsOptions =
options;
window.mParticle.Rokt.selectPlacementsCalled = true;
},
});
};
await window.mParticle.forwarder.init(
{
accountId: '123456',
},
reportService.cb,
true,
null,
{}
);
// Wait for initialization to complete (after launcher is created)
await waitForCondition(() => {
return window.mParticle.forwarder.isInitialized;
});

await window.mParticle.forwarder.selectPlacements({
identifier: 'test-placement',
attributes: {},
});

window.Rokt.selectPlacementsOptions.attributes.should.deepEqual(
{
customerid: 'customer123',
emailsha256: 'sha256-test@gmail.com',
mpid: '234',
}
);
});

it('should map other to emailsha256 when other is passed through selectPlacements', async () => {
window.mParticle.Rokt.filters = {
userAttributeFilters: [],
filterUserAttributes: function (attributes) {
return attributes;
},
filteredUser: {
getMPID: function () {
return '123';
},
getUserIdentities: function () {
return {
userIdentities: {
customerid: 'customer123',
},
};
},
},
};

// Set up the createLauncher to properly resolve asynchronously
window.Rokt.createLauncher = async function () {
return Promise.resolve({
selectPlacements: function (options) {
window.mParticle.Rokt.selectPlacementsOptions =
options;
window.mParticle.Rokt.selectPlacementsCalled = true;
},
});
};

await window.mParticle.forwarder.init(
{
accountId: '123456',
},
reportService.cb,
true,
null,
{
'test-attribute': 'test-value',
}
);

// Wait for initialization to complete (after launcher is created)
await waitForCondition(() => {
return window.mParticle.forwarder.isInitialized;
});

await window.mParticle.forwarder.selectPlacements({
identifier: 'test-placement',
attributes: {
other: 'sha256-test@gmail.com',
},
});

window.Rokt.selectPlacementsOptions.attributes.should.deepEqual(
{
'test-attribute': 'test-value',
customerid: 'customer123',
emailsha256: 'sha256-test@gmail.com',
mpid: '123',
}
);
});

it('should prioritize other passed to selectPlacements over other in userIdentities', async () => {
window.mParticle.Rokt.filters = {
userAttributeFilters: [],
filterUserAttributes: function (attributes) {
return attributes;
},
filteredUser: {
getMPID: function () {
return '123';
},
getUserIdentities: function () {
return {
userIdentities: {
customerid: 'customer123',
other: 'not-prioritized-from-userIdentities@gmail.com',
},
};
},
},
};

// Set up the createLauncher to properly resolve asynchronously
window.Rokt.createLauncher = async function () {
return Promise.resolve({
selectPlacements: function (options) {
window.mParticle.Rokt.selectPlacementsOptions =
options;
window.mParticle.Rokt.selectPlacementsCalled = true;
},
});
};

await window.mParticle.forwarder.init(
{
accountId: '123456',
},
reportService.cb,
true,
null,
{
'test-attribute': 'test-value',
}
);

// Wait for initialization to complete (after launcher is created)
await waitForCondition(() => {
return window.mParticle.forwarder.isInitialized;
});

await window.mParticle.forwarder.selectPlacements({
identifier: 'test-placement',
attributes: {
other: 'prioritized-from-selectPlacements@gmail.com',
},
});

window.Rokt.selectPlacementsOptions.attributes.should.deepEqual(
{
'test-attribute': 'test-value',
customerid: 'customer123',
emailsha256:
'prioritized-from-selectPlacements@gmail.com',
mpid: '123',
}
);
});
});
});

Expand Down
Loading