Skip to content
Snippets Groups Projects
Commit 400a413c authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

Merge pull request #1980 from mozilla/hotfix_1978_kpi_off

Fix exception being thrown if KPI data is disabled.
parents acce0c1e 162c49b8
No related branches found
No related tags found
No related merge requests found
......@@ -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
});
......
......@@ -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();
});
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment