Add unit tests for CheckToken
This commit is contained in:
parent
86fbe4d2da
commit
47d7706cd2
2 changed files with 47 additions and 6 deletions
|
@ -172,5 +172,47 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
|||
Assert.IsType<BadRequestObjectResult>(result);
|
||||
tokens.Verify(i => i.FindAsync(It.IsAny<TokenListFilters>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test_CheckToken_NotFound()
|
||||
{
|
||||
// Arrange
|
||||
var mapper = TestUtils.GetMapper();
|
||||
var feedbackService = new Mock<IFeedbackReceiversService>();
|
||||
var tokens = new Mock<ITokensService>();
|
||||
var logger = new Mock<ILogger<TokensController>>();
|
||||
tokens.Setup(i => i.FindAsync(It.IsAny<TokenListFilters>()))
|
||||
.ReturnsAsync(new List<Token>());
|
||||
|
||||
// Test
|
||||
var controller = new TokensController(feedbackService.Object, tokens.Object, logger.Object, mapper);
|
||||
var result = await controller.CheckToken("random");
|
||||
|
||||
// Assert
|
||||
var checkResult = (CheckTokenDto) ((ObjectResult) result).Value;
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
Assert.False(checkResult.IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test_CheckToken_Valid()
|
||||
{
|
||||
// Arrange
|
||||
var mapper = TestUtils.GetMapper();
|
||||
var feedbackService = new Mock<IFeedbackReceiversService>();
|
||||
var tokens = new Mock<ITokensService>();
|
||||
var logger = new Mock<ILogger<TokensController>>();
|
||||
tokens.Setup(i => i.FindAsync(It.IsAny<TokenListFilters>()))
|
||||
.ReturnsAsync(new List<Token> { new Token() });
|
||||
|
||||
// Test
|
||||
var controller = new TokensController(feedbackService.Object, tokens.Object, logger.Object, mapper);
|
||||
var result = await controller.CheckToken("random");
|
||||
|
||||
// Assert
|
||||
var checkResult = (CheckTokenDto) ((ObjectResult) result).Value;
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
Assert.True(checkResult.IsValid);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -160,13 +160,12 @@ namespace Retroactiune.Controllers
|
|||
string guid
|
||||
)
|
||||
{
|
||||
// TODO: Unit test.
|
||||
var response = await _tokensService.FindAsync(new TokenListFilters
|
||||
{
|
||||
Ids = new[] {guid}
|
||||
});
|
||||
try
|
||||
{
|
||||
var response = await _tokensService.FindAsync(new TokenListFilters
|
||||
{
|
||||
Ids = new[] {guid}
|
||||
});
|
||||
var token = response.ElementAt(0);
|
||||
return Ok(new CheckTokenDto
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue