Skip to content

Commit f17d894

Browse files
Added additional test cases for fixPropertiesJsonString, that handles nested objects and no properties field
1 parent e37c2a1 commit f17d894

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

azure/test/activity_logs_monitoring.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const client = require('../activity_logs_monitoring').forTests;
33
const constants = client.constants;
44
const sinon = require('sinon');
55
const { InvocationContext } = require('@azure/functions');
6+
const { hostname } = require('os');
67

78
function fakeContext() {
89
return new InvocationContext({
@@ -827,6 +828,43 @@ describe('EventhubLogHandler Fix Properties Json String', function() {
827828
it('parses properties string with single quotes into object', function() {
828829
const record = { properties: "{'key':'value'}" };
829830
const result = this.forwarder.fixPropertiesJsonString(record);
831+
832+
const expectedProperties = { properties: { key: "value" } };
833+
834+
assert.deepEqual(
835+
expectedProperties,
836+
result
837+
);
838+
assert.equal(
839+
'object',
840+
typeof result.properties
841+
)
842+
});
843+
844+
it('parses object that doesnt have properties', function() {
845+
const record = { hostname: "server_name", subObject: { key:"value"} };
846+
const result = this.forwarder.fixPropertiesJsonString(record);
847+
848+
assert.deepEqual(
849+
record,
850+
result
851+
);
852+
assert.equal(
853+
'object',
854+
typeof result
855+
)
856+
});
857+
858+
it('parses properties string with nested objects', function() {
859+
const record = { properties: "{'key':'value','subObj':{ 'subKey' : 'subValue' }}" };
860+
const result = this.forwarder.fixPropertiesJsonString(record);
861+
862+
const expectedProperties = { properties: { key: "value", subObj: { subKey: "subValue"} } };
863+
864+
assert.deepEqual(
865+
expectedProperties,
866+
result
867+
);
830868
assert.equal(
831869
'object',
832870
typeof result.properties
@@ -836,6 +874,11 @@ describe('EventhubLogHandler Fix Properties Json String', function() {
836874
it("leaves properties string unchanged when it doesn't match the malformed pattern", function() {
837875
const record = { properties: 'some plain string without colons' };
838876
const result = this.forwarder.fixPropertiesJsonString(record);
877+
878+
assert.deepEqual(
879+
record,
880+
result
881+
);
839882
assert.equal(
840883
'string',
841884
typeof result.properties
@@ -846,6 +889,11 @@ describe('EventhubLogHandler Fix Properties Json String', function() {
846889
// includes the "':'" marker so the function attempts replacement, but JSON remains invalid
847890
const badRecord = { properties: "Look i know i shouldn't but, i will do this ':' " };
848891
const result = this.forwarder.fixPropertiesJsonString(badRecord);
892+
893+
assert.deepEqual(
894+
badRecord,
895+
result
896+
);
849897
assert.equal(
850898
'string',
851899
typeof result.properties

0 commit comments

Comments
 (0)