using NATS.Server.JetStream;
using NATS.Server.JetStream.Models;

namespace NATS.Server.JetStream.Tests;

public class JetStreamMirrorSourceParityTests
{
    [Fact]
    public async Task Source_subject_transform_and_cross_account_mapping_copy_expected_messages_only()
    {
        var manager = new StreamManager();
        manager.CreateOrUpdate(new StreamConfig
        {
            Name = "SRC",
            Subjects = ["orders.*"],
        });

        manager.CreateOrUpdate(new StreamConfig
        {
            Name = "AGG",
            Subjects = ["agg.*"],
            Sources =
            [
                new StreamSourceConfig
                {
                    Name = "SRC",
                    SubjectTransformPrefix = "agg.",
                    SourceAccount = "A",
                },
            ],
        });

        manager.Capture("orders.created", "1"u8.ToArray());
        manager.TryGet("AGG", out var aggregate).ShouldBeTrue();
        var messages = await aggregate.Store.ListAsync(default);
        messages.ShouldContain(m => m.Subject == "agg.orders.created");
    }
}
