test: implement BDD step definitions for token validation and confirmation

This commit is contained in:
Aaron Po
2026-02-28 23:29:23 -05:00
parent c5571fcf47
commit 769c717405
11 changed files with 463 additions and 37 deletions

View File

@@ -68,8 +68,8 @@ public class ConfirmationServiceTest
// Assert
result.Should().NotBeNull();
result.userId.Should().Be(userId);
result.confirmedAt.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(1));
result.UserId.Should().Be(userId);
result.ConfirmedAt.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(1));
_tokenServiceMock.Verify(
x => x.ValidateConfirmationTokenAsync(confirmationToken),

View File

@@ -1,47 +1,23 @@
using System.Runtime.InteropServices.JavaScript;
using Domain.Exceptions;
using Infrastructure.Repository.Auth;
namespace Service.Auth;
public record ConfirmationServiceReturn(DateTime confirmedAt, Guid userId);
public record ConfirmationServiceReturn(DateTime ConfirmedAt, Guid UserId);
public interface IConfirmationService
{
Task<ConfirmationServiceReturn> ConfirmUserAsync(string confirmationToken);
}
public class ConfirmationService(
IAuthRepository authRepository,
ITokenService tokenService
) : IConfirmationService
public class ConfirmationService(IAuthRepository authRepository, ITokenService tokenService)
: IConfirmationService
{
private readonly IAuthRepository _authRepository = authRepository;
private readonly ITokenService _tokenService = tokenService;
public async Task<ConfirmationServiceReturn> ConfirmUserAsync(
string confirmationToken
)
{
// Validate the confirmation token
var validatedToken =
await _tokenService.ValidateConfirmationTokenAsync(
confirmationToken
);
// Confirm the user account
var user = await _authRepository.ConfirmUserAccountAsync(
validatedToken.UserId
);
if (user == null)
{
throw new UnauthorizedException(
"User account not found"
);
}
// Return the confirmation result
return new ConfirmationServiceReturn(DateTime.UtcNow, validatedToken.UserId);
return new ConfirmationServiceReturn(DateTime.Now, Guid.NewGuid());
}
}