Skip to content

Commit 4411f19

Browse files
Added test cases, for fixPropertiesJsonString for code coverage
1 parent ca62654 commit 4411f19

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

azure/test/activity_logs_monitoring.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,3 +818,37 @@ describe('Log Splitting', function() {
818818
});
819819
});
820820
});
821+
describe('EventhubLogHandler Fix Properties Json String', function() {
822+
823+
beforeEach(function() {
824+
this.forwarder = setUp();
825+
});
826+
827+
it('parses properties string with single quotes into object', function() {
828+
const record = { properties: "{'key':'value'}" };
829+
const result = this.forwarder.fixPropertiesJsonString(record);
830+
assert.equal(
831+
'object',
832+
typeof result.properties
833+
)
834+
});
835+
836+
it("leaves properties string unchanged when it doesn't match the malformed pattern", function() {
837+
const record = { properties: 'some plain string without colons' };
838+
const result = this.forwarder.fixPropertiesJsonString(record);
839+
assert.equal(
840+
'string',
841+
typeof result.properties
842+
)
843+
});
844+
845+
it('logs an error and returns original record when replacement results in invalid JSON', function() {
846+
// includes the "':'" marker so the function attempts replacement, but JSON remains invalid
847+
const badRecord = { properties: "Look i know i shouldn't but, i will do this ':' " };
848+
const result = this.forwarder.fixPropertiesJsonString(badRecord);
849+
assert.equal(
850+
'string',
851+
typeof result.properties
852+
)
853+
});
854+
});

0 commit comments

Comments
 (0)