Skip to content
Draft
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
6 changes: 6 additions & 0 deletions src/Rokt-Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var constructor = function () {
self.placementEventMappingLookup = {};
self.placementEventAttributeMappingLookup = {};
self.eventQueue = [];
self.eventStreamQueue = [];
self.integrationName = null;

function getEventAttributeValue(event, eventAttributeKey) {
Expand Down Expand Up @@ -521,7 +522,12 @@ var constructor = function () {

function _sendEventStream(event) {
if (window.Rokt && typeof window.Rokt.__event_stream__ === 'function') {
while (self.eventStreamQueue.length) {
window.Rokt.__event_stream__(self.eventStreamQueue.shift());
}
window.Rokt.__event_stream__(event);
} else {
self.eventStreamQueue.push(event);
}
}

Expand Down
79 changes: 67 additions & 12 deletions test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4317,6 +4317,7 @@

describe('#_sendEventStream', () => {
beforeEach(() => {
window.mParticle.forwarder.eventStreamQueue = [];
window.Rokt = new MockRoktForwarder();
window.Rokt.createLauncher = async function () {
return Promise.resolve({
Expand Down Expand Up @@ -4364,6 +4365,7 @@
afterEach(() => {
delete window.Rokt.__event_stream__;
window.mParticle.forwarder.eventQueue = [];
window.mParticle.forwarder.eventStreamQueue = [];
window.mParticle.forwarder.isInitialized = false;
window.mParticle.Rokt.attachKitCalled = false;
});
Expand Down Expand Up @@ -4396,7 +4398,7 @@
receivedEvents[0].should.deepEqual(testEvent);
});

it('should not throw when window.Rokt.__event_stream__ is not defined', async () => {
it('should queue event when window.Rokt.__event_stream__ is not defined', async () => {
await window.mParticle.forwarder.init(
{ accountId: '123456' },
reportService.cb,
Expand All @@ -4407,16 +4409,21 @@

await waitForCondition(() => window.mParticle.Rokt.attachKitCalled);

var testEvent = {
EventName: 'Test Event',
EventCategory: EventType.Other,
EventDataType: MessageType.PageEvent,
};

(function () {
window.mParticle.forwarder.process({
EventName: 'Test Event',
EventCategory: EventType.Other,
EventDataType: MessageType.PageEvent,
});
window.mParticle.forwarder.process(testEvent);
}).should.not.throw();

window.mParticle.forwarder.eventStreamQueue.length.should.equal(1);
window.mParticle.forwarder.eventStreamQueue[0].should.deepEqual(testEvent);

Check failure on line 4423 in test/src/tests.js

View workflow job for this annotation

GitHub Actions / Run Web Kit PR Workflow / Build and Test

Replace `testEvent` with `⏎················testEvent⏎············`
});

it('should not throw when window.Rokt is undefined', async () => {
it('should queue event when window.Rokt is undefined', async () => {
await window.mParticle.forwarder.init(
{ accountId: '123456' },
reportService.cb,
Expand All @@ -4430,14 +4437,19 @@
var savedRokt = window.Rokt;
window.Rokt = undefined;

var testEvent = {
EventName: 'Test Event',
EventCategory: EventType.Other,
EventDataType: MessageType.PageEvent,
};

(function () {
window.mParticle.forwarder.process({
EventName: 'Test Event',
EventCategory: EventType.Other,
EventDataType: MessageType.PageEvent,
});
window.mParticle.forwarder.process(testEvent);
}).should.not.throw();

window.mParticle.forwarder.eventStreamQueue.length.should.equal(1);
window.mParticle.forwarder.eventStreamQueue[0].should.deepEqual(testEvent);

Check failure on line 4451 in test/src/tests.js

View workflow job for this annotation

GitHub Actions / Run Web Kit PR Workflow / Build and Test

Replace `testEvent` with `⏎················testEvent⏎············`

window.Rokt = savedRokt;
});

Expand Down Expand Up @@ -4579,6 +4591,49 @@
'foo-mapped-flag': true,
});
});

it('should flush queued events in FIFO order when __event_stream__ becomes available', async () => {
await window.mParticle.forwarder.init(
{ accountId: '123456' },
reportService.cb,
true,
null,
{}
);

await waitForCondition(() => window.mParticle.Rokt.attachKitCalled);

window.mParticle.forwarder.process({
EventName: 'Event A',
EventCategory: EventType.Other,
EventDataType: MessageType.PageEvent,
});
window.mParticle.forwarder.process({
EventName: 'Event B',
EventCategory: EventType.Other,
EventDataType: MessageType.PageEvent,
});

window.mParticle.forwarder.eventStreamQueue.length.should.equal(2);

var receivedEvents = [];
window.Rokt.__event_stream__ = function (event) {
receivedEvents.push(event);
};

window.mParticle.forwarder.process({
EventName: 'Event C',
EventCategory: EventType.Other,
EventDataType: MessageType.PageEvent,
});

receivedEvents.length.should.equal(3);
receivedEvents[0].EventName.should.equal('Event A');
receivedEvents[1].EventName.should.equal('Event B');
receivedEvents[2].EventName.should.equal('Event C');
window.mParticle.forwarder.eventStreamQueue.length.should.equal(0);
});

Check failure on line 4635 in test/src/tests.js

View workflow job for this annotation

GitHub Actions / Run Web Kit PR Workflow / Build and Test

Delete `⏎`

});

describe('#parseSettingsString', () => {
Expand Down
Loading