using System.Net;
using System.Text.Json;
using Microsoft.AspNetCore.Mvc.Testing;

namespace Flyshot.Server.IntegrationTests;

public sealed class FlyshotServerFactory : WebApplicationFactory<Program>;

public sealed class HealthEndpointTests(FlyshotServerFactory factory) : IClassFixture<FlyshotServerFactory>
{
    [Fact]
    public async Task GetHealthz_ReturnsOkPayload()
    {
        using var client = factory.CreateClient();

        using var response = await client.GetAsync("/healthz");

        Assert.Equal(HttpStatusCode.OK, response.StatusCode);

        await using var responseStream = await response.Content.ReadAsStreamAsync();
        using var jsonDocument = await JsonDocument.ParseAsync(responseStream);
        var root = jsonDocument.RootElement;

        Assert.Equal("ok", root.GetProperty("status").GetString());
        Assert.Equal("flyshot-server-host", root.GetProperty("service").GetString());
    }
}
