mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-04-06 02:19:05 +00:00
test: implement BDD step definitions for token validation and confirmation
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user