< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.WebApi.Email.EmailDeliveryOptions
Assembly: ArturRios.Heimdall.WebApi
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Presentation/ArturRios.Heimdall.WebApi/Email/EmailDeliveryOptions.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 57
Line coverage: 100%
Branch coverage
70%
Covered branches: 7
Total branches: 10
Branch coverage: 70%
Method coverage
100%
Covered methods: 5
Fully covered methods: 5
Total methods: 5
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_VerificationUrl()100%11100%
get_PasswordResetUrl()100%11100%
get_MailgunConfigured()100%11100%
FromEnvironment()50%66100%
BuildLink(...)100%44100%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Presentation/ArturRios.Heimdall.WebApi/Email/EmailDeliveryOptions.cs

#LineLine coverage
 1using ArturRios.Messaging.Email;
 2
 3namespace ArturRios.Heimdall.WebApi.Email;
 4
 5/// <summary>
 6///     Settings for outbound transactional email. Two halves: whether Mailgun is configured at all,
 7///     which decides between real delivery and the logging senders at start-up, and the front-end
 8///     links the two emails point at.
 9/// </summary>
 10/// <remarks>
 11///     The Mailgun credentials themselves are read by <see cref="MailgunEmailService" /> from its
 12///     own environment variables at call time — this class only observes whether they are present,
 13///     so an unconfigured environment degrades to logging instead of failing every send.
 14/// </remarks>
 15public class EmailDeliveryOptions
 16{
 17    private const string VerificationUrlVariable = "HEIMDALL_EMAIL_VERIFICATION_URL";
 18    private const string PasswordResetUrlVariable = "HEIMDALL_PASSWORD_RESET_URL";
 19
 20    /// <summary>Base link a verification token is appended to (UC-14).</summary>
 183821    public string VerificationUrl { get; init; } = string.Empty;
 22
 23    /// <summary>Base link a password reset token is appended to (UC-13).</summary>
 184124    public string PasswordResetUrl { get; init; } = string.Empty;
 25
 26    /// <summary>
 27    ///     Whether Mailgun has both the credentials it needs. False in any environment that has not
 28    ///     been given them — notably the functional test suite, which must never reach the network.
 29    /// </summary>
 179830    public bool MailgunConfigured { get; init; }
 31
 89932    public static EmailDeliveryOptions FromEnvironment() => new()
 89933    {
 89934        VerificationUrl = Environment.GetEnvironmentVariable(VerificationUrlVariable) ?? string.Empty,
 89935        PasswordResetUrl = Environment.GetEnvironmentVariable(PasswordResetUrlVariable) ?? string.Empty,
 89936        MailgunConfigured =
 89937            !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(MailgunEmailService.ApiKeyVariable)) &&
 89938            !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(MailgunEmailService.DomainVariable))
 89939    };
 40
 41    /// <summary>
 42    ///     Appends a token to a configured base link as a <c>token</c> query parameter, respecting a
 43    ///     query string the base may already carry. Returns an empty string when no link is
 44    ///     configured, which is the signal for the senders to write the bare token instead.
 45    /// </summary>
 46    public static string BuildLink(string baseUrl, string token)
 47    {
 2548        if (string.IsNullOrWhiteSpace(baseUrl))
 49        {
 650            return string.Empty;
 51        }
 52
 1953        var separator = baseUrl.Contains('?') ? '&' : '?';
 54
 1955        return $"{baseUrl}{separator}token={Uri.EscapeDataString(token)}";
 56    }
 57}