using StellaOps.Feedser.Source.Common.Fetch;

namespace StellaOps.Feedser.Source.Common.Tests;

public sealed class SourceFetchServiceTests
{
    [Fact]
    public void CreateHttpRequestMessage_DefaultsToJsonAccept()
    {
        var request = new SourceFetchRequest("client", "source", new Uri("https://example.test/data"));

        using var message = SourceFetchService.CreateHttpRequestMessage(request);

        Assert.Single(message.Headers.Accept);
        Assert.Equal("application/json", message.Headers.Accept.First().MediaType);
    }

    [Fact]
    public void CreateHttpRequestMessage_UsesAcceptOverrides()
    {
        var request = new SourceFetchRequest("client", "source", new Uri("https://example.test/data"))
        {
            AcceptHeaders = new[]
            {
                "text/html",
                "application/xhtml+xml;q=0.9",
            }
        };

        using var message = SourceFetchService.CreateHttpRequestMessage(request);

        Assert.Equal(2, message.Headers.Accept.Count);
        Assert.Contains(message.Headers.Accept, h => h.MediaType == "text/html");
        Assert.Contains(message.Headers.Accept, h => h.MediaType == "application/xhtml+xml");
    }
}
