using Shouldly;
using NATS.Server.WebSocket;

namespace NATS.Server.Transport.Tests.WebSocket;

public class WebSocketOptionsTests
{
    [Fact]
    public void DefaultOptions_PortIsNegativeOne_Disabled()
    {
        var opts = new WebSocketOptions();
        opts.Port.ShouldBe(-1);
        opts.Host.ShouldBe("0.0.0.0");
        opts.Compression.ShouldBeFalse();
        opts.NoTls.ShouldBeFalse();
        opts.HandshakeTimeout.ShouldBe(TimeSpan.FromSeconds(2));
        opts.AuthTimeout.ShouldBe(TimeSpan.FromSeconds(2));
    }

    [Fact]
    public void NatsOptions_HasWebSocketProperty()
    {
        var opts = new NatsOptions();
        opts.WebSocket.ShouldNotBeNull();
        opts.WebSocket.Port.ShouldBe(-1);
    }

    [Fact]
    public void WsAuthConfig_sets_auth_override_when_websocket_auth_fields_are_present()
    {
        var ws = new WebSocketOptions
        {
            Username = "u",
        };

        WsAuthConfig.Apply(ws);

        ws.AuthOverride.ShouldBeTrue();
    }

    [Fact]
    public void WsAuthConfig_keeps_auth_override_false_when_no_ws_auth_fields_are_present()
    {
        var ws = new WebSocketOptions();

        WsAuthConfig.Apply(ws);

        ws.AuthOverride.ShouldBeFalse();
    }
}
