< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.Command.Services.EmailVerificationTokenRetirement
Assembly: ArturRios.Heimdall.Command
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Command/Services/EmailVerificationTokenRetirement.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 48
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage
100%
Covered methods: 1
Fully covered methods: 1
Total methods: 1
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
RetireLiveAsync()100%44100%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Command/Services/EmailVerificationTokenRetirement.cs

#LineLine coverage
 1using ArturRios.Data.Relational.Core.Interfaces;
 2using ArturRios.Heimdall.Domain.Entities;
 3using Microsoft.EntityFrameworkCore;
 4
 5namespace ArturRios.Heimdall.Command.Services;
 6
 7/// <summary>
 8///     Retires a person's outstanding email-verification links (UC-15 step 3, UC-51), so that once a
 9///     new link is mailed it is the only one that works. Shared by both use cases so the rule cannot
 10///     drift between them.
 11/// </summary>
 12/// <remarks>
 13///     Already-expired tokens are left alone — AF-14a refuses them either way, and rewriting them
 14///     would only make a dead token report a different reason for being dead — and another person's
 15///     tokens are never touched.
 16/// </remarks>
 17public static class EmailVerificationTokenRetirement
 18{
 19    /// <summary>
 20    ///     Marks every live (unused, unexpired at <paramref name="now" />) verification token of the
 21    ///     person with internal id <paramref name="personId" /> as used.
 22    /// </summary>
 23    /// <returns>The update errors of the first failed write, or <c>null</c> when all succeeded.</returns>
 24    public static async Task<IEnumerable<string>?> RetireLiveAsync(
 25        IAsyncReadOnlyRepository<EmailVerificationToken, long> tokenReader,
 26        IAsyncRepository<EmailVerificationToken, long> tokenWriter,
 27        long personId,
 28        DateTime now)
 29    {
 10330        var live = await tokenReader.Query()
 10331            .Where(x => x.PersonId == personId && !x.Used && x.ExpiresAt > now)
 10332            .ToListAsync();
 33
 23734        foreach (var outstanding in live)
 35        {
 1636            outstanding.Used = true;
 37
 1638            var update = await tokenWriter.UpdateAsync(outstanding);
 39
 1640            if (!update.Success)
 41            {
 142                return update.Errors;
 43            }
 44        }
 45
 10246        return null;
 10347    }
 48}

Methods/Properties

RetireLiveAsync()