Add settings endpoints and registration status check: implement new API endpoints for settings management, including registration status retrieval, and update the registration command handler to enforce registration rules based on site settings.
This commit is contained in:
@@ -13,9 +13,15 @@ public class RegisterCommandHandlerTests
|
||||
private readonly IJwtTokenService _jwtTokenService = Substitute.For<IJwtTokenService>();
|
||||
private readonly IRefreshTokenService _refreshTokenService =
|
||||
Substitute.For<IRefreshTokenService>();
|
||||
private readonly ISiteSettings _siteSettings = Substitute.For<ISiteSettings>();
|
||||
|
||||
public RegisterCommandHandlerTests()
|
||||
{
|
||||
_siteSettings.IsRegistrationEnabledAsync(Arg.Any<CancellationToken>()).Returns(true);
|
||||
}
|
||||
|
||||
private RegisterCommandHandler CreateHandler() =>
|
||||
new(_identityService, _jwtTokenService, _refreshTokenService);
|
||||
new(_identityService, _jwtTokenService, _refreshTokenService, _siteSettings);
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WithNewUserName_CreatesUserAndReturnsAuthResult()
|
||||
@@ -41,6 +47,21 @@ public class RegisterCommandHandlerTests
|
||||
Assert.Equal("bob", result.Value.User.UserName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenRegistrationDisabled_ReturnsForbidden()
|
||||
{
|
||||
_siteSettings.IsRegistrationEnabledAsync(Arg.Any<CancellationToken>()).Returns(false);
|
||||
|
||||
var result = await CreateHandler()
|
||||
.Handle(new RegisterCommand("bob", "password123"), CancellationToken.None);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(AuthErrors.RegistrationDisabled, result.Error);
|
||||
await _identityService
|
||||
.DidNotReceive()
|
||||
.CreateUserAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WithTakenUserName_ReturnsFailure()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user