11'use strict' ;
22
3+ const path = require ( 'path' ) ;
34const querystring = require ( 'querystring' ) ;
45const expect = require ( 'chai' ) . expect ;
56const proxyquire = require ( 'proxyquire' ) ;
@@ -9,6 +10,7 @@ const gitProvider = require('../src/gitProvider');
910const userName = 'testUser' ;
1011const repoName = 'testRepo' ;
1112const filePath = '/sampleDirectory/sampleTestFile.txt' ;
13+ const fileName = path . basename ( filePath ) ;
1214const branch = 'master' ;
1315const line = 123 ;
1416
@@ -62,8 +64,12 @@ suite('gitProvider', function () {
6264 workspace : {
6365 getConfiguration : function ( ) {
6466 return {
65- get : function ( ) {
66- return testDomain ;
67+ get : function ( configKey ) {
68+ if ( configKey === 'gitHubDomain' ) {
69+ return testDomain ;
70+ } else if ( configKey === 'useCommitSHAInURL' ) {
71+ return false ;
72+ }
6773 } ,
6874 } ;
6975 } ,
@@ -93,7 +99,7 @@ suite('gitProvider', function () {
9399 get : function ( configKey ) {
94100 if ( configKey === 'gitHubDomain' ) {
95101 return testDomain ;
96- } else if ( providerProtocol === 'providerProtocol' ) {
102+ } else if ( configKey === 'providerProtocol' ) {
97103 return testProtocol ;
98104 }
99105 } ,
@@ -116,39 +122,40 @@ suite('gitProvider', function () {
116122
117123 suite ( 'Bitbucket' , function ( ) {
118124 const remoteUrl = `https://bitbucket.org/${ userName } /${ repoName } .git` ;
119- const provider = gitProvider ( remoteUrl ) ;
125+ const sha = 'f9f2dcbf56e88ee3612c9890a6df1cfd4dde8c5e' ;
126+ const provider = gitProvider ( remoteUrl , sha ) ;
120127
121128 suite ( '#webUrl(branch, filePath)' , function ( ) {
122129 test ( 'should returns file URL' , function ( ) {
123- const expectedUrl = `https://bitbucket.org/${ userName } /${ repoName } /src/${ branch } ${ filePath } ` ;
130+ const expectedUrl = `https://bitbucket.org/${ userName } /${ repoName } /src/${ sha } ${ filePath } ` ;
124131 const webUrl = provider . webUrl ( branch , filePath ) ;
125132 expect ( webUrl ) . to . equal ( expectedUrl ) ;
126133 } ) ;
127134 } ) ;
128135
129136 suite ( '#webUrl(branch, filePath, line)' , function ( ) {
130137 test ( 'should returns file URL with line hash' , function ( ) {
131- const expectedUrl = `https://bitbucket.org/${ userName } /${ repoName } /src/${ branch } ${ filePath } #cl -${ line } ` ;
138+ const expectedUrl = `https://bitbucket.org/${ userName } /${ repoName } /src/${ sha } ${ filePath } #${ fileName } -${ line } ` ;
132139 const webUrl = provider . webUrl ( branch , filePath , line ) ;
133140 expect ( webUrl ) . to . equal ( expectedUrl ) ;
134141 } ) ;
135142 } ) ;
136143
137144 suite ( '#webUrl(branch)' , function ( ) {
138145 test ( 'should returns repository root URL' , function ( ) {
139- const expectedUrl = `https://bitbucket.org/${ userName } /${ repoName } /src/${ branch } ` ;
140- const webUrl = provider . webUrl ( branch ) ;
146+ const expectedUrl = `https://bitbucket.org/${ userName } /${ repoName } /src/${ sha } ` ;
147+ const webUrl = provider . webUrl ( branch , '' ) ;
141148 expect ( webUrl ) . to . equal ( expectedUrl ) ;
142149 } ) ;
143150 } ) ;
144151
145152 suite ( 'with ssh remote URL' , function ( ) {
146153 const remoteUrl = `[email protected] :${ userName } /${ repoName } .git` ; 147- const provider = gitProvider ( remoteUrl ) ;
154+ const provider = gitProvider ( remoteUrl , sha ) ;
148155
149156 suite ( '#webUrl(branch, filePath)' , function ( ) {
150157 test ( 'should returns HTTPS URL' , function ( ) {
151- const expectedUrl = `https://bitbucket.org/${ userName } /${ repoName } /src/${ branch } ${ filePath } ` ;
158+ const expectedUrl = `https://bitbucket.org/${ userName } /${ repoName } /src/${ sha } ${ filePath } ` ;
152159 const webUrl = provider . webUrl ( branch , filePath ) ;
153160 expect ( webUrl ) . to . equal ( expectedUrl ) ;
154161 } ) ;
0 commit comments