small fix

This commit is contained in:
Artemy
2025-07-24 14:45:01 +07:00
parent 73f22a3ace
commit 53ea25f9fd
5 changed files with 26 additions and 23 deletions
@@ -82,21 +82,7 @@ public class FriendshipControllerTests
var badRequestResult = result as BadRequestObjectResult;
Assert.That(badRequestResult.Value, Is.EqualTo("Query cannot be empty"));
}
[Test]
public async Task Search_NotFound_IfThrowsSearchUsersException()
{
// Arrange
_friendsServiceMock.Setup(f => f.SearchUsersAsync(It.IsAny<string>(), It.IsAny<Guid>()))
.ThrowsAsync(new SearchUsersException(_fixture.Create<string>()));
// Act
var result = await _controller.Search(_fixture.Create<string>());
// Assert
Assert.That(result, Is.InstanceOf<NotFoundObjectResult>());
}
[Test]
public async Task Search_StatusCode500_IfThrowsSomeException()
{
@@ -36,7 +36,7 @@ public class FriendsRequestQueryController : Controller
{
var result = await _friendsService.GetIncomingAsync(_currentUserService.GetCurrentUserId());
var response = _mapper.Map<List<FriendshipDto>>(result);
return Ok(response);
}
catch (InvalidOperationException ex)
@@ -44,6 +44,11 @@ public class FriendsRequestQueryController : Controller
_logger.LogWarning(ex, ex.Message);
return Ok(new List<FriendshipDto>());
}
catch (UnauthorizedAccessException ex)
{
_logger.LogWarning(ex, ex.Message);
return Forbid(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
@@ -70,6 +75,11 @@ public class FriendsRequestQueryController : Controller
_logger.LogWarning(ex, ex.Message);
return Ok(new List<FriendshipDto>());
}
catch (UnauthorizedAccessException ex)
{
_logger.LogWarning(ex, ex.Message);
return Forbid(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
@@ -41,10 +41,10 @@ public class FriendshipController : Controller
return Ok(response);
}
catch (SearchUsersException ex)
catch (UnauthorizedAccessException ex)
{
_logger.LogWarning(ex, ex.Message);
return NotFound(new { error = ex.Message });
return Forbid(ex.Message);
}
catch (Exception ex)
{
@@ -69,6 +69,11 @@ public class FriendshipController : Controller
_logger.LogError(ex, ex.Message);
return Ok(Array.Empty<UserDto>());
}
catch (UnauthorizedAccessException ex)
{
_logger.LogWarning(ex, ex.Message);
return Forbid(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
@@ -61,15 +61,18 @@ public class FriendshipServiceTests
}
[Test]
public void SearchUsersAsync_Throws_SearchUsersException_IfThrowsNotFoundByKeyException_String_Guid()
public async Task SearchUsersAsync_Returns_EmptyList_IfThrowsNotFoundByKeyException_String_Guid()
{
// Arrange
_usersRepositoryMock
.Setup(u => u.SearchPotentialFriendsAsync(It.IsAny<Guid>(), It.IsAny<string>()))
.ThrowsAsync(new NotFoundByKeyException<(string,Guid)>(("test",Guid.NewGuid()),"test"));
// Axt & Assert
Assert.ThrowsAsync<SearchUsersException>(async () => await _service.SearchUsersAsync("test", Guid.NewGuid()));
// Act
var users = await _service.SearchUsersAsync("test", Guid.NewGuid());
// & Assert
Assert.That(users, Is.Empty);
}
[Test]
@@ -33,8 +33,7 @@ public class FriendshipService : IFriendshipService
}
catch (NotFoundByKeyException<(string, Guid)> ex)
{
throw new SearchUsersException(
$"Users with given query: \"{query}\" for user with id {currentId} was not found", ex);
return [];
}
catch (NotFoundByKeyException<Guid> ex)
{