< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.Shared.Messages.PersonMessageMap
Assembly: ArturRios.Heimdall.Shared
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Shared/Messages/PersonMessageMap.cs
Line coverage
100%
Covered lines: 95
Uncovered lines: 0
Coverable lines: 95
Total lines: 106
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
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
.cctor()100%11100%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Shared/Messages/PersonMessageMap.cs

#LineLine coverage
 1using ArturRios.Util.Http;
 2
 3namespace ArturRios.Heimdall.Shared.Messages;
 4
 5/// <summary>
 6///     Maps each <see cref="PersonMessages" /> value to its HTTP status code, following the UC-06,
 7///     UC-07, UC-08, UC-09 and UC-10 flows. Passed to the response resolver.
 8/// </summary>
 9public static class PersonMessageMap
 10{
 411    public static readonly IReadOnlyDictionary<string, int> StatusCodes =
 412        DataAccessMessageMap.CombinedWith(new Dictionary<string, int>
 413        {
 414            // UC-06 main flow — person created.
 415            [PersonMessages.PersonCreatedSuccessfully] = HttpStatusCodes.Created,
 416            // AF-06a — email already exists.
 417            [PersonMessages.EmailAlreadyExists] = HttpStatusCodes.Conflict,
 418            // AF-08k — the email sign-in method is enabled; a state the caller must change first, as
 419            // AF-36a's "already active" is.
 420            [PersonMessages.EmailSignInMethodEnabled] = HttpStatusCodes.Conflict,
 421            // AF-06b — scope not found.
 422            [PersonMessages.ScopeNotFound] = HttpStatusCodes.NotFound,
 423            // AF-06e — actor is not an owner of the target scope.
 424            [PersonMessages.NotScopeOwner] = HttpStatusCodes.Forbidden,
 425            // AF-06d — invalid input.
 426            [PersonMessages.NameRequired] = HttpStatusCodes.BadRequest,
 427            [PersonMessages.NameTooLong] = HttpStatusCodes.BadRequest,
 428            [PersonMessages.EmailRequired] = HttpStatusCodes.BadRequest,
 429            [PersonMessages.EmailInvalid] = HttpStatusCodes.BadRequest,
 430            [PersonMessages.EmailTooLong] = HttpStatusCodes.BadRequest,
 431            [PersonMessages.PasswordRequired] = HttpStatusCodes.BadRequest,
 432            [PersonMessages.PasswordTooShort] = HttpStatusCodes.BadRequest,
 433            [PersonMessages.InvalidRole] = HttpStatusCodes.BadRequest,
 434            // UC-07 main flow — person(s) retrieved, by any of reads a to e.
 435            [PersonMessages.PersonRetrievedSuccessfully] = HttpStatusCodes.Ok,
 436            [PersonMessages.PersonsRetrievedSuccessfully] = HttpStatusCodes.Ok,
 437            // AF-07a — person not found.
 438            [PersonMessages.PersonNotFound] = HttpStatusCodes.NotFound,
 439            // AF-07b — caller may not view the person.
 440            [PersonMessages.NotAuthorizedToViewPerson] = HttpStatusCodes.Forbidden,
 441            // UC-08 main flow — person updated.
 442            [PersonMessages.PersonUpdatedSuccessfully] = HttpStatusCodes.Ok,
 443            // UC-08 — caller may not update the person; AF-08c for the role-change case.
 444            [PersonMessages.NotAuthorizedToUpdatePerson] = HttpStatusCodes.Forbidden,
 445            [PersonMessages.RoleChangeRequiresSystemAdmin] = HttpStatusCodes.Forbidden,
 446            // AF-08h / AF-08i (FR-PE-14, FR-AU-13) — an own email change without the current password,
 447            // or without the second factor when it is active, or while the re-authentication budget is
 448            // paused. UC-39's one refusal, and UC-39's status for it.
 449            [AuthMessages.PasswordOrCodeIncorrect] = HttpStatusCodes.Unauthorized,
 450            // UC-08 — the transition needs a scope the request does not carry, or the role is unknown.
 451            [PersonMessages.UnsupportedRoleTransition] = HttpStatusCodes.BadRequest,
 452            [PersonMessages.UnknownRole] = HttpStatusCodes.BadRequest,
 453            // NFR-12 — the change would strip a scope of its last owner (UC-08 role change, UC-09 AF-09e).
 454            [PersonMessages.ScopeWouldLoseLastOwner] = HttpStatusCodes.Conflict,
 455            // UC-09 main flow and AF-09b — person deleted, or already was.
 456            [PersonMessages.PersonDeletedSuccessfully] = HttpStatusCodes.Ok,
 457            // AF-09c — caller may not delete the person; AF-09d / AF-10c — caller targeted themselves.
 458            [PersonMessages.NotAuthorizedToDeletePerson] = HttpStatusCodes.Forbidden,
 459            [PersonMessages.CannotDeleteSelf] = HttpStatusCodes.Forbidden,
 460            // UC-10 main flow — person hard deleted. AF-10a reuses PersonNotFound (404), AF-10b reuses
 461            // ScopeWouldLoseLastOwner (409), and AF-10c reuses CannotDeleteSelf (403).
 462            [PersonMessages.PersonHardDeletedSuccessfully] = HttpStatusCodes.Ok,
 463            // UC-21 main flow — ownership added. AF-21d answers 200 instead, so the two paths carry
 464            // different messages; AF-21a reuses ScopeNotFound (404) and AF-21c NotScopeOwner (403).
 465            [PersonMessages.ScopeOwnerAddedSuccessfully] = HttpStatusCodes.Created,
 466            [PersonMessages.AlreadyScopeOwner] = HttpStatusCodes.Ok,
 467            // AF-21b — the named person is not a usable ScopeAdmin.
 468            [PersonMessages.PersonNotValidScopeAdmin] = HttpStatusCodes.BadRequest,
 469            // UC-22 main flow — ownership removed. AF-22a reuses ScopeNotFound (404) for its scope half,
 470            // AF-22b reuses ScopeWouldLoseLastOwner (409) and AF-22c NotScopeOwner (403).
 471            [PersonMessages.ScopeOwnerRemovedSuccessfully] = HttpStatusCodes.Ok,
 472            // AF-22a — the named person holds no ownership row for this scope.
 473            [PersonMessages.PersonNotScopeOwner] = HttpStatusCodes.NotFound,
 474            // UC-23 main flow — the User was promoted to owner. AF-23a reuses ScopeNotFound (404),
 475            // AF-23c NotScopeOwner (403), and the FR-PE-09 namespace guard EmailAlreadyExists (409).
 476            [PersonMessages.ScopeUserPromotedSuccessfully] = HttpStatusCodes.Ok,
 477            // AF-23b — the named person is not a usable User of the target scope.
 478            [PersonMessages.PersonNotScopeUser] = HttpStatusCodes.BadRequest,
 479            // AF-23d — the person is already a ScopeAdmin.
 480            [PersonMessages.AlreadyScopeAdmin] = HttpStatusCodes.Conflict,
 481            // UC-51 main flow — the verification email was handed to the sender. AF-51a reuses
 482            // PersonNotFound (404).
 483            [PersonMessages.VerificationEmailSentToPerson] = HttpStatusCodes.Ok,
 484            // AF-51b / AF-52b — the caller may not email this person.
 485            [PersonMessages.NotAuthorizedToEmailPerson] = HttpStatusCodes.Forbidden,
 486            // AF-51c / AF-52c — deleted, or restricted (NFR-24).
 487            [PersonMessages.PersonIsDeleted] = HttpStatusCodes.Conflict,
 488            [PersonMessages.PersonProcessingRestricted] = HttpStatusCodes.Conflict,
 489            // AF-51d — already verified; the refusal UC-15 gives, so the same status here.
 490            [AuthMessages.EmailAlreadyVerified] = HttpStatusCodes.BadRequest,
 491            // AF-51e / AF-52e — the per-person cooldown is running (FR-EV-07, FR-PR-06).
 492            [PersonMessages.AccountEmailSentRecently] = HttpStatusCodes.TooManyRequests,
 493            // AF-08j — an own email change the person's account-email budget refused (FR-PE-16).
 494            [AuthMessages.EmailSentRecently] = HttpStatusCodes.TooManyRequests,
 495            [AuthMessages.AccountEmailLimitReached] = HttpStatusCodes.TooManyRequests,
 496            // UC-52 main flow — the reset email was handed to the sender. AF-52a reuses PersonNotFound
 497            // (404); AF-52b, AF-52c and AF-52e share UC-51's entries above.
 498            [PersonMessages.PasswordResetSentToPerson] = HttpStatusCodes.Ok,
 499            // AF-52d — the account cannot sign in (FR-AU-06/07).
 4100            [PersonMessages.PersonCannotSignIn] = HttpStatusCodes.Conflict,
 4101            // UC-07 reads b to e (NFR-10) — invalid pagination or an over-length name/email filter.
 4102            [PaginationMessages.InvalidPageNumber] = HttpStatusCodes.BadRequest,
 4103            [PaginationMessages.InvalidPageSize] = HttpStatusCodes.BadRequest,
 4104            [PaginationMessages.FilterTooLong] = HttpStatusCodes.BadRequest
 4105        });
 106}

Methods/Properties

.cctor()