Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,24 @@ var constructor = function () {
self.userAttributes = filteredUser.getAllUserAttributes();
}

function onLoginComplete(filteredUser) {
self.userAttributes = filteredUser.getAllUserAttributes();
_sendEventStream({
EventName: 'User Login',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to confirm these match what's expected

EventDataType: 10, // MessageType.Profile
Timestamp: Date.now(),
Comment thread
alexs-mparticle marked this conversation as resolved.
});
}

function onLogoutComplete(filteredUser) {
self.userAttributes = filteredUser.getAllUserAttributes();
_sendEventStream({
EventName: 'User Logout',
EventDataType: 10, // MessageType.Profile
Timestamp: Date.now(),
});
}

function setUserAttribute(key, value) {
self.userAttributes[key] = value;
}
Expand Down Expand Up @@ -713,6 +731,8 @@ var constructor = function () {
this.setExtensionData = setExtensionData;
this.setUserAttribute = setUserAttribute;
this.onUserIdentified = onUserIdentified;
this.onLoginComplete = onLoginComplete;
this.onLogoutComplete = onLogoutComplete;
this.removeUserAttribute = removeUserAttribute;

/**
Expand Down
148 changes: 148 additions & 0 deletions test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3149,6 +3149,154 @@ describe('Rokt Forwarder', () => {
});
});

describe('#onLoginComplete', () => {
afterEach(() => {
delete window.Rokt.__event_stream__;
window.mParticle.forwarder.eventStreamQueue = [];
});

it('should update userAttributes from the filtered user', () => {
window.mParticle.forwarder.onLoginComplete({
getAllUserAttributes: function () {
return { 'user-attr': 'user-value' };
},
});

window.mParticle.forwarder.userAttributes.should.deepEqual({
'user-attr': 'user-value',
});
});

it('should send a User Login event to window.Rokt.__event_stream__', () => {
var receivedEvents = [];
window.Rokt.__event_stream__ = function (event) {
receivedEvents.push(event);
};

window.mParticle.forwarder.onLoginComplete({
getAllUserAttributes: function () {
return { 'user-attr': 'user-value' };
},
});

receivedEvents.length.should.equal(1);
receivedEvents[0].EventName.should.equal('User Login');
receivedEvents[0].EventDataType.should.equal(10);
receivedEvents[0].UserAttributes.should.deepEqual({
'user-attr': 'user-value',
});
});

it('should queue event when window.Rokt.__event_stream__ is not available', () => {
window.mParticle.forwarder.onLoginComplete({
getAllUserAttributes: function () {
return {};
},
});

window.mParticle.forwarder.eventStreamQueue.length.should.equal(1);
window.mParticle.forwarder.eventStreamQueue[0].EventName.should.equal(
'User Login'
);
window.mParticle.forwarder.eventStreamQueue[0].EventDataType.should.equal(
10
);
});

it('should queue event when window.Rokt is undefined', () => {
var savedRokt = window.Rokt;
window.Rokt = undefined;

(function () {
window.mParticle.forwarder.onLoginComplete({
getAllUserAttributes: function () {
return {};
},
});
}).should.not.throw();

window.mParticle.forwarder.eventStreamQueue.length.should.equal(1);
window.mParticle.forwarder.eventStreamQueue[0].EventName.should.equal(
'User Login'
);

window.Rokt = savedRokt;
});
});

describe('#onLogoutComplete', () => {
afterEach(() => {
delete window.Rokt.__event_stream__;
window.mParticle.forwarder.eventStreamQueue = [];
});

it('should update userAttributes from the filtered user', () => {
window.mParticle.forwarder.onLogoutComplete({
getAllUserAttributes: function () {
return { 'remaining-attr': 'some-value' };
},
});

window.mParticle.forwarder.userAttributes.should.deepEqual({
'remaining-attr': 'some-value',
});
});

it('should send a User Logout event to window.Rokt.__event_stream__', () => {
var receivedEvents = [];
window.Rokt.__event_stream__ = function (event) {
receivedEvents.push(event);
};

window.mParticle.forwarder.onLogoutComplete({
getAllUserAttributes: function () {
return {};
},
});

receivedEvents.length.should.equal(1);
receivedEvents[0].EventName.should.equal('User Logout');
receivedEvents[0].EventDataType.should.equal(10);
receivedEvents[0].UserAttributes.should.deepEqual({});
});

it('should queue event when window.Rokt.__event_stream__ is not available', () => {
window.mParticle.forwarder.onLogoutComplete({
getAllUserAttributes: function () {
return {};
},
});

window.mParticle.forwarder.eventStreamQueue.length.should.equal(1);
window.mParticle.forwarder.eventStreamQueue[0].EventName.should.equal(
'User Logout'
);
window.mParticle.forwarder.eventStreamQueue[0].EventDataType.should.equal(
10
);
});

it('should queue event when window.Rokt is undefined', () => {
var savedRokt = window.Rokt;
window.Rokt = undefined;

(function () {
window.mParticle.forwarder.onLogoutComplete({
getAllUserAttributes: function () {
return {};
},
});
}).should.not.throw();

window.mParticle.forwarder.eventStreamQueue.length.should.equal(1);
window.mParticle.forwarder.eventStreamQueue[0].EventName.should.equal(
'User Logout'
);

window.Rokt = savedRokt;
});
});

describe('#fetchOptimizely', () => {
// Helper functions for setting up Optimizely mocks
function setupValidOptimizelyMock(experiments) {
Expand Down
Loading