diff --git a/resources/static/common/js/modules/interaction_data.js b/resources/static/common/js/modules/interaction_data.js index 181db90d64aedef85291e5ad943019de8a4133ed..11379e4df87faddcb1909f8e6bab23b66614c06e 100644 --- a/resources/static/common/js/modules/interaction_data.js +++ b/resources/static/common/js/modules/interaction_data.js @@ -220,9 +220,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 @@ -346,6 +349,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 eadf72fa0db55e4fa480598c97a47f340104f2ff..1b8130529be9d6c28a76491d8d1d24c46d2f647c 100644 --- a/resources/static/test/cases/common/js/modules/interaction_data.js +++ b/resources/static/test/cases/common/js/modules/interaction_data.js @@ -15,7 +15,7 @@ mediator = bid.Mediator, controller; - module("shared/modules/interaction_data", { + module("common/js/modules/interaction_data", { setup: function() { testHelpers.setup(); localStorage.removeItem("interaction_data"); @@ -249,13 +249,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(); }); });