namespace ZB.MOM.WW.Audit.Tests;

public class RedactingAuditWriterTests
{
    private sealed class CapturingWriter : IAuditWriter
    {
        public AuditEvent? Last;
        public Task WriteAsync(AuditEvent evt, CancellationToken ct = default) { Last = evt; return Task.CompletedTask; }
    }
    private sealed class StampRedactor : IAuditRedactor
    {
        public AuditEvent Apply(AuditEvent rawEvent) => rawEvent with { DetailsJson = "redacted" };
    }

    private static AuditEvent Evt() => new() { EventId = Guid.NewGuid(), OccurredAtUtc = DateTimeOffset.UtcNow,
        Actor = "a", Action = "x", Outcome = AuditOutcome.Success, DetailsJson = "secret" };

    [Fact]
    public async Task Inner_writer_receives_the_redacted_event()
    {
        var inner = new CapturingWriter();
        var sut = new RedactingAuditWriter(new StampRedactor(), inner);
        await sut.WriteAsync(Evt());
        Assert.Equal("redacted", inner.Last!.DetailsJson);
    }
}
