using NATS.Server.JetStream.Storage;

namespace NATS.Server.Tests;

public class JetStreamStoreExpiryParityTests
{
    [Fact]
    public async Task File_store_prunes_expired_messages_using_max_age_policy()
    {
        var dir = Path.Combine(Path.GetTempPath(), $"nats-js-filestore-expiry-{Guid.NewGuid():N}");
        await using var store = new FileStore(new FileStoreOptions
        {
            Directory = dir,
            MaxAgeMs = 10,
        });

        await store.AppendAsync("orders.created", "old"u8.ToArray(), default);
        await Task.Delay(20);
        await store.AppendAsync("orders.created", "new"u8.ToArray(), default);

        var state = await store.GetStateAsync(default);
        state.Messages.ShouldBe((ulong)1);
    }
}
