83 lines
2.0 KiB
C#
83 lines
2.0 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using FluentAssertions;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Xunit;
|
|
|
|
namespace SocialService.FunctionalTests.Controllers;
|
|
|
|
/// <summary>
|
|
/// EN: Functional tests for Relationships API endpoints.
|
|
/// VI: Functional tests cho các endpoints API Relationships.
|
|
/// </summary>
|
|
public class RelationshipsControllerTests : IClassFixture<CustomWebApplicationFactory>
|
|
{
|
|
private readonly HttpClient _client;
|
|
|
|
public RelationshipsControllerTests(CustomWebApplicationFactory factory)
|
|
{
|
|
_client = factory.CreateClient(new WebApplicationFactoryClientOptions
|
|
{
|
|
AllowAutoRedirect = false
|
|
});
|
|
}
|
|
|
|
#region Get Endpoints Tests
|
|
|
|
[Fact]
|
|
public async Task GetFriends_ValidUser_ReturnsOk()
|
|
{
|
|
// Arrange
|
|
var userId = Guid.NewGuid();
|
|
|
|
// Act
|
|
var response = await _client.GetAsync($"/api/v1/relationships/users/{userId}/friends");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetMutualFriends_ValidUsers_ReturnsOk()
|
|
{
|
|
// Arrange
|
|
var userId1 = Guid.NewGuid();
|
|
var userId2 = Guid.NewGuid();
|
|
|
|
// Act
|
|
var response = await _client.GetAsync($"/api/v1/relationships/users/{userId1}/mutual-friends/{userId2}");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetFriendSuggestions_ValidUser_ReturnsOk()
|
|
{
|
|
// Arrange
|
|
var userId = Guid.NewGuid();
|
|
|
|
// Act
|
|
var response = await _client.GetAsync($"/api/v1/relationships/users/{userId}/suggestions");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Health Check Tests
|
|
|
|
[Fact]
|
|
public async Task HealthCheck_Live_ReturnsHealthy()
|
|
{
|
|
// Act
|
|
var response = await _client.GetAsync("/health/live");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
}
|
|
|
|
#endregion
|
|
}
|