Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions PathfinderHonorManager.Tests/Validator/PathfinderValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,90 @@ public async Task Validate_AllRulesApplied_ValidationError()
validationResult.ShouldHaveValidationErrorFor(p => p.ClubID);
}

[Test]
public async Task Validate_InvalidClubId_ValidationError()
{
using (var context = new PathfinderContext(ContextOptions))
{
var newPathfinder = new Incoming.PathfinderDtoInternal
{
FirstName = "Test",
LastName = "User",
Email = "test@example.com",
ClubID = Guid.NewGuid()
};

var validationResult = await _pathfinderValidator
.TestValidateAsync(newPathfinder, options => options.IncludeRuleSets("update"));

validationResult.ShouldHaveValidationErrorFor(p => p.ClubID)
.WithErrorMessage("New club ID must be valid if provided");
}
}

[Test]
public async Task Validate_ValidClubIdInUpdate_ShouldPass()
{
using (var context = new PathfinderContext(ContextOptions))
{
var club = new Club
{
ClubID = Guid.NewGuid(),
Name = "Test Club",
ClubCode = "TEST"
};
await context.Clubs.AddAsync(club);
await context.SaveChangesAsync();

var newPathfinder = new Incoming.PathfinderDtoInternal
{
FirstName = "Test",
LastName = "User",
Email = "test@example.com",
ClubID = club.ClubID
};

var validationResult = await _pathfinderValidator
.TestValidateAsync(newPathfinder, options => options.IncludeRuleSets("update"));

validationResult.ShouldNotHaveValidationErrorFor(p => p.ClubID);
}
}

[Test]
public async Task Validate_NullClubId_ShouldPass()
{
var newPathfinder = new Incoming.PathfinderDtoInternal
{
FirstName = "Test",
LastName = "User",
Email = "test@example.com",
ClubID = null
};

var validationResult = await _pathfinderValidator
.TestValidateAsync(newPathfinder, options => options.IncludeRuleSets("update"));

validationResult.ShouldNotHaveValidationErrorFor(p => p.ClubID);
}

[Test]
public async Task Validate_EmptyGuidClubId_ShouldPass()
{
var newPathfinder = new Incoming.PathfinderDtoInternal
{
FirstName = "Test",
LastName = "User",
Email = "test@example.com",
ClubID = Guid.Empty
};

var validationResult = await _pathfinderValidator
.TestValidateAsync(newPathfinder, options => options.IncludeRuleSets("update"));

validationResult.ShouldNotHaveValidationErrorFor(p => p.ClubID);
}

public static void SeedDatabase(PathfinderContext context)
{
context.Database.EnsureDeleted();
Expand Down
5 changes: 1 addition & 4 deletions PathfinderHonorManager/Controllers/ClubController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ public class ClubsController : CustomApiController
{
private readonly IClubService _clubService;
private readonly ILogger<ClubsController> _logger;
private readonly IValidator<ClubDto> _validator;

public ClubsController(
IClubService clubService,
ILogger<ClubsController> logger,
IValidator<ClubDto> validator)
ILogger<ClubsController> logger)
{
_clubService = clubService;
_logger = logger;
_validator = validator;
}

// GET Clubs
Expand Down
6 changes: 3 additions & 3 deletions PathfinderHonorManager/Service/PathfinderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ await _validator.ValidateAsync(
catch (Exception ex)
{
_logger.LogError(ex, "Error adding pathfinder for club {ClubCode}", clubCode);
throw;
throw new InvalidOperationException($"Failed to add pathfinder for club {clubCode}", ex);
}
}

Expand Down Expand Up @@ -205,7 +205,7 @@ await _validator.ValidateAsync(
catch (Exception ex)
{
_logger.LogError(ex, "Error updating pathfinder with ID {PathfinderId} for club {ClubCode}", pathfinderId, clubCode);
throw;
throw new InvalidOperationException($"Failed to update pathfinder {pathfinderId} for club {clubCode}", ex);
}
}

Expand Down Expand Up @@ -253,7 +253,7 @@ await _validator.ValidateAsync(
catch (Exception ex)
{
_logger.LogError(ex, "Error updating pathfinder with ID {PathfinderId} during bulk update for club {ClubCode}", item.PathfinderId, clubCode);
throw;
throw new InvalidOperationException($"Failed to update pathfinder {item.PathfinderId} during bulk update for club {clubCode}", ex);
}
}
}
Expand Down
Loading