import { expect } from 'chai' ; import * as sinon from 'sinon' ; import * as vscode from 'vscode' ; import { getDocumentName , trackErrorWithTelemetry } from '../../src/commonUtils' ; import { telemetryService } from '../../src/telemetry' ; import { MockTextDocumentProvider } from './testUtilities' ; describe ( 'Common SOQL Builder Utilities' , ( ) => { let mockTextDocument ; let docProviderDisposable ; let sandbox ; beforeEach ( async ( ) => { sandbox = sinon . createSandbox ( ) ; docProviderDisposable = vscode . workspace . registerTextDocumentContentProvider ( 'sfdc-test' , new MockTextDocumentProvider ( ) ) ; mockTextDocument = await vscode . workspace . openTextDocument ( vscode . Uri . parse ( 'sfdc-test:test/examples/soql/mocksoql.soql' ) ) ; } ) ; afterEach ( ( ) => { docProviderDisposable . dispose ( ) ; sandbox . restore ( ) ; } ) ; it ( 'gets the document name form path' , ( ) => { const documentName = getDocumentName ( mockTextDocument ) ; expect ( documentName ) . equals ( 'mocksoql.soql' ) ; } ) ; it ( 'display and track error with correct telemetry namespace' , async ( ) => { const telemetryServiceStub = sandbox . stub ( telemetryService , 'sendException' ) . resolves ( ) ; const errorNamespace = 'test-me' ; const errorDetails = 'this is a test error' ; await trackErrorWithTelemetry ( errorNamespace , errorDetails ) ; expect ( telemetryServiceStub . callCount ) . to . equal ( 1 ) ; expect ( telemetryServiceStub . getCall ( 0 ) . args [ 0 ] ) . to . equal ( `soql_error_${ errorNamespace }` ) ; expect ( telemetryServiceStub . getCall ( 0 ) . args [ 1 ] ) . to . equal ( errorDetails ) ; } ) ; } ) ;