using OmsorgCore.Email;

namespace OmsorgCore.Tests.Services;

public class EmailTemplateRendererTests
{
    [Fact]
    public void Render_ReplacesKnownPlaceholders()
    {
        var result = EmailTemplateRenderer.Render(
            "Code: $RESET_PIN$, gültig $RESET_PIN_EXPIRY_MINUTES$ Minuten.",
            new Dictionary<string, string>
            {
                ["RESET_PIN"] = "123456",
                ["RESET_PIN_EXPIRY_MINUTES"] = "5"
            });

        Assert.Equal("Code: 123456, gültig 5 Minuten.", result);
    }

    [Fact]
    public void Render_LeavesUnknownPlaceholdersUntouched()
    {
        var result = EmailTemplateRenderer.Render(
            "Hallo $UNKNOWN$, Code: $RESET_PIN$.",
            new Dictionary<string, string> { ["RESET_PIN"] = "123456" });

        Assert.Equal("Hallo $UNKNOWN$, Code: 123456.", result);
    }

    [Fact]
    public void Render_ReplacesRepeatedPlaceholder()
    {
        var result = EmailTemplateRenderer.Render(
            "$RESET_PIN$ - $RESET_PIN$",
            new Dictionary<string, string> { ["RESET_PIN"] = "111" });

        Assert.Equal("111 - 111", result);
    }
}
