@@ -299,4 +299,126 @@ await FluentActions
299299 _mockGithubApi . Verify ( m => m . GetMigrationLogUrl ( githubOrg , repo ) , Times . Exactly ( 6 ) ) ;
300300 _mockHttpDownloadService . Verify ( m => m . DownloadToFile ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ) , Times . Never ( ) ) ;
301301 }
302+
303+ [ Fact ]
304+ public async Task Should_Throw_When_Neither_MigrationId_Nor_OrgRepo_Provided ( )
305+ {
306+ // Act & Assert
307+ var args = new DownloadLogsCommandArgs ( ) ;
308+ await FluentAssertions . FluentActions
309+ . Invoking ( async ( ) => await _handler . Handle ( args ) )
310+ . Should ( ) . ThrowAsync < OctoshiftCliException > ( )
311+ . WithMessage ( "Either --migration-id (GraphQL migration ID) or both --github-org and --github-repo must be specified." ) ;
312+ }
313+
314+ [ Fact ]
315+ public async Task Should_Throw_When_Only_GithubOrg_Provided ( )
316+ {
317+ // Act & Assert
318+ var args = new DownloadLogsCommandArgs
319+ {
320+ GithubOrg = "test-org"
321+ } ;
322+ await FluentAssertions . FluentActions
323+ . Invoking ( async ( ) => await _handler . Handle ( args ) )
324+ . Should ( ) . ThrowAsync < OctoshiftCliException > ( )
325+ . WithMessage ( "Either --migration-id (GraphQL migration ID) or both --github-org and --github-repo must be specified." ) ;
326+ }
327+
328+ [ Fact ]
329+ public async Task Should_Throw_When_Only_GithubRepo_Provided ( )
330+ {
331+ // Act & Assert
332+ var args = new DownloadLogsCommandArgs
333+ {
334+ GithubRepo = "test-repo"
335+ } ;
336+ await FluentAssertions . FluentActions
337+ . Invoking ( async ( ) => await _handler . Handle ( args ) )
338+ . Should ( ) . ThrowAsync < OctoshiftCliException > ( )
339+ . WithMessage ( "Either --migration-id (GraphQL migration ID) or both --github-org and --github-repo must be specified." ) ;
340+ }
341+
342+ [ Fact ]
343+ public async Task Should_Log_Warning_When_MigrationId_And_OrgRepo_Both_Provided ( )
344+ {
345+ // Arrange
346+ const string migrationId = "RM_test123" ;
347+ const string githubOrg = "test-org" ;
348+ const string githubRepo = "test-repo" ;
349+ const string logUrl = "some-url" ;
350+ const string repoName = "test-repo-name" ;
351+
352+ _mockGithubApi . Setup ( m => m . GetMigration ( migrationId ) )
353+ . ReturnsAsync ( ( State : "SUCCEEDED" , RepositoryName : repoName , WarningsCount : 0 , FailureReason : "" , MigrationLogUrl : logUrl ) ) ;
354+ _mockHttpDownloadService . Setup ( m => m . DownloadToFile ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ) ) ;
355+
356+ // Act
357+ var args = new DownloadLogsCommandArgs
358+ {
359+ MigrationId = migrationId ,
360+ GithubOrg = githubOrg ,
361+ GithubRepo = githubRepo
362+ } ;
363+ await _handler . Handle ( args ) ;
364+
365+ // Assert
366+ _mockLogger . Verify ( m => m . LogWarning ( "--github-org and --github-repo are ignored when --migration-id is specified." ) , Times . Once ) ;
367+ _mockGithubApi . Verify ( m => m . GetMigration ( migrationId ) , Times . Once ) ;
368+ _mockGithubApi . Verify ( m => m . GetMigrationLogUrl ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ) , Times . Never ) ;
369+ }
370+
371+ [ Fact ]
372+ public async Task Should_Succeed_When_Only_MigrationId_Provided ( )
373+ {
374+ // Arrange
375+ const string migrationId = "RM_test123" ;
376+ const string logUrl = "some-url" ;
377+ const string repoName = "test-repo-name" ;
378+ const string expectedFileName = $ "migration-log-{ repoName } -{ migrationId } .log";
379+
380+ _mockGithubApi . Setup ( m => m . GetMigration ( migrationId ) )
381+ . ReturnsAsync ( ( State : "SUCCEEDED" , RepositoryName : repoName , WarningsCount : 0 , FailureReason : "" , MigrationLogUrl : logUrl ) ) ;
382+ _mockHttpDownloadService . Setup ( m => m . DownloadToFile ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ) ) ;
383+
384+ // Act
385+ var args = new DownloadLogsCommandArgs
386+ {
387+ MigrationId = migrationId
388+ } ;
389+ await _handler . Handle ( args ) ;
390+
391+ // Assert
392+ _mockGithubApi . Verify ( m => m . GetMigration ( migrationId ) , Times . Once ) ;
393+ _mockHttpDownloadService . Verify ( m => m . DownloadToFile ( logUrl , expectedFileName ) , Times . Once ) ;
394+ _mockGithubApi . Verify ( m => m . GetMigrationLogUrl ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ) , Times . Never ) ;
395+ }
396+
397+ [ Fact ]
398+ public async Task Should_Succeed_When_Only_OrgRepo_Provided ( )
399+ {
400+ // Arrange
401+ const string githubOrg = "test-org" ;
402+ const string githubRepo = "test-repo" ;
403+ const string logUrl = "some-url" ;
404+ const string migrationId = "RM_test123" ;
405+ const string expectedFileName = $ "migration-log-{ githubOrg } -{ githubRepo } -{ migrationId } .log";
406+
407+ _mockGithubApi . Setup ( m => m . GetMigrationLogUrl ( githubOrg , githubRepo ) )
408+ . ReturnsAsync ( ( logUrl , migrationId ) ) ;
409+ _mockHttpDownloadService . Setup ( m => m . DownloadToFile ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ) ) ;
410+
411+ // Act
412+ var args = new DownloadLogsCommandArgs
413+ {
414+ GithubOrg = githubOrg ,
415+ GithubRepo = githubRepo
416+ } ;
417+ await _handler . Handle ( args ) ;
418+
419+ // Assert
420+ _mockGithubApi . Verify ( m => m . GetMigrationLogUrl ( githubOrg , githubRepo ) , Times . Once ) ;
421+ _mockHttpDownloadService . Verify ( m => m . DownloadToFile ( logUrl , expectedFileName ) , Times . Once ) ;
422+ _mockGithubApi . Verify ( m => m . GetMigration ( It . IsAny < string > ( ) ) , Times . Never ) ;
423+ }
302424}
0 commit comments