[Telemetry] Provide empty series

Provide an empty series when a historical telemetry request
does not return anything for a given telemetry point.
Addresses WTD-1426.
This commit is contained in:
Victor Woeltjen 2015-07-14 15:51:13 -07:00
parent 4c77dd6a69
commit ea19bde1e7
2 changed files with 18 additions and 3 deletions

View File

@ -29,6 +29,13 @@ define(
function () { function () {
"use strict"; "use strict";
var ZERO = function () { return 0; },
EMPTY_SERIES = {
getPointCount: ZERO,
getDomainValue: ZERO,
getRangeValue: ZERO
};
/** /**
* A telemetry capability provides a means of requesting telemetry * A telemetry capability provides a means of requesting telemetry
* for a specific object, and for unwrapping the response (to get * for a specific object, and for unwrapping the response (to get
@ -102,7 +109,8 @@ define(
// Pull out the relevant field from the larger, // Pull out the relevant field from the larger,
// structured response. // structured response.
function getRelevantResponse(response) { function getRelevantResponse(response) {
return ((response || {})[source] || {})[key] || {}; return ((response || {})[source] || {})[key] ||
EMPTY_SERIES;
} }
// Issue a request to the service // Issue a request to the service
@ -182,4 +190,4 @@ define(
return TelemetryCapability; return TelemetryCapability;
} }
); );

View File

@ -118,6 +118,13 @@ define(
}); });
it("provides an empty series when telemetry is missing", function () {
var series;
mockTelemetryService.requestTelemetry.andReturn(mockPromise({}));
telemetry.requestData({}).then(function (s) { series = s; });
expect(series.getPointCount()).toEqual(0);
});
it("provides telemetry metadata", function () { it("provides telemetry metadata", function () {
expect(telemetry.getMetadata()).toEqual({ expect(telemetry.getMetadata()).toEqual({
id: "testId", // from domain object id: "testId", // from domain object
@ -184,4 +191,4 @@ define(
}); });
}); });
} }
); );