using Elfisa.Core;
using Xunit;

namespace Elfisa.Tests;

public class SessionTests
{
    [Fact]
    public void Future_token_is_not_expired()
        => Assert.False(Session.IsJwtExpired(Jwt.Make(Jwt.Now + 3600)));

    [Fact]
    public void Past_token_is_expired()
        => Assert.True(Session.IsJwtExpired(Jwt.Make(Jwt.Now - 10)));

    [Fact]
    public void Within_60s_skew_is_treated_expired()
        => Assert.True(Session.IsJwtExpired(Jwt.Make(Jwt.Now + 30)));

    [Theory]
    [InlineData("")]
    [InlineData("onlyonepart")]
    [InlineData("has.two")]
    [InlineData("too.many.parts.here")]
    [InlineData("a.!!!notbase64!!!.c")]
    public void Malformed_token_is_treated_expired(string token)
        => Assert.True(Session.IsJwtExpired(token));

    [Fact]
    public void No_exp_claim_is_not_expired()
        => Assert.False(Session.IsJwtExpired(Jwt.MakeNoExp()));
}
