import "reflect-metadata" ; const rmock = require ( "mock-require" ) ; rmock ( "vscode" , { } ) ; import { TfvcIsActiveValidator } from "../../../src/bll/cvsutils/tfvcisactivevalidator" ; import { instance , mock , when } from "ts-mockito" ; import { CpProxy } from "../../../src/bll/moduleproxies/cp-proxy" ; suite ( "Tfvc Is Active Validator" , ( ) => { const tfvcPath = "tf" ; const rootPath = "testRootPath" ; const correctResult = { stdout : "Not null output" } ; test ( "should handle \"tf\" with valid params" , function ( done ) { const cpMock = mock ( CpProxy ) ; when ( cpMock . execAsync ( getArgumentForIsTfsRepository ( tfvcPath , rootPath ) ) ) . thenReturn ( Promise . resolve ( correctResult ) ) ; const cpSpy = instance ( cpMock ) ; const tfvcIsActiveValidator = new TfvcIsActiveValidator ( cpSpy ) ; tfvcIsActiveValidator . validate ( rootPath , tfvcPath ) . then ( ( ) => { done ( ) ; } ) . catch ( ( err ) => { done ( err ) ; } ) ; } ) ; test ( "should handle not tfvc repo" , function ( done ) { const cpMock = mock ( CpProxy ) ; when ( cpMock . execAsync ( getArgumentForIsTfsRepository ( tfvcPath , rootPath ) ) ) . thenReturn ( Promise . reject ( undefined ) ) ; const cpSpy = instance ( cpMock ) ; const tfvcIsActiveValidator = new TfvcIsActiveValidator ( cpSpy ) ; tfvcIsActiveValidator . validate ( rootPath , tfvcPath ) . then ( ( ) => { done ( "Should not be tfvc repo" ) ; } ) . catch ( ( err ) => { if ( err . message === "Tfs repository was not determined" ) { done ( ) ; } else { done ( "unexpected error message" ) ; } } ) ; } ) ; } ) ; function getArgumentForIsTfsRepository ( tfPath , workspaceRootPath ) { return `"${ tfPath }" diff /noprompt /format:brief /recursive "${ workspaceRootPath }"` ; }