"use strict" ; import { assert } from "chai" ; import * as http from "http" ; import { anyString , instance , mock , when } from "ts-mockito" ; import { InMemoryCredentialsStore } from "../../src/bll/credentialsstore/inmemorycredentialsstore" ; import { TestSettings } from "../testsettings" ; import { FsProxy } from "../../src/bll/moduleproxies/fs-proxy" ; import * as stream from "stream" ; import * as Assert from "assert" ; import { WebLinks } from "../../src/dal/weblinks" ; import { VsCodeUtils } from "../../src/bll/utils/vscodeutils" ; const EXPECTED_CONTENT_LENGTH = 239 ; suite ( "WebLinksImpl" , ( ) => { test ( "should verify uploadChanges" , function ( done ) { setupServer ( done ) ; const credStoreMock = mock ( InMemoryCredentialsStore ) ; when ( credStoreMock . getCredentials ( ) ) . thenReturn ( Promise . resolve ( TestSettings . credentials ) ) ; const credStoreSpy = instance ( credStoreMock ) ; const readable = new stream . Readable ( ) ; const fsProxyMock = mock ( FsProxy ) ; when ( fsProxyMock . createReadStream ( anyString ( ) ) ) . thenReturn ( readable ) ; when ( fsProxyMock . getFileSize ( anyString ( ) ) ) . thenReturn ( EXPECTED_CONTENT_LENGTH ) ; const fsProxySpy = instance ( fsProxyMock ) ; readable . push ( null ) ; const webLinksImpl = new WebLinks ( credStoreSpy , fsProxySpy , new VsCodeUtils ( ) ) ; webLinksImpl . uploadChanges ( "patchPath" , "testMessage" ) . then ( ( ) => { } ) . catch ( ( err ) => { done ( err ) ; } ) ; } ) ; } ) ; function setupServer ( done ) { http . createServer ( function ( req , res ) { try { res . end ( ) ; Assert . equal ( req . headers [ "authorization" ] , TestSettings . basicAuthHeader ) ; Assert . equal ( req . headers [ "content-length" ] , EXPECTED_CONTENT_LENGTH ) ; Assert . notEqual ( req . headers [ "user-agent" ] . indexOf ( "TeamCity Integration" ) , - 1 , "User " + "agent header should contain a corresponding string" ) ; done ( ) ; } catch ( err ) { done ( err ) ; } } ) . listen ( TestSettings . port ) ; }