diff --git a/src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs b/src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs index c6dc28a..bb1919a 100644 --- a/src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs +++ b/src/Stack.Tests/Commands/Stack/StackStatusCommandHandlerTests.cs @@ -217,6 +217,82 @@ public async Task WhenAllStacksAreRequested_ReturnsStatusOfEachStack() }); } + [Fact] + public async Task WhenAllStacksAreRequested_WithStacksInMultipleRepositories_ReturnsStatusOfEachStackInTheCorrectRepository() + { + // Arrange + var gitOperations = Substitute.For(); + var gitHubOperations = Substitute.For(); + var stackConfig = Substitute.For(); + var inputProvider = Substitute.For(); + var outputProvider = Substitute.For(); + var handler = new StackStatusCommandHandler(inputProvider, outputProvider, gitOperations, gitHubOperations, stackConfig); + + var remoteUri = Some.HttpsUri().ToString(); + + gitOperations.GetRemoteUri().Returns(remoteUri); + gitOperations.GetCurrentBranch().Returns("branch-1"); + + var stack1 = new Config.Stack("Stack1", remoteUri, "branch-1", ["branch-3", "branch-5"]); + var stack2 = new Config.Stack("Stack2", remoteUri, "branch-2", ["branch-4"]); + var stack3 = new Config.Stack("Stack2", Some.HttpsUri().ToString(), "branch-6", ["branch-7"]); + var stacks = new List([stack1, stack2]); + stackConfig.Load().Returns(stacks); + + outputProvider + .WhenForAnyArgs(o => o.Status(Arg.Any(), Arg.Any())) + .Do(ci => ci.ArgAt(1)()); + + gitOperations + .GetBranchesThatExistInRemote(Arg.Any()) + .Returns(["branch-1", "branch-2", "branch-3", "branch-4", "branch-5"]); + + gitOperations + .GetBranchesThatExistLocally(Arg.Any()) + .Returns(["branch-1", "branch-2", "branch-3", "branch-4", "branch-5"]); + + gitOperations + .GetStatusOfRemoteBranch("branch-3", "branch-1") + .Returns((10, 5)); + + gitOperations + .GetStatusOfRemoteBranch("branch-5", "branch-3") + .Returns((1, 0)); + + gitOperations + .GetStatusOfRemoteBranch("branch-4", "branch-2") + .Returns((3, 1)); + + var pr = new GitHubPullRequest(1, "PR title", "PR body", GitHubPullRequestStates.Open, Some.HttpsUri()); + + gitHubOperations + .GetPullRequest("branch-3") + .Returns(pr); + + // Act + var response = await handler.Handle(new StackStatusCommandInputs(null, true)); + + // Assert + var expectedBranchDetailsForStack1 = new Dictionary + { + { "branch-3", new BranchDetail { Status = new BranchStatus(true, true, 10, 5), PullRequest = pr } }, + { "branch-5", new BranchDetail { Status = new BranchStatus(true, true, 1, 0) } } + }; + var expectedBranchDetailsForStack2 = new Dictionary + { + { "branch-4", new BranchDetail { Status = new BranchStatus(true, true, 3, 1) } } + }; + response.Statuses.Should().BeEquivalentTo(new Dictionary + { + { + stack1, new(expectedBranchDetailsForStack1) + }, + { + stack2, new(expectedBranchDetailsForStack2) + } + }); + } + [Fact] public async Task WhenStackNameIsProvided_ButStackDoesNotExist_Throws() { diff --git a/src/Stack/Commands/Stack/StackStatusCommand.cs b/src/Stack/Commands/Stack/StackStatusCommand.cs index 470c77e..e5e1e88 100644 --- a/src/Stack/Commands/Stack/StackStatusCommand.cs +++ b/src/Stack/Commands/Stack/StackStatusCommand.cs @@ -61,7 +61,7 @@ public async Task Handle(StackStatusCommandInputs in if (inputs.All) { - stacksToCheckStatusFor.AddRange(stacks); + stacksToCheckStatusFor.AddRange(stacksForRemote); } else {