[Telemetry] Added unit tests for addition of bounds and domains to telemetry requests

This commit is contained in:
Henry 2017-03-27 14:53:41 -07:00
parent da40f4c96e
commit 09419398e9
2 changed files with 44 additions and 5 deletions

View File

@ -140,7 +140,8 @@ define(
typeRequest = (type && type.getDefinition().telemetry) || {},
modelTelemetry = domainObject.getModel().telemetry,
fullRequest = Object.create(typeRequest),
bounds;
bounds,
timeSystem;
// Add properties from the telemetry field of this
// specific domain object.
@ -167,6 +168,13 @@ define(
fullRequest.end = bounds.end;
}
if (request.domain === undefined) {
timeSystem = this.openmct.conductor.timeSystem();
if (timeSystem !== undefined) {
fullRequest.domain = timeSystem.metadata.key;
}
}
return fullRequest;
};

View File

@ -104,6 +104,13 @@ define(
start: 0,
end: 1
};
},
timeSystem: function () {
return {
metadata: {
key: 'mockTimeSystem'
}
};
}
}
};
@ -141,7 +148,8 @@ define(
id: "testId", // from domain object
source: "testSource", // from model
key: "testKey", // from model
start: 42 // from argument
start: 42, // from argument
domain: 'mockTimeSystem'
}]);
});
@ -160,7 +168,8 @@ define(
source: "testSource",
key: "testKey",
start: 0,
end: 1
end: 1,
domain: 'mockTimeSystem'
});
});
@ -176,7 +185,8 @@ define(
source: "testSource", // from model
key: "testId", // from domain object
start: 0,
end: 1
end: 1,
domain: 'mockTimeSystem'
});
});
@ -257,7 +267,8 @@ define(
source: "testSource",
key: "testKey",
start: 0,
end: 1
end: 1,
domain: 'mockTimeSystem'
}]
);
@ -274,8 +285,28 @@ define(
expect(mockUnsubscribe).not.toHaveBeenCalled();
subscription(); // should be an unsubscribe function
expect(mockUnsubscribe).toHaveBeenCalled();
});
it("applies time conductor bounds if request bounds not defined", function () {
var fullRequest = telemetry.buildRequest({});
var mockBounds = mockAPI.conductor.bounds();
expect(fullRequest.start).toBe(mockBounds.start);
expect(fullRequest.end).toBe(mockBounds.end);
fullRequest = telemetry.buildRequest({start: 10, end: 20});
expect(fullRequest.start).toBe(10);
expect(fullRequest.end).toBe(20);
});
it("applies domain from time system if none defined", function () {
var fullRequest = telemetry.buildRequest({});
var mockTimeSystem = mockAPI.conductor.timeSystem();
expect(fullRequest.domain).toBe(mockTimeSystem.metadata.key);
fullRequest = telemetry.buildRequest({domain: 'someOtherDomain'});
expect(fullRequest.domain).toBe('someOtherDomain');
});
});
}