-
Notifications
You must be signed in to change notification settings - Fork 227
[APIView] Identify the package type #12398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
69e3a02
update controller
helen229 d9d84b1
Update src/dotnet/APIView/APIViewWeb/LeanControllers/ReviewsControlle…
helen229 5898f7e
fix comments
helen229 d91837b
Merge branch 'gaoh/package-type' of https://github.com/Azure/azure-sd…
helen229 1f04c53
comment fix
helen229 a906109
move enum to model file
helen229 46d85e3
revert change back due to deployment issue
helen229 1ceba9f
update enum value to match SdkType
helen229 1620612
update existing review with PackageType
helen229 482772f
fix comments
helen229 c01b5b3
update enum type
helen229 cd44a31
update to JsonStringEnumConver
helen229 9073560
Add PackageType enum with centralized parsing and Unknown default
helen229 7dd92b6
change it back to null and one line
helen229 b3a9399
update expression
helen229 1c97d19
revert to StringEnumConverter
helen229 2dd4b97
modifcations after testing with mgmt
helen229 09d2eda
add tests
helen229 71b1555
update unit tests
helen229 a303298
update tests with more mocks
helen229 4b9861d
Merge remote-tracking branch 'origin' into gaoh/package-type
helen229 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
412 changes: 412 additions & 0 deletions
412
src/dotnet/APIView/APIViewUnitTests/AutoReviewControllerTests.cs
Large diffs are not rendered by default.
Oops, something went wrong.
261 changes: 261 additions & 0 deletions
261
src/dotnet/APIView/APIViewUnitTests/PullRequestsControllerTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,261 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using APIViewWeb; | ||
| using APIViewWeb.DTOs; | ||
| using APIViewWeb.Helpers; | ||
| using APIViewWeb.LeanControllers; | ||
| using APIViewWeb.Managers; | ||
| using APIViewWeb.Models; | ||
| using FluentAssertions; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.Logging; | ||
| using Moq; | ||
| using Xunit; | ||
|
|
||
| namespace APIViewUnitTests | ||
| { | ||
| public class PullRequestsControllerTests | ||
| { | ||
| private readonly Mock<ILogger<PullRequestsController>> _mockLogger; | ||
| private readonly Mock<IPullRequestManager> _mockPullRequestManager; | ||
| private readonly Mock<IConfiguration> _mockConfiguration; | ||
| private readonly List<LanguageService> _languageServices; | ||
| private readonly PullRequestsController _controller; | ||
|
|
||
| public PullRequestsControllerTests() | ||
| { | ||
| _mockLogger = new Mock<ILogger<PullRequestsController>>(); | ||
| _mockPullRequestManager = new Mock<IPullRequestManager>(); | ||
| _mockConfiguration = new Mock<IConfiguration>(); | ||
| _languageServices = new List<LanguageService>(); | ||
|
|
||
| _controller = new PullRequestsController( | ||
| _mockLogger.Object, | ||
| _mockPullRequestManager.Object, | ||
| _mockConfiguration.Object, | ||
| _languageServices); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("client")] | ||
| [InlineData("mgmt")] | ||
| [InlineData("CLIENT")] | ||
| [InlineData("MGMT")] | ||
| public async Task CreateAPIRevisionIfAPIHasChanges_WithValidPackageType_PassesCorrectValueToManager(string packageTypeValue) | ||
| { | ||
| // Arrange | ||
| _mockPullRequestManager.Setup(m => m.CreateAPIRevisionIfAPIHasChanges( | ||
| It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), | ||
| It.IsAny<string>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<CreateAPIRevisionAPIResponse>(), | ||
| It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) | ||
| .ReturnsAsync("https://test.com/review/test-id"); | ||
|
|
||
| // Setup HTTP context for Request.Host | ||
| var httpContext = new DefaultHttpContext(); | ||
| httpContext.Request.Host = new HostString("test.com"); | ||
| _controller.ControllerContext = new ControllerContext() | ||
| { | ||
| HttpContext = httpContext | ||
| }; | ||
|
|
||
| // Act | ||
| var result = await _controller.CreateAPIRevisionIfAPIHasChanges( | ||
| buildId: "test-build-id", | ||
| artifactName: "test-artifact", | ||
| filePath: "test/path", | ||
| commitSha: "abc123", | ||
| repoName: "test-repo", | ||
| packageName: "test-package", | ||
| pullRequestNumber: 123, | ||
| packageType: packageTypeValue); | ||
|
|
||
| // Assert | ||
| result.Should().NotBeNull(); | ||
|
|
||
| // Verify that the manager was called with the exact packageType value passed from controller | ||
| _mockPullRequestManager.Verify(m => m.CreateAPIRevisionIfAPIHasChanges( | ||
| "test-build-id", | ||
| "test-artifact", | ||
| "test/path", | ||
| "abc123", | ||
| "test-repo", | ||
| "test-package", | ||
| 123, | ||
| "test.com", | ||
| It.IsAny<CreateAPIRevisionAPIResponse>(), | ||
| null, // codeFile | ||
| null, // baselineCodeFile | ||
| null, // language - actual value from controller | ||
| "internal", // default project | ||
| packageTypeValue), // packageType should be passed exactly as received | ||
| Times.Once); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(null)] | ||
| [InlineData("")] | ||
| [InlineData(" ")] | ||
| [InlineData("invalid")] | ||
| [InlineData("unknown")] | ||
| public async Task CreateAPIRevisionIfAPIHasChanges_WithInvalidPackageType_PassesValueToManager(string packageTypeValue) | ||
| { | ||
| // Arrange | ||
| _mockPullRequestManager.Setup(m => m.CreateAPIRevisionIfAPIHasChanges( | ||
| It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), | ||
| It.IsAny<string>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<CreateAPIRevisionAPIResponse>(), | ||
| It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) | ||
| .ReturnsAsync("https://test.com/review/test-id"); | ||
|
|
||
| // Setup HTTP context for Request.Host | ||
| var httpContext = new DefaultHttpContext(); | ||
| httpContext.Request.Host = new HostString("test.com"); | ||
| _controller.ControllerContext = new ControllerContext() | ||
| { | ||
| HttpContext = httpContext | ||
| }; | ||
|
|
||
| // Act | ||
| var result = await _controller.CreateAPIRevisionIfAPIHasChanges( | ||
| buildId: "test-build-id", | ||
| artifactName: "test-artifact", | ||
| filePath: "test/path", | ||
| commitSha: "abc123", | ||
| repoName: "test-repo", | ||
| packageName: "test-package", | ||
| pullRequestNumber: 123, | ||
| packageType: packageTypeValue); | ||
|
|
||
| // Assert | ||
| result.Should().NotBeNull(); | ||
|
|
||
| // Verify that the manager was called with the exact packageType value (even if invalid) | ||
| _mockPullRequestManager.Verify(m => m.CreateAPIRevisionIfAPIHasChanges( | ||
| "test-build-id", | ||
| "test-artifact", | ||
| "test/path", | ||
| "abc123", | ||
| "test-repo", | ||
| "test-package", | ||
| 123, | ||
| "test.com", | ||
| It.IsAny<CreateAPIRevisionAPIResponse>(), | ||
| null, // codeFile | ||
| null, // baselineCodeFile | ||
| null, // language - actual value from controller | ||
| "internal", // default project | ||
| packageTypeValue), // packageType should be passed exactly as received (even invalid values) | ||
| Times.Once); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CreateAPIRevisionIfAPIHasChanges_WhenPackageTypeOmitted_PassesNullToManager() | ||
| { | ||
| // Arrange | ||
| _mockPullRequestManager.Setup(m => m.CreateAPIRevisionIfAPIHasChanges( | ||
| It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), | ||
| It.IsAny<string>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<CreateAPIRevisionAPIResponse>(), | ||
| It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) | ||
| .ReturnsAsync("https://test.com/review/test-id"); | ||
|
|
||
| // Setup HTTP context for Request.Host | ||
| var httpContext = new DefaultHttpContext(); | ||
| httpContext.Request.Host = new HostString("test.com"); | ||
| _controller.ControllerContext = new ControllerContext() | ||
| { | ||
| HttpContext = httpContext | ||
| }; | ||
|
|
||
| // Act - Not providing packageType parameter to test default behavior | ||
| var result = await _controller.CreateAPIRevisionIfAPIHasChanges( | ||
| buildId: "test-build-id", | ||
| artifactName: "test-artifact", | ||
| filePath: "test/path", | ||
| commitSha: "abc123", | ||
| repoName: "test-repo", | ||
| packageName: "test-package", | ||
| pullRequestNumber: 123); | ||
| // packageType parameter omitted | ||
|
|
||
| // Assert | ||
| result.Should().NotBeNull(); | ||
|
|
||
| // Verify that the manager was called with null packageType when omitted | ||
| _mockPullRequestManager.Verify(m => m.CreateAPIRevisionIfAPIHasChanges( | ||
| "test-build-id", | ||
| "test-artifact", | ||
| "test/path", | ||
| "abc123", | ||
| "test-repo", | ||
| "test-package", | ||
| 123, | ||
| "test.com", | ||
| It.IsAny<CreateAPIRevisionAPIResponse>(), | ||
| null, // codeFile | ||
| null, // baselineCodeFile | ||
| null, // language - actual value from controller | ||
| "internal", // default project | ||
| null), // packageType should be null when omitted | ||
| Times.Once); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CreateAPIRevisionIfAPIHasChanges_WhenNoAPIRevisionUrlReturned_ReturnsAlreadyReported() | ||
| { | ||
| // Arrange - Manager returns null/empty URL indicating no changes | ||
| _mockPullRequestManager.Setup(m => m.CreateAPIRevisionIfAPIHasChanges( | ||
| It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), | ||
| It.IsAny<string>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<CreateAPIRevisionAPIResponse>(), | ||
| It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) | ||
| .ReturnsAsync((string)null); // No API revision URL returned | ||
|
|
||
| // Setup HTTP context for Request.Host | ||
| var httpContext = new DefaultHttpContext(); | ||
| httpContext.Request.Host = new HostString("test.com"); | ||
| _controller.ControllerContext = new ControllerContext() | ||
| { | ||
| HttpContext = httpContext | ||
| }; | ||
|
|
||
| // Act | ||
| var result = await _controller.CreateAPIRevisionIfAPIHasChanges( | ||
| buildId: "test-build-id", | ||
| artifactName: "test-artifact", | ||
| filePath: "test/path", | ||
| commitSha: "abc123", | ||
| repoName: "test-repo", | ||
| packageName: "test-package", | ||
| pullRequestNumber: 123, | ||
| packageType: "client"); | ||
|
|
||
| // Assert | ||
| result.Should().NotBeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetAssociatedPullRequestsAsync_ReturnsExpectedResult() | ||
| { | ||
| // Arrange | ||
| var reviewId = "test-review-id"; | ||
| var apiRevisionId = "test-revision-id"; | ||
| var expectedPullRequests = new List<PullRequestModel> | ||
| { | ||
| new PullRequestModel { ReviewId = reviewId, PullRequestNumber = 123 }, | ||
| new PullRequestModel { ReviewId = reviewId, PullRequestNumber = 456 } | ||
| }; | ||
|
|
||
| _mockPullRequestManager.Setup(m => m.GetPullRequestsModelAsync(reviewId, apiRevisionId)) | ||
| .ReturnsAsync(expectedPullRequests); | ||
|
|
||
| // Act | ||
| var result = await _controller.GetAssociatedPullRequestsAsync(reviewId, apiRevisionId); | ||
|
|
||
| // Assert | ||
| result.Should().NotBeNull(); | ||
|
|
||
| _mockPullRequestManager.Verify(m => m.GetPullRequestsModelAsync(reviewId, apiRevisionId), Times.Once); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.