Skip to content

Commit

Permalink
test: add login controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mobinbr committed Aug 20, 2024
1 parent de982fb commit 3176dd2
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/Web.UnitTests/Controllers/IdentityControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,35 @@ public async Task Signup_WhenSignUpSucceeds_ReturnsOkResult()
Assert.Equal("MobinBarfi", responseValue.UserName);
Assert.Equal("Admin", responseValue.Role);
}

// Login Tests
[Fact]
public async Task Login_WhenLoginSucceeds_ReturnsOkResult()
{
// Arrange
var loginDto = new LoginDto
{
UserName = "MobinBarfi",
Password = "Abc@1234"
};

var mockResponse = new LoginUserResponse
{
UserName = "MobinBarfi",
Token = "FakeToken"
};

_identityServiceMock
.Login(Arg.Any<LoginUserRequest>())
.Returns(Result<LoginUserResponse>.Ok(mockResponse));

// Act
var result = await _controller.Login(loginDto);

// Assert
var okResult = Assert.IsType<OkObjectResult>(result);
var response = Assert.IsType<UserLoggedInDto>(okResult.Value);
Assert.Equal("MobinBarfi", response.UserName);
Assert.Equal("FakeToken", response.Token);
}
}

0 comments on commit 3176dd2

Please sign in to comment.