Skip to content

Commit 06e3f40

Browse files
guillermotGuillermo Tamanaha
authored andcommitted
feat: Enhance local launcher logic with user threshold check (#49)
* feat: Enhance local launcher logic with user threshold check * Rename function --------- Co-authored-by: Guillermo Tamanaha <v-gtamanaha@mparticle.com>
1 parent 49cd24e commit 06e3f40

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/Rokt-Kit.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,15 @@ var constructor = function () {
435435
function isPartnerInLocalLauncherTestGroup() {
436436
return (
437437
window.mParticle.config &&
438-
window.mParticle.config.isLocalLauncherEnabled
438+
window.mParticle.config.isLocalLauncherEnabled &&
439+
_isAssignedToSampleGroup()
439440
);
440441
}
442+
443+
function _isAssignedToSampleGroup() {
444+
var LOCAL_LAUNCHER_TEST_GROUP_THRESHOLD = 0.5;
445+
return Math.random() > LOCAL_LAUNCHER_TEST_GROUP_THRESHOLD;
446+
}
441447
};
442448

443449
function generateIntegrationName(customIntegrationName) {

test/src/tests.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ describe('Rokt Forwarder', () => {
566566
},
567567
};
568568
window.mParticle.config = undefined;
569+
Math.random = () => 1;
569570
});
570571

571572
it('should create a remote launcher if the partner is not in the local launcher test group', async () => {
@@ -598,6 +599,44 @@ describe('Rokt Forwarder', () => {
598599
window.mParticle.Rokt.createLocalLauncherCalled.should.equal(true);
599600
});
600601

602+
it('should create a remote launcher if the partner is in the local launcher test group but the random number is below the thresholds', async () => {
603+
window.mParticle.config = {
604+
isLocalLauncherEnabled: true,
605+
};
606+
607+
Math.random = () => 0;
608+
609+
await window.mParticle.forwarder.init(
610+
{ accountId: '123456' },
611+
reportService.cb,
612+
true,
613+
null,
614+
{}
615+
);
616+
617+
window.mParticle.Rokt.createLauncherCalled.should.equal(true);
618+
window.mParticle.Rokt.createLocalLauncherCalled.should.equal(false);
619+
});
620+
621+
it('should create a local launcher if the partner is in the local launcher test group but the random number is above the thresholds', async () => {
622+
window.mParticle.config = {
623+
isLocalLauncherEnabled: true,
624+
};
625+
626+
Math.random = () => 1;
627+
628+
await window.mParticle.forwarder.init(
629+
{ accountId: '123456' },
630+
reportService.cb,
631+
true,
632+
null,
633+
{}
634+
);
635+
636+
window.mParticle.Rokt.createLauncherCalled.should.equal(false);
637+
window.mParticle.Rokt.createLocalLauncherCalled.should.equal(true);
638+
});
639+
601640
it('should call attachKit', async () => {
602641
await window.mParticle.forwarder.init(
603642
{ accountId: '123456' },

0 commit comments

Comments
 (0)