refactor: address code review findings across all projects
Apply comprehensive fixes from code reviews including: - Extract shared utilities (SqlFormatHelper, CellValueConverter, DbDestinationBase) - Add interface abstractions (IAuthenticationService, IDatabaseMigrator, IMisQueryBuilder) - Implement SecureStore for encrypted secrets storage - Fix error handling with proper HTTP status codes and logging - Optimize double enumeration in DevEtlRegistry - Add DataSync.Dev README for developer onboarding - Extract filter panel base classes to reduce duplication - Update code review docs to mark all issues as fixed
This commit is contained in:
@@ -14,6 +14,11 @@ using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using Shouldly;
|
||||
|
||||
// Alias to avoid conflict with JdeScoping.Core.Interfaces.IAuthenticationService
|
||||
using IAspNetAuthService = Microsoft.AspNetCore.Authentication.IAuthenticationService;
|
||||
// Alias to match AuthController naming convention
|
||||
using IAuthService = JdeScoping.Core.Interfaces.IAuthenticationService;
|
||||
|
||||
namespace JdeScoping.Api.Tests.Controllers;
|
||||
|
||||
public class AuthControllerTests
|
||||
@@ -186,14 +191,14 @@ public class AuthControllerTests
|
||||
|
||||
private static HttpContext CreateMockHttpContext()
|
||||
{
|
||||
var authServiceMock = Substitute.For<IAuthenticationService>();
|
||||
var authServiceMock = Substitute.For<IAspNetAuthService>();
|
||||
authServiceMock.SignOutAsync(Arg.Any<HttpContext>(), Arg.Any<string>(), Arg.Any<AuthenticationProperties>())
|
||||
.Returns(Task.CompletedTask);
|
||||
authServiceMock.SignInAsync(Arg.Any<HttpContext>(), Arg.Any<string>(), Arg.Any<ClaimsPrincipal>(), Arg.Any<AuthenticationProperties>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var serviceProvider = Substitute.For<IServiceProvider>();
|
||||
serviceProvider.GetService(typeof(IAuthenticationService)).Returns(authServiceMock);
|
||||
serviceProvider.GetService(typeof(IAspNetAuthService)).Returns(authServiceMock);
|
||||
|
||||
var httpContext = new DefaultHttpContext
|
||||
{
|
||||
|
||||
@@ -77,15 +77,15 @@ public class FileControllerTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UploadWorkOrders_NoFile_ReturnsError()
|
||||
public async Task UploadWorkOrders_NoFile_ReturnsBadRequest()
|
||||
{
|
||||
// Act
|
||||
var result = await _controller.UploadWorkOrders(null, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.Result.ShouldBeOfType<OkObjectResult>();
|
||||
var okResult = (OkObjectResult)result.Result!;
|
||||
var uploadResult = okResult.Value.ShouldBeOfType<FileUploadResult<WorkOrderViewModel>>();
|
||||
// Assert - should return BadRequest for validation errors, not 200 OK
|
||||
result.Result.ShouldBeOfType<BadRequestObjectResult>();
|
||||
var badRequestResult = (BadRequestObjectResult)result.Result!;
|
||||
var uploadResult = badRequestResult.Value.ShouldBeOfType<FileUploadResult<WorkOrderViewModel>>();
|
||||
uploadResult.WasSuccessful.ShouldBeFalse();
|
||||
uploadResult.ErrorMessage.ShouldBe("No file uploaded");
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ public class SearchControllerTests
|
||||
private readonly ILotFinderRepository _repository;
|
||||
private readonly IHubContext<StatusHub> _hubContext;
|
||||
private readonly ILogger<SearchController> _logger;
|
||||
private readonly TimeProvider _timeProvider;
|
||||
private readonly SearchController _controller;
|
||||
|
||||
public SearchControllerTests()
|
||||
@@ -27,7 +28,8 @@ public class SearchControllerTests
|
||||
_repository = Substitute.For<ILotFinderRepository>();
|
||||
_hubContext = Substitute.For<IHubContext<StatusHub>>();
|
||||
_logger = Substitute.For<ILogger<SearchController>>();
|
||||
_controller = new SearchController(_repository, _hubContext, _logger);
|
||||
_timeProvider = TimeProvider.System;
|
||||
_controller = new SearchController(_repository, _hubContext, _logger, _timeProvider);
|
||||
SetupAuthenticatedUser("testuser");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user