diff --git a/resources/static/common/js/modules/interaction_data.js b/resources/static/common/js/modules/interaction_data.js index 8f36514dac7ddc5f6f13dccd4d4e6a593f105ef5..77267d4743e546aa161216319f49fdd800236677 100644 --- a/resources/static/common/js/modules/interaction_data.js +++ b/resources/static/common/js/modules/interaction_data.js @@ -155,9 +155,12 @@ BrowserID.Modules.InteractionData = (function() { } function onKPIData(msg, result) { + // currentData will be undefined if sampling is disabled. var currentData = this.getCurrent(); - _.extend(currentData, result); - model.setCurrent(currentData); + if (currentData) { + _.extend(currentData, result); + model.setCurrent(currentData); + } } // At every load, after session_context returns, try to publish the previous @@ -281,6 +284,14 @@ BrowserID.Modules.InteractionData = (function() { , setNameTable: function(table) { this.mediatorToKPINameTable = table; + }, + + enable: function() { + this.samplingEnabled = true; + }, + + disable: function() { + this.samplingEnabled = false; } // END TEST API }); diff --git a/resources/static/test/cases/common/js/modules/interaction_data.js b/resources/static/test/cases/common/js/modules/interaction_data.js index 1beb33008293d297a40f88cabcd519e042959ef8..669b0fe30fa3d407c500b68ee6d4369bc28f3bb7 100644 --- a/resources/static/test/cases/common/js/modules/interaction_data.js +++ b/resources/static/test/cases/common/js/modules/interaction_data.js @@ -14,7 +14,7 @@ mediator = bid.Mediator, controller; - module("shared/modules/interaction_data", { + module("common/js/modules/interaction_data", { setup: function() { testHelpers.setup(); localStorage.removeItem("interaction_data"); @@ -246,13 +246,23 @@ }); }); - asyncTest("kpi_data message adds fields to current kpi_data", function() { + asyncTest("kpi_data message only adds fields to current kpi_data if sampling is enabled", function() { createController(); network.withContext(function() { + // number_emails will not be added to KPI data because sampling is + // disabled. + controller.disable(); mediator.publish("kpi_data", { number_emails: 1 }); + testHelpers.testUndefined(controller.getCurrent()); + + // number_emails will be added to KPI data because sampling is + // disabled. + controller.enable(); + mediator.publish("kpi_data", { number_emails: 2 }); testHelpers.testObjectValuesEqual(controller.getCurrent(), { - number_emails: 1 + number_emails: 2 }); + start(); }); });