using TeleWave.Domain.Auth;
using Xunit;

namespace TeleWave.Domain.Tests.Auth;

public class RefreshTokenTests
{
    [Fact]
    public void Issue_CreatesActiveToken()
    {
        var token = RefreshToken.Issue(Guid.NewGuid(), "hash", DateTimeOffset.UtcNow.AddDays(1));

        Assert.True(token.IsActive);
        Assert.Null(token.RevokedAt);
    }

    [Fact]
    public void IsActive_WhenExpired_ReturnsFalse()
    {
        var token = RefreshToken.Issue(Guid.NewGuid(), "hash", DateTimeOffset.UtcNow.AddDays(-1));

        Assert.False(token.IsActive);
    }

    [Fact]
    public void Revoke_MarksTokenInactive()
    {
        var token = RefreshToken.Issue(Guid.NewGuid(), "hash", DateTimeOffset.UtcNow.AddDays(1));

        token.Revoke("new-hash");

        Assert.False(token.IsActive);
        Assert.NotNull(token.RevokedAt);
        Assert.Equal("new-hash", token.ReplacedByTokenHash);
    }
}
