-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: Changing logic to the use case
- Loading branch information
Showing
12 changed files
with
246 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...eycloak.TokenManager/TokenManager.Application.Services/Requests/User/AttributesRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace TokenManager.Application.Services.Requests.User | ||
{ | ||
public record AttributesRequest(string? Tenant, string? ZoneInfo, string? Birthdate, string? PhoneNumber, string? Gender, string? Fullname, string? Picture); | ||
public record AttributesRequest(string Tenant, Dictionary<string, string> UserAttributes); | ||
} |
9 changes: 2 additions & 7 deletions
9
src/Feijuca.Keycloak.TokenManager/TokenManager.Domain/Entities/Attributes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
namespace TokenManager.Domain.Entities | ||
{ | ||
public class Attributes(string? Zoneinfo, string? Birthdate, string? PhoneNumber, string? Gender, string? Fullname, string? Tenant, string? Picture) | ||
public class Attributes(string Tenant, Dictionary<string, string> UserAttributes) | ||
{ | ||
public string? Zoneinfo { get; set; } = Zoneinfo; | ||
public string? Birthdate { get; set; } = Birthdate; | ||
public string? PhoneNumber { get; set; } = PhoneNumber; | ||
public string? Gender { get; set; } = Gender; | ||
public string? Fullname { get; set; } = Fullname; | ||
public Dictionary<string, string> UserAttributes = UserAttributes; | ||
public string? Tenant { get; set; } = Tenant; | ||
public string? Picture { get; set; } = Picture; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
...Keycloak.TokenManager/TokenManager.Infra.CrossCutting/Extensions/RepositoriesExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
tests/TokenManager.UnitTests/Handlers/CreateUserCommandHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using AutoFixture; | ||
using Contracts.Common; | ||
using FluentAssertions; | ||
using Moq; | ||
using TokenManager.Application.Services.Commands.Users; | ||
using TokenManager.Domain.Entities; | ||
using TokenManager.Domain.Errors; | ||
using TokenManager.Domain.Interfaces; | ||
|
||
namespace TokenManager.UnitTests.Handlers | ||
{ | ||
public class CreateUserCommandHandlerTests | ||
{ | ||
private readonly Fixture _autoFixture = new(); | ||
private readonly Mock<IUserRepository> _userRepositoryMock = new(); | ||
private readonly CreateUserCommandHandler _createUserCommandHandler; | ||
|
||
public CreateUserCommandHandlerTests() | ||
{ | ||
_createUserCommandHandler = new(_userRepositoryMock.Object); | ||
} | ||
|
||
[Fact] | ||
public async Task HandleWhenInformAValidUser_ShouldCreateANewUserAndReturnsTrue() | ||
{ | ||
// Arrange | ||
var createUserCommand = _autoFixture.Create<CreateUserCommand>(); | ||
var tokenDetails = _autoFixture.Create<TokenDetails>(); | ||
var successResult = Result<TokenDetails>.Success(tokenDetails); | ||
|
||
_userRepositoryMock | ||
.Setup(x => x.GetAccessTokenAsync(It.IsAny<string>())) | ||
.ReturnsAsync(successResult); | ||
|
||
(bool result, string content) createUserResult = (true, "Success message"); | ||
|
||
_userRepositoryMock | ||
.Setup(x => x.CreateNewUserAsync(It.IsAny<User>())) | ||
.ReturnsAsync(createUserResult); | ||
|
||
var user = _autoFixture.Create<User>(); | ||
var userResult = Result<User>.Success(user); | ||
|
||
_userRepositoryMock | ||
.Setup(x => x.GetUserAsync(It.IsAny<string>())) | ||
.ReturnsAsync(userResult); | ||
|
||
_userRepositoryMock | ||
.Setup(x => x.ResetPasswordAsync(It.IsAny<string>(), It.IsAny<string>())) | ||
.ReturnsAsync(userResult); | ||
|
||
//Act | ||
var resultHandle = await _createUserCommandHandler.Handle(createUserCommand, CancellationToken.None); | ||
|
||
//Assert | ||
_userRepositoryMock | ||
.Verify(x => x.GetAccessTokenAsync(It.IsAny<string>()), Times.Once); | ||
|
||
resultHandle.IsSuccess | ||
.Should() | ||
.Be(true); | ||
} | ||
|
||
[Fact] | ||
public async Task HandleWhenInformAInvalidUser_ShouldNotCreateANewUserAndReturnsFalse() | ||
{ | ||
// Arrange | ||
var createUserCommand = _autoFixture.Create<CreateUserCommand>(); | ||
|
||
var errorMessage = _autoFixture.Create<string>(); | ||
UserErrors.SetTechnicalMessage(errorMessage); | ||
var result = Result.Failure(UserErrors.TokenGenerationError); | ||
|
||
_userRepositoryMock | ||
.Setup(x => x.GetAccessTokenAsync(It.IsAny<string>()), Times.Once) | ||
.ReturnsAsync(result); | ||
|
||
//Act | ||
var resultHandle = await _createUserCommandHandler.Handle(createUserCommand, CancellationToken.None); | ||
|
||
//Assert | ||
resultHandle.IsSuccess | ||
.Should() | ||
.Be(false); | ||
|
||
resultHandle.Error.Description | ||
.Should() | ||
.Contain(result.Error.Description); | ||
|
||
resultHandle.Error.Code | ||
.Should() | ||
.Contain(result.Error.Code); | ||
} | ||
} | ||
} |
Oops, something went wrong.