11import is from '@sindresorhus/is' ;
22import { mockDeep } from 'jest-mock-extended' ;
33import * as httpMock from '../../../../test/http-mock' ;
4+ import { mocked } from '../../../../test/util' ;
45import {
56 REPOSITORY_CHANGED ,
67 REPOSITORY_EMPTY ,
78 REPOSITORY_NOT_FOUND ,
89} from '../../../constants/error-messages' ;
10+ import type { logger as _logger } from '../../../logger' ;
911import type * as _git from '../../../util/git' ;
1012import type { LongCommitSha } from '../../../util/git/types' ;
1113import type { Platform } from '../types' ;
@@ -185,6 +187,7 @@ describe('modules/platform/bitbucket-server/index', () => {
185187
186188 let hostRules : jest . Mocked < HostRules > ;
187189 let git : jest . Mocked < typeof _git > ;
190+ let logger : jest . Mocked < typeof _logger > ;
188191 const username = 'abc' ;
189192 const password = '123' ;
190193
@@ -211,6 +214,7 @@ describe('modules/platform/bitbucket-server/index', () => {
211214 // reset module
212215 jest . resetModules ( ) ;
213216 bitbucket = await import ( '.' ) ;
217+ logger = mocked ( await import ( '../../../logger' ) ) . logger ;
214218 hostRules = jest . requireMock ( '../../../util/host-rules' ) ;
215219 git = jest . requireMock ( '../../../util/git' ) ;
216220 git . branchExists . mockReturnValue ( true ) ;
@@ -226,6 +230,10 @@ describe('modules/platform/bitbucket-server/index', () => {
226230 username,
227231 password,
228232 } ) ;
233+ httpMock
234+ . scope ( urlHost )
235+ . get ( `${ urlPath } /rest/api/1.0/application-properties` )
236+ . reply ( 200 , { version : '8.0.0' } ) ;
229237 await bitbucket . initPlatform ( {
230238 endpoint,
231239 username,
@@ -234,19 +242,52 @@ describe('modules/platform/bitbucket-server/index', () => {
234242 } ) ;
235243
236244 describe ( 'initPlatform()' , ( ) => {
237- it ( 'should throw if no endpoint' , ( ) => {
245+ it ( 'should throw if no endpoint' , async ( ) => {
238246 expect . assertions ( 1 ) ;
239- expect ( ( ) => bitbucket . initPlatform ( { } ) ) . toThrow ( ) ;
247+ await expect ( bitbucket . initPlatform ( { } ) ) . rejects . toThrow ( ) ;
240248 } ) ;
241249
242- it ( 'should throw if no username/password' , ( ) => {
250+ it ( 'should throw if no username/password' , async ( ) => {
243251 expect . assertions ( 1 ) ;
244- expect ( ( ) =>
252+ await expect (
245253 bitbucket . initPlatform ( { endpoint : 'endpoint' } ) ,
246- ) . toThrow ( ) ;
254+ ) . rejects . toThrow ( ) ;
255+ } ) ;
256+
257+ it ( 'should throw if version could not be fetched' , async ( ) => {
258+ httpMock
259+ . scope ( 'https://stash.renovatebot.com' )
260+ . get ( '/rest/api/1.0/application-properties' )
261+ . reply ( 403 ) ;
262+
263+ await bitbucket . initPlatform ( {
264+ endpoint : 'https://stash.renovatebot.com' ,
265+ username : 'abc' ,
266+ password : '123' ,
267+ } ) ;
268+ expect ( logger . debug ) . toHaveBeenCalledWith (
269+ expect . any ( Object ) ,
270+ 'Error authenticating with Bitbucket. Check that your token includes "api" permissions' ,
271+ ) ;
272+ } ) ;
273+
274+ it ( 'should skip api call to fetch version when platform version is set in environment' , async ( ) => {
275+ process . env . RENOVATE_X_PLATFORM_VERSION = '8.0.0' ;
276+ await expect (
277+ bitbucket . initPlatform ( {
278+ endpoint : 'https://stash.renovatebot.com' ,
279+ username : 'abc' ,
280+ password : '123' ,
281+ } ) ,
282+ ) . toResolve ( ) ;
283+ delete process . env . RENOVATE_X_PLATFORM_VERSION ;
247284 } ) ;
248285
249286 it ( 'should init' , async ( ) => {
287+ httpMock
288+ . scope ( 'https://stash.renovatebot.com' )
289+ . get ( '/rest/api/1.0/application-properties' )
290+ . reply ( 200 , { version : '8.0.0' } ) ;
250291 expect (
251292 await bitbucket . initPlatform ( {
252293 endpoint : 'https://stash.renovatebot.com' ,
0 commit comments