import { assert , match , SinonStub , stub } from 'sinon' ; import TelemetryReporter from 'vscode-extension-telemetry' ; import { TelemetryService } from '../../../src/telemetry/telemetry' ; describe ( 'Telemetry' , ( ) => { let reporter ; let sendEvent ; beforeEach ( ( ) => { reporter = new TelemetryReporter ( 'salesforcedx-vscode' , 'v1' , 'test567890' ) ; sendEvent = stub ( reporter , 'sendTelemetryEvent' ) ; } ) ; afterEach ( async ( ) => { sendEvent . restore ( ) ; await reporter . dispose ( ) ; } ) ; it ( 'Should send telemetry data' , async ( ) => { const telemetryService = TelemetryService . getInstance ( ) ; telemetryService . initializeService ( reporter , true ) ; telemetryService . sendExtensionActivationEvent ( [ 0 , 300 ] ) ; assert . calledOnce ( sendEvent ) ; } ) ; it ( 'Should not send telemetry data' , async ( ) => { const telemetryService = TelemetryService . getInstance ( ) ; telemetryService . initializeService ( reporter , false ) ; telemetryService . sendExtensionActivationEvent ( [ 0 , 400 ] ) ; assert . notCalled ( sendEvent ) ; } ) ; it ( 'Should send correct data format on sendExtensionActivationEvent' , async ( ) => { const telemetryService = TelemetryService . getInstance ( ) ; telemetryService . initializeService ( reporter , true ) ; telemetryService . sendExtensionActivationEvent ( [ 0 , 400 ] ) ; assert . calledOnce ( sendEvent ) ; const expectedData = { extensionName : 'salesforcedx-vscode-apex-debugger' , startupTime : match . string } ; assert . calledWith ( sendEvent , 'activationEvent' , match ( expectedData ) ) ; } ) ; it ( 'Should send correct data format on sendExtensionDeactivationEvent' , async ( ) => { const telemetryService = TelemetryService . getInstance ( ) ; telemetryService . initializeService ( reporter , true ) ; telemetryService . sendExtensionDeactivationEvent ( ) ; assert . calledOnce ( sendEvent ) ; const expectedData = { extensionName : 'salesforcedx-vscode-apex-debugger' } ; assert . calledWith ( sendEvent , 'deactivationEvent' , expectedData ) ; } ) ; } ) ;