Skip to content

Commit 165df39

Browse files
iakiobugthesystem
authored andcommitted
Fix tests (#92)
* typo * Fix gitProvider tests #87 * Fix Bitbucket tests See #82, #86, and https://confluence.atlassian.com/bitbucket/hyperlinking-to-source-code-in-bitbucket-824476709.html
1 parent 8e94f85 commit 165df39

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

test/gitProvider.test.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const path = require('path');
34
const querystring = require('querystring');
45
const expect = require('chai').expect;
56
const proxyquire = require('proxyquire');
@@ -9,6 +10,7 @@ const gitProvider = require('../src/gitProvider');
910
const userName = 'testUser';
1011
const repoName = 'testRepo';
1112
const filePath = '/sampleDirectory/sampleTestFile.txt';
13+
const fileName = path.basename(filePath);
1214
const branch = 'master';
1315
const 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

Comments
 (0)