115 lines
2.7 KiB
C#
115 lines
2.7 KiB
C#
using System.Net;
|
|
using FluentAssertions;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Xunit;
|
|
|
|
namespace SocialService.FunctionalTests.Controllers;
|
|
|
|
/// <summary>
|
|
/// EN: Functional tests for Admin API endpoints.
|
|
/// VI: Functional tests cho các endpoints Admin API.
|
|
/// </summary>
|
|
public class AdminControllerTests : IClassFixture<CustomWebApplicationFactory>
|
|
{
|
|
private readonly HttpClient _client;
|
|
|
|
public AdminControllerTests(CustomWebApplicationFactory factory)
|
|
{
|
|
_client = factory.CreateClient(new WebApplicationFactoryClientOptions
|
|
{
|
|
AllowAutoRedirect = false
|
|
});
|
|
}
|
|
|
|
#region Relationships Tests
|
|
|
|
[Fact]
|
|
public async Task GetAllRelationships_ReturnsOk()
|
|
{
|
|
// Act
|
|
var response = await _client.GetAsync("/api/v1/admin/social/relationships");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetAllRelationships_WithFilter_ReturnsOk()
|
|
{
|
|
// Act
|
|
var response = await _client.GetAsync("/api/v1/admin/social/relationships?status=accepted&type=friendship");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetRelationshipById_NotFound_Returns404()
|
|
{
|
|
// Arrange
|
|
var id = Guid.NewGuid();
|
|
|
|
// Act
|
|
var response = await _client.GetAsync($"/api/v1/admin/social/relationships/{id}");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task DeleteRelationship_NotFound_Returns404()
|
|
{
|
|
// Arrange
|
|
var id = Guid.NewGuid();
|
|
|
|
// Act
|
|
var response = await _client.DeleteAsync($"/api/v1/admin/social/relationships/{id}");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Blocks Tests
|
|
|
|
[Fact]
|
|
public async Task GetAllBlocks_ReturnsOk()
|
|
{
|
|
// Act
|
|
var response = await _client.GetAsync("/api/v1/admin/social/blocks");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task DeleteBlock_NotFound_Returns404()
|
|
{
|
|
// Arrange
|
|
var id = Guid.NewGuid();
|
|
|
|
// Act
|
|
var response = await _client.DeleteAsync($"/api/v1/admin/social/blocks/{id}");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Statistics Tests
|
|
|
|
[Fact]
|
|
public async Task GetStatistics_ReturnsOk()
|
|
{
|
|
// Act
|
|
var response = await _client.GetAsync("/api/v1/admin/social/statistics");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
}
|
|
|
|
#endregion
|
|
}
|