@@ -12,6 +12,7 @@ describe('VersionManagerController', () => {
1212 let commandMock : CommandMock ;
1313
1414 const log = jest . fn ( ) ;
15+ const error = jest . fn ( ) ;
1516
1617 const uiServiceMock = {
1718 table : jest . fn ( ) ,
@@ -32,6 +33,7 @@ describe('VersionManagerController', () => {
3233
3334 [
3435 log ,
36+ error ,
3537 ...Object . values ( uiServiceMock ) ,
3638 ...Object . values ( versionManagerServiceMock ) ,
3739 ] . forEach ( ( spy ) => spy . mockReset ( ) ) ;
@@ -42,15 +44,15 @@ describe('VersionManagerController', () => {
4244 { provide : UIService , useValue : uiServiceMock } ,
4345 { provide : VersionManagerService , useValue : versionManagerServiceMock } ,
4446 { provide : COMMANDER_PROGRAM , useValue : commandMock } ,
45- { provide : LOGGER , useValue : { log } } ,
47+ { provide : LOGGER , useValue : { log, error } } ,
4648 ] ,
4749 } ) . compile ( ) ;
4850 } ) ;
4951
50- it ( 'adds 3 commands, but 2 actions' , ( ) => {
51- expect ( commandMock . action ) . toHaveBeenCalledTimes ( 2 ) ;
52- expect ( commandMock . command ) . toHaveBeenCalledTimes ( 3 ) ;
53- expect ( commandMock . description ) . toHaveBeenCalledTimes ( 3 ) ;
52+ it ( 'adds 4 commands, but 3 actions' , ( ) => {
53+ expect ( commandMock . action ) . toHaveBeenCalledTimes ( 3 ) ;
54+ expect ( commandMock . command ) . toHaveBeenCalledTimes ( 4 ) ;
55+ expect ( commandMock . description ) . toHaveBeenCalledTimes ( 4 ) ;
5456 } ) ;
5557
5658 describe ( 'commands' , function ( ) {
@@ -310,5 +312,44 @@ describe('VersionManagerController', () => {
310312 ) ;
311313 } ) ;
312314 } ) ;
315+
316+ describe ( 'resolve' , ( ) => {
317+ beforeEach ( ( ) => {
318+ cmd = commandMock . commands [ 'resolve <versionTags...>' ] ;
319+ } ) ;
320+
321+ afterEach ( ( ) => {
322+ process . exitCode = 0 ;
323+ } ) ;
324+
325+ it ( 'has the correct description' , ( ) => {
326+ expect ( cmd . description ) . toEqual ( 'resolve version tags to a version' ) ;
327+ } ) ;
328+
329+ it ( 'prints the first matching version' , async ( ) => {
330+ versionManagerServiceMock . search . mockReturnValue (
331+ of ( [ { version : '1.2.4' } , { version : '1.2.3' } ] ) ,
332+ ) ;
333+
334+ await cmd . action ( [ 'latest' ] ) ;
335+
336+ expect ( versionManagerServiceMock . search ) . toHaveBeenNthCalledWith ( 1 , [
337+ 'latest' ,
338+ ] ) ;
339+ expect ( log ) . toHaveBeenNthCalledWith ( 1 , '1.2.4' ) ;
340+ } ) ;
341+
342+ it ( 'prints a message and sets a non-zero exit code if the search result is empty' , async ( ) => {
343+ versionManagerServiceMock . search . mockReturnValue ( of ( [ ] ) ) ;
344+
345+ await cmd . action ( [ 'latest' ] ) ;
346+
347+ expect ( error ) . toHaveBeenNthCalledWith (
348+ 1 ,
349+ chalk . red ( 'Unable to find version matching criteria "latest"' ) ,
350+ ) ;
351+ expect ( process . exitCode ) . toBe ( 1 ) ;
352+ } ) ;
353+ } ) ;
313354 } ) ;
314355} ) ;
0 commit comments