namespace RpgRoller.Tests;

public sealed class ResponseCompressionApiTests(WebApplicationFactory<Program> factory) : ApiTestBase(factory)
{
    [Fact]
    public async Task AuthenticatedJsonResponses_EnableGzipCompression()
    {
        using var factory = CreateFactory();
        using var client = factory.CreateClient(new() { AllowAutoRedirect = false });

        await RegisterAsync(client, "gm-compress", "Password123", "GM");
        await LoginAsync(client, "gm-compress", "Password123");
        _ = await PostAsync<CreateCampaignRequest, CampaignSummary>(client, "/api/campaigns", new("Compressed", "d6"));

        var request = new HttpRequestMessage(HttpMethod.Get, "/api/campaigns");
        request.Headers.Add("Accept-Encoding", "gzip");

        var response = await client.SendAsync(request);

        response.EnsureSuccessStatusCode();
        Assert.Contains("gzip", response.Content.Headers.ContentEncoding);
    }
}