Skip to content

Commit

Permalink
Address issue #368
Browse files Browse the repository at this point in the history
  • Loading branch information
OsvaldoRosado committed Feb 7, 2018
1 parent d7f737f commit b324e79
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface DependencyTelemetry extends Telemetry {
/**
* Result code returned form the remote component. This is domain specific and can be HTTP status code or SQL result code
*/
resultCode: string;
resultCode: string | number;

/**
* True if remote call was successful, false otherwise
Expand Down
2 changes: 1 addition & 1 deletion Declarations/Contracts/TelemetryTypes/RequestTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface RequestTelemetry extends Telemetry
/**
* Result code reported by the application
*/
resultCode: string;
resultCode: string | number;

/**
* Whether the request was successful
Expand Down
4 changes: 2 additions & 2 deletions Library/EnvelopeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class EnvelopeFactory {
remoteDependency.success = telemetry.success;
remoteDependency.type = telemetry.dependencyTypeName;
remoteDependency.properties = telemetry.properties;
remoteDependency.resultCode = telemetry.resultCode;
remoteDependency.resultCode = (telemetry.resultCode ? telemetry.resultCode + '' : '');

if (telemetry.id) {
remoteDependency.id = telemetry.id;
Expand Down Expand Up @@ -177,7 +177,7 @@ class EnvelopeFactory {
requestData.url = telemetry.url;
requestData.source = telemetry.source;
requestData.duration = Util.msToTimeSpan(telemetry.duration);
requestData.responseCode = telemetry.resultCode;
requestData.responseCode = (telemetry.resultCode ? telemetry.resultCode + '' : '');
requestData.success = telemetry.success
requestData.properties = telemetry.properties;

Expand Down
43 changes: 43 additions & 0 deletions Tests/Library/Client.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,28 @@ describe("Library/TelemetryClient", () => {
assert.deepEqual(obj0.baseData.properties, properties);
});

it("should create envelope with correct properties (numeric result code)", () => {
trackStub.restore();
var commandName = "http://bing.com/search?q=test";
var dependencyTypeName = "dependencyTypeName";
var createEnvelopeSpy = sinon.spy(EnvelopeFactory, "createEnvelope");
client.trackDependency({ name: name, data: commandName, duration: value, success: true, resultCode: 0, dependencyTypeName: dependencyTypeName, properties: properties });
assert.ok(createEnvelopeSpy.calledOnce);


var envelopeCreated = createEnvelopeSpy.firstCall.returnValue;
var obj0 = <Contracts.Data<Contracts.RemoteDependencyData>>envelopeCreated.data;
createEnvelopeSpy.restore();

assert.equal(obj0.baseData.name, name);
assert.equal(obj0.baseData.data, commandName);
assert.equal(obj0.baseData.target, 'bing.com');
assert.equal(obj0.baseData.duration, Util.msToTimeSpan(value));
assert.equal(obj0.baseData.success, true);
assert.equal(obj0.baseData.type, dependencyTypeName);
assert.deepEqual(obj0.baseData.properties, properties);
});

it("should process the id when specified", () => {
trackStub.restore();
var commandName = "http://bing.com/search?q=test";
Expand Down Expand Up @@ -666,6 +688,27 @@ describe("Library/TelemetryClient", () => {
assert.deepEqual(obj0.baseData.properties, properties);
});

it("should create envelope with correct properties (numeric resultCode)", () => {
trackStub.restore();
var url = "http://bing.com/search?q=test";
var createEnvelopeSpy = sinon.spy(EnvelopeFactory, "createEnvelope");
client.trackRequest({ url: url, source: "source", name: name, duration: value, success: true, resultCode: 200, properties: properties });
assert.ok(createEnvelopeSpy.calledOnce);


var envelopeCreated = createEnvelopeSpy.firstCall.returnValue;
var obj0 = <Contracts.Data<Contracts.RequestData>>envelopeCreated.data;
createEnvelopeSpy.restore();

assert.equal(obj0.baseData.name, name);
assert.equal(obj0.baseData.url, url);
assert.equal(obj0.baseData.source, 'source');
assert.equal(obj0.baseData.duration, Util.msToTimeSpan(value));
assert.equal(obj0.baseData.success, true);
assert.equal(obj0.baseData.responseCode, "200");
assert.deepEqual(obj0.baseData.properties, properties);
});

it("should process the id when specified", () => {
trackStub.restore();
var url = "http://bing.com/search?q=test";
Expand Down

0 comments on commit b324e79

Please sign in to comment.