< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.WebApi.Email.MailgunPasswordResetSender
Assembly: ArturRios.Heimdall.WebApi
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Presentation/ArturRios.Heimdall.WebApi/Email/MailgunPasswordResetSender.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 47
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage
100%
Covered methods: 3
Fully covered methods: 3
Total methods: 3
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Purpose()100%11100%
SendAsync(...)100%44100%

File(s)

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

#LineLine coverage
 1using ArturRios.Heimdall.Command.Services;
 2using ArturRios.Messaging.Email;
 3
 4namespace ArturRios.Heimdall.WebApi.Email;
 5
 6/// <summary>
 7///     Delivers UC-12's password reset token as a real email through Mailgun (FR-PR-02). Registered
 8///     in place of <see cref="LoggingPasswordResetSender" /> whenever Mailgun is configured.
 9/// </summary>
 10public class MailgunPasswordResetSender(
 11    IEmailService emailService,
 12    EmailDeliveryOptions options,
 13    ILogger<MailgunPasswordResetSender> logger)
 1214    : MailgunSender(emailService, logger), IPasswordResetSender
 15{
 16    private const string Subject = "Reset your password";
 17
 1218    protected override string Purpose => "password reset";
 19
 20    public Task SendAsync(string email, string token, string? linkBase)
 21    {
 22        // The scope's own link wins; without one the deployment-wide setting applies.
 1223        var link = EmailDeliveryOptions.BuildLink(
 1224            string.IsNullOrWhiteSpace(linkBase) ? options.PasswordResetUrl : linkBase, token);
 25
 26        // Without a configured front end there is nowhere to link to, so the token goes in plain.
 27        // It is still usable — UC-13 takes the token, and the link is only a convenience wrapper
 28        // around it.
 1229        var body = string.IsNullOrEmpty(link)
 1230            ? $"""
 1231               Someone asked to reset the password for this address.
 1232
 1233               Use this token to set a new password: {token}
 1234
 1235               If it wasn't you, ignore this email — nothing has changed.
 1236               """
 1237            : $"""
 1238               Someone asked to reset the password for this address.
 1239
 1240               Set a new password here: {link}
 1241
 1242               If it wasn't you, ignore this email — nothing has changed.
 1243               """;
 44
 1245        return DeliverAsync(email, Subject, body);
 46    }
 47}