< Summary - Heimdall API

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
NotifyAsync()0%620%

File(s)

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

#LineLine coverage
 1using ArturRios.Heimdall.Command.Services;
 2using ArturRios.Heimdall.Shared.Security;
 3using ArturRios.Messaging.Email;
 4
 5namespace ArturRios.Heimdall.WebApi.Email;
 6
 7/// <summary>
 8///     Sends GDPR Art. 18(3)'s notification through Mailgun, and reports whether it was accepted.
 9/// </summary>
 10/// <remarks>
 11///     Deliberately does not extend <see cref="MailgunSender" />. That base class swallows delivery
 12///     failures on purpose, which is right for every other email this API sends and wrong for this
 13///     one — see <see cref="IRestrictionLiftNotifier" />.
 14/// </remarks>
 015public class MailgunRestrictionLiftNotifier(
 016    IEmailService emailService,
 017    ILogger<MailgunRestrictionLiftNotifier> logger) : IRestrictionLiftNotifier
 18{
 19    private const string Subject = "The restriction on your account is being lifted";
 20
 21    public async Task<bool> NotifyAsync(string email)
 22    {
 23        const string body = """
 24                            You asked us to restrict processing of your data, and that restriction is
 25                            being lifted.
 26
 27                            Your account will work normally again. If you did not expect this, or you
 28                            believe the matter that led to the restriction is unresolved, reply to
 29                            this message.
 30                            """;
 31
 32        try
 33        {
 034            var result = await emailService.SendEmailAsync(email, Subject, body);
 35
 036            if (!result.Success)
 37            {
 038                logger.LogError(
 039                    "Mailgun refused the restriction lift notification for {EmailRef}: {Errors}",
 040                    LogSafeEmail.Reference(email), string.Join(" | ", result.Errors));
 41            }
 42
 043            return result.Success;
 44        }
 045        catch (Exception exception)
 46        {
 047            logger.LogError(
 048                exception, "Could not deliver the restriction lift notification to {EmailRef}",
 049                LogSafeEmail.Reference(email));
 50
 051            return false;
 52        }
 053    }
 54}