@@ -6,7 +6,6 @@ import semver = require('semver/preload');
66jest . mock ( 'os' ) ;
77jest . mock ( '@actions/core' ) ;
88jest . mock ( 'semver' ) ;
9-
109const DEFAULT_CLI_URL : string = 'https://releases.jfrog.io/artifactory/jfrog-cli/' ;
1110const CUSTOM_CLI_URL : string = 'http://127.0.0.1:8081/artifactory/jfrog-cli-remote/' ;
1211// Config in JFrog CLI 1.46.3 and below
@@ -425,3 +424,37 @@ describe('isJobSummarySupported', () => {
425424 expect ( semver . gte ) . toHaveBeenCalledWith ( version , MIN_CLI_VERSION_JOB_SUMMARY ) ;
426425 } ) ;
427426} ) ;
427+
428+ describe ( 'Utils.removeJFrogServers' , ( ) => {
429+ beforeEach ( ( ) => {
430+ jest . clearAllMocks ( ) ;
431+ } ) ;
432+
433+ it ( 'should remove only the custom server ID if defined' , async ( ) => {
434+ const customServerId : string = 'custom-server-id' ;
435+ jest . spyOn ( Utils as any , 'getInputtedCustomId' ) . mockReturnValue ( customServerId ) ;
436+ jest . spyOn ( Utils as any , 'runCli' ) . mockResolvedValue ( undefined ) ;
437+
438+ await Utils . removeJFrogServers ( ) ;
439+
440+ expect ( core . info ) . toHaveBeenCalledWith ( `The value of custom is: '${ customServerId } '` ) ;
441+ expect ( core . debug ) . toHaveBeenCalledWith ( `Removing custom server ID: '${ customServerId } '...` ) ;
442+ expect ( Utils . runCli ) . toHaveBeenCalledWith ( [ 'c' , 'rm' , customServerId , '--quiet' ] ) ;
443+ } ) ;
444+
445+ it ( 'should remove all configured server IDs if no custom server ID is defined' , async ( ) => {
446+ jest . spyOn ( Utils as any , 'getInputtedCustomId' ) . mockReturnValue ( undefined ) ;
447+ const serverIds : string [ ] = [ 'server1' , 'server2' ] ;
448+ jest . spyOn ( Utils as any , 'getConfiguredJFrogServers' ) . mockReturnValue ( serverIds ) ;
449+ jest . spyOn ( Utils as any , 'runCli' ) . mockResolvedValue ( undefined ) ;
450+
451+ await Utils . removeJFrogServers ( ) ;
452+
453+ expect ( core . info ) . toHaveBeenCalledWith ( `The value of custom is: 'undefined'` ) ;
454+ for ( const serverId of serverIds ) {
455+ expect ( core . debug ) . toHaveBeenCalledWith ( `Removing server ID: '${ serverId } '...` ) ;
456+ expect ( Utils . runCli ) . toHaveBeenCalledWith ( [ 'c' , 'rm' , serverId , '--quiet' ] ) ;
457+ }
458+ expect ( core . exportVariable ) . toHaveBeenCalledWith ( Utils . JFROG_CLI_SERVER_IDS_ENV_VAR , '' ) ;
459+ } ) ;
460+ } ) ;
0 commit comments