11import { expect , describe , it } from "@jest/globals" ;
2- import { logger , HeartbeatMetrics , HeartbeatLogs , Watchdogs } from "LoggerWrapper.js" ;
2+ import { logger , HeartbeatMetrics , HeartbeatLogs , Watchdogs , parseIsExtension } from "LoggerWrapper.js" ;
33import * as applicationInsights from "applicationinsights" ;
44
55beforeEach ( ( ) => {
@@ -10,6 +10,99 @@ afterEach(() => {
1010 jest . restoreAllMocks ( ) ;
1111} ) ;
1212
13+ describe ( "isExtension" , ( ) => {
14+ describe ( "Parsing" , ( ) => {
15+ it ( "Parses 'true' as true" , ( ) => {
16+ expect ( parseIsExtension ( "true" ) ) . toBe ( true ) ;
17+ } ) ;
18+
19+ it ( "Parses '1' as true" , ( ) => {
20+ expect ( parseIsExtension ( "1" ) ) . toBe ( true ) ;
21+ } ) ;
22+
23+ it ( "Parses 'yes' as true" , ( ) => {
24+ expect ( parseIsExtension ( "yes" ) ) . toBe ( true ) ;
25+ } ) ;
26+
27+ it ( "Parses 'TRUE' (uppercase) as true" , ( ) => {
28+ expect ( parseIsExtension ( "TRUE" ) ) . toBe ( true ) ;
29+ } ) ;
30+
31+ it ( "Parses 'false' as false" , ( ) => {
32+ expect ( parseIsExtension ( "false" ) ) . toBe ( false ) ;
33+ } ) ;
34+
35+ it ( "Parses '0' as false" , ( ) => {
36+ expect ( parseIsExtension ( "0" ) ) . toBe ( false ) ;
37+ } ) ;
38+
39+ it ( "Parses undefined as false" , ( ) => {
40+ expect ( parseIsExtension ( undefined ) ) . toBe ( false ) ;
41+ } ) ;
42+
43+ it ( "Parses empty string as false" , ( ) => {
44+ expect ( parseIsExtension ( "" ) ) . toBe ( false ) ;
45+ } ) ;
46+ } ) ;
47+
48+ describe ( "Telemetry Inclusion" , ( ) => {
49+ it ( "Includes isExtension in event telemetry" , async ( ) => {
50+ const eventsSent = < applicationInsights . Contracts . EventTelemetry [ ] > [ ] ;
51+
52+ jest . spyOn ( applicationInsights . TelemetryClient . prototype , "trackEvent" ) . mockImplementation ( ( telemetry : applicationInsights . Contracts . EventTelemetry ) => {
53+ eventsSent . push ( telemetry ) ;
54+ } ) ;
55+
56+ await logger . SendEvent ( "TestEvent" , "test-operation-id" , "test-uid" , false ) ;
57+
58+ expect ( eventsSent . length ) . toBe ( 1 ) ;
59+ expect ( eventsSent [ 0 ] . properties . clusterMetadata ) . toBeDefined ( ) ;
60+
61+ const clusterMetadata = JSON . parse ( eventsSent [ 0 ] . properties . clusterMetadata ) ;
62+ expect ( clusterMetadata . isExtension ) . toBeDefined ( ) ;
63+ expect ( typeof clusterMetadata . isExtension ) . toBe ( "boolean" ) ;
64+ } ) ;
65+
66+ it ( "Includes isExtension in metric telemetry" , async ( ) => {
67+ logger . setHeartbeatMetric ( HeartbeatMetrics . CRCount , 5 ) ;
68+
69+ const metricsSent = < ( applicationInsights . Contracts . MetricTelemetry & applicationInsights . Contracts . MetricPointTelemetry ) [ ] > [ ] ;
70+
71+ jest . spyOn ( applicationInsights . TelemetryClient . prototype , "trackMetric" ) . mockImplementation ( ( telemetry : applicationInsights . Contracts . MetricTelemetry & applicationInsights . Contracts . MetricPointTelemetry ) => {
72+ metricsSent . push ( telemetry ) ;
73+ } ) ;
74+
75+ await logger . startHeartbeats ( "test-operation-id" ) ;
76+
77+ expect ( metricsSent . length ) . toBeGreaterThan ( 0 ) ;
78+ expect ( metricsSent [ 0 ] . properties . clusterMetadata ) . toBeDefined ( ) ;
79+
80+ const clusterMetadata = JSON . parse ( metricsSent [ 0 ] . properties . clusterMetadata ) ;
81+ expect ( clusterMetadata . isExtension ) . toBeDefined ( ) ;
82+ expect ( typeof clusterMetadata . isExtension ) . toBe ( "boolean" ) ;
83+ } ) ;
84+
85+ it ( "Includes isExtension in trace telemetry" , async ( ) => {
86+ logger . appendHeartbeatLog ( HeartbeatLogs . ApiServerTopExceptionsEncountered , "test-error" ) ;
87+
88+ const tracesSent = < applicationInsights . Contracts . TraceTelemetry [ ] > [ ] ;
89+
90+ jest . spyOn ( applicationInsights . TelemetryClient . prototype , "trackTrace" ) . mockImplementation ( ( telemetry : applicationInsights . Contracts . TraceTelemetry ) => {
91+ tracesSent . push ( telemetry ) ;
92+ } ) ;
93+
94+ await logger . startHeartbeats ( "test-operation-id" ) ;
95+
96+ expect ( tracesSent . length ) . toBeGreaterThan ( 0 ) ;
97+ expect ( tracesSent [ 0 ] . properties . clusterMetadata ) . toBeDefined ( ) ;
98+
99+ const clusterMetadata = JSON . parse ( tracesSent [ 0 ] . properties . clusterMetadata ) ;
100+ expect ( clusterMetadata . isExtension ) . toBeDefined ( ) ;
101+ expect ( typeof clusterMetadata . isExtension ) . toBe ( "boolean" ) ;
102+ } ) ;
103+ } ) ;
104+ } ) ;
105+
13106describe ( "Heartbeats" , ( ) => {
14107 it ( "Sends logs" , async ( ) => {
15108 for ( let i = 0 ; i < 10 ; i ++ ) {
0 commit comments