import "reflect-metadata" ; const rmock = require ( "mock-require" ) ; rmock ( "vscode" , { } ) ; import { assert } from "chai" ; import { GitIsActiveValidator } from "../../../src/bll/cvsutils/gitisactivevalidator" ; import { instance , mock , when } from "ts-mockito" ; import { CpProxy } from "../../../src/bll/moduleproxies/cp-proxy" ; suite ( "Git Is Active Validator" , ( ) => { const correctVersionResult = { stdout : "git version 2.13.2.windows.1" } ; const inCorrectVersionResult = { stdout : "git version 1.13.2.windows.1" } ; test ( "should handle \"git\" with valid params" , function ( done ) { const gitPath = "git" ; const rootPath = "testRootPath" ; const cpMock = mock ( CpProxy ) ; when ( cpMock . execAsync ( getArgumentForGitVersion ( gitPath ) ) ) . thenReturn ( Promise . resolve ( correctVersionResult ) ) ; when ( cpMock . execAsync ( getArgumentForGitIsActiveCommand ( gitPath , rootPath ) ) ) . thenReturn ( Promise . resolve ( undefined ) ) ; const cpSpy = instance ( cpMock ) ; const gitIsActiveValidator = new GitIsActiveValidator ( cpSpy ) ; gitIsActiveValidator . validate ( rootPath , gitPath ) . then ( ( ) => { done ( ) ; } ) . catch ( ( err ) => { done ( err ) ; } ) ; } ) ; test ( "should handle git has incorrect version" , function ( done ) { const gitPath = "git" ; const rootPath = "testRootPath" ; const cpMock = mock ( CpProxy ) ; when ( cpMock . execAsync ( getArgumentForGitVersion ( gitPath ) ) ) . thenReturn ( Promise . resolve ( inCorrectVersionResult ) ) ; when ( cpMock . execAsync ( getArgumentForGitIsActiveCommand ( gitPath , rootPath ) ) ) . thenReturn ( Promise . resolve ( undefined ) ) ; const cpSpy = instance ( cpMock ) ; const gitIsActiveValidator = new GitIsActiveValidator ( cpSpy ) ; gitIsActiveValidator . validate ( rootPath , gitPath ) . then ( ( ) => { done ( "Version should be incorrect" ) ; } ) . catch ( ( err ) => { assert . equal ( err . message , "Git 1.13.2.windows.1 installed. TeamCity extension requires git >= 2" ) ; done ( ) ; } ) ; } ) ; test ( "should handle not in git repo" , function ( done ) { const gitPath = "git" ; const rootPath = "testRootPath" ; const cpMock = mock ( CpProxy ) ; when ( cpMock . execAsync ( getArgumentForGitVersion ( gitPath ) ) ) . thenReturn ( Promise . resolve ( correctVersionResult ) ) ; when ( cpMock . execAsync ( getArgumentForGitIsActiveCommand ( gitPath , rootPath ) ) ) . thenReturn ( Promise . reject ( undefined ) ) ; const cpSpy = instance ( cpMock ) ; const gitIsActiveValidator = new GitIsActiveValidator ( cpSpy ) ; gitIsActiveValidator . validate ( rootPath , gitPath ) . then ( ( ) => { done ( "There should not be a git repo" ) ; } ) . catch ( ( err ) => { assert . equal ( err . message , "Git repository was not determined" ) ; done ( ) ; } ) ; } ) ; } ) ; function getArgumentForGitIsActiveCommand ( path , workspaceRootPath ) { return `"${ path }" -C "${ workspaceRootPath }" rev-parse --show-toplevel` ; } function getArgumentForGitVersion ( path ) { return `"${ path }" --version` ; }