Change addTrackingProperties to only set header.id if trackingProperties is defined and has id property.

This commit is contained in:
Matt Mazzola 2016-06-22 11:42:44 -07:00
Родитель aed367078c
Коммит f8f23ff8a3
2 изменённых файлов: 18 добавлений и 1 удалений

Просмотреть файл

@ -22,7 +22,9 @@ export class HttpPostMessage {
// live in this class, but then we have to have hard dependency for things like ITrackingProperties
static addTrackingProperties(message: any, trackingProperties: any): any {
message.headers = message.headers || {};
message.headers.id = trackingProperties.id;
if(trackingProperties && trackingProperties.id) {
message.headers.id = trackingProperties.id;
}
return message;
}
static getTrackingProperties(message: any): any {

Просмотреть файл

@ -182,6 +182,21 @@ describe("HttpPostMessage", function () {
// Assert
expect(resultMessage.headers.id).toEqual(trackingProperties.id);
});
it("addTrackingProperties will set header.id to undefined if trackingProperties or trackingProperties.id provided is falsy", function () {
// Arrange
const testMessage = {
method: "GET",
url: "report/pages",
headers: {}
};
// Act
const resultMessage = hpm.HttpPostMessage.addTrackingProperties(testMessage, { x: 'abc' });
// Assert
expect(resultMessage.headers.id).toBe(undefined);
});
it("getTrackingProperties should return tracking properties object by fetching id from headers of message", function () {
// Arrange