< Summary

Information
Class: RoleRadar.Domain.Tracking.PostingCandidate
Assembly: RoleRadar.Domain
File(s): /home/runner/work/roleradar/roleradar/src/RoleRadar.Domain/Tracking/Posting.cs
Line coverage
100%
Covered lines: 5
Uncovered lines: 0
Coverable lines: 5
Total lines: 529
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Id()100%11100%
get_Title()100%11100%
get_Disposition()100%11100%
get_Reason()100%11100%

File(s)

/home/runner/work/roleradar/roleradar/src/RoleRadar.Domain/Tracking/Posting.cs

#LineLine coverage
 1namespace RoleRadar.Domain.Tracking;
 2
 3public sealed record PostingDifference(
 4    string Field,
 5    object? StoredValue,
 6    object? SuppliedValue);
 7
 328public sealed record PostingCandidate(
 349    Guid Id,
 210    string Title,
 211    PostingDisposition Disposition,
 3412    string? Reason);
 13
 14
 15public sealed class Posting
 16{
 17    public const int MaxTitleLength = 200;
 18    public const int MaxUrlLength = 1000;
 19    public const int MaxAtsTenantLength = 100;
 20    public const int MaxRequisitionIdLength = 100;
 21    public const int MaxLocationLength = 150;
 22    public const int MaxCompensationTextLength = 300;
 23    public const int MaxCultureSummaryLength = 500;
 24    public const int MaxDispositionReasonLength = 500;
 25
 26    public Guid Id { get; init; }
 27    public string OwnerId { get; init; } = string.Empty;
 28    public Guid CompanyId { get; private set; }
 29    public string Title { get; private set; } = string.Empty;
 30    public string NormalizedTitle { get; private set; } = string.Empty;
 31    public string? OriginalUrl { get; private set; }
 32    public string? NormalizedUrl { get; private set; }
 33    public SourceKind SourceKind { get; private set; } = SourceKind.Ats;
 34    public string? AtsTenant { get; private set; }
 35    public string? RequisitionId { get; private set; }
 36    public string? DedupKeyA { get; private set; }
 37    public string? DedupKeyB { get; private set; }
 38    public string? DedupKeyC { get; private set; }
 39    public string? Location { get; private set; }
 40    public RemoteType RemoteType { get; private set; } = RemoteType.Unknown;
 41    public Compensation Compensation { get; private set; } = new();
 42    public bool? CompHighPriority { get; private set; }
 43    public string? PostedDate { get; private set; }
 44    public DateTimeOffset FirstSeenAt { get; init; }
 45    public DateTimeOffset LastVerifiedAt { get; private set; }
 46    public string? ClosedDate { get; private set; }
 47    public decimal? Score { get; private set; }
 48    public CultureLevel CultureLevel { get; private set; } = CultureLevel.Unknown;
 49    public string? CultureSummary { get; private set; }
 50    public PostingDisposition Disposition { get; private set; } = PostingDisposition.Lead;
 51    public string? DispositionReason { get; private set; }
 52    public Guid? DispositionCriterionId { get; private set; }
 53    public ResurfacePolicy ResurfacePolicy { get; private set; } = ResurfacePolicy.Never;
 54    public DateTimeOffset? DecidedAt { get; private set; }
 55    public Guid? DuplicateOfId { get; private set; }
 56    public Guid? ScreeningNoteId { get; private set; }
 57    public Guid VersionToken { get; private set; }
 58    public DateTimeOffset CreatedAt { get; init; }
 59    public DateTimeOffset UpdatedAt { get; private set; }
 60
 61    public static Posting Create(
 62        string ownerId,
 63        Guid companyId,
 64        string title,
 65        SourceKind sourceKind = SourceKind.Ats,
 66        string? originalUrl = null,
 67        string? atsTenant = null,
 68        string? requisitionId = null,
 69        string? location = null,
 70        RemoteType remoteType = RemoteType.Unknown,
 71        Compensation? compensation = null,
 72        string? postedDate = null,
 73        decimal? score = null,
 74        CultureLevel cultureLevel = CultureLevel.Unknown,
 75        string? cultureSummary = null,
 76        PostingDisposition disposition = PostingDisposition.Lead,
 77        string? dispositionReason = null,
 78        Guid? dispositionCriterionId = null,
 79        ResurfacePolicy resurfacePolicy = ResurfacePolicy.Never,
 80        DateTimeOffset? decidedAt = null,
 81        Guid? duplicateOfId = null,
 82        Guid? screeningNoteId = null,
 83        Guid? id = null,
 84        DateTimeOffset? now = null,
 85        bool? compHighPriority = null,
 86        string? closedDate = null)
 87    {
 88        ArgumentException.ThrowIfNullOrWhiteSpace(ownerId);
 89        ArgumentException.ThrowIfNullOrWhiteSpace(title);
 90
 91        var trimmedTitle = title.Trim();
 92        if (trimmedTitle.Length > MaxTitleLength)
 93        {
 94            throw new ArgumentException($"Posting title cannot exceed {MaxTitleLength} characters.", nameof(title));
 95        }
 96
 97        if (originalUrl is not null && originalUrl.Length > MaxUrlLength)
 98        {
 99            throw new ArgumentException($"Original URL cannot exceed {MaxUrlLength} characters.", nameof(originalUrl));
 100        }
 101
 102        if (atsTenant is not null && atsTenant.Length > MaxAtsTenantLength)
 103        {
 104            throw new ArgumentException($"ATS tenant cannot exceed {MaxAtsTenantLength} characters.", nameof(atsTenant))
 105        }
 106
 107        if (requisitionId is not null && requisitionId.Length > MaxRequisitionIdLength)
 108        {
 109            throw new ArgumentException($"Requisition ID cannot exceed {MaxRequisitionIdLength} characters.", nameof(req
 110        }
 111
 112        if (location is not null && location.Length > MaxLocationLength)
 113        {
 114            throw new ArgumentException($"Location cannot exceed {MaxLocationLength} characters.", nameof(location));
 115        }
 116
 117        if (compensation?.Text is not null && compensation.Text.Length > MaxCompensationTextLength)
 118        {
 119            throw new ArgumentException($"Compensation text cannot exceed {MaxCompensationTextLength} characters.", name
 120        }
 121
 122        if (cultureSummary is not null && cultureSummary.Length > MaxCultureSummaryLength)
 123        {
 124            throw new ArgumentException($"Culture summary cannot exceed {MaxCultureSummaryLength} characters.", nameof(c
 125        }
 126
 127        if (dispositionReason is not null && dispositionReason.Length > MaxDispositionReasonLength)
 128        {
 129            throw new ArgumentException($"Disposition reason cannot exceed {MaxDispositionReasonLength} characters.", na
 130        }
 131
 132        if (score.HasValue && (score.Value < 0.0m || score.Value > 10.0m))
 133        {
 134            throw new ArgumentException("Score must be between 0.0 and 10.0.", nameof(score));
 135        }
 136
 137        var actualId = id ?? Guid.CreateVersion7();
 138        if (duplicateOfId.HasValue && duplicateOfId.Value == actualId)
 139        {
 140            throw new ArgumentException("A posting cannot be a duplicate of itself.", nameof(duplicateOfId));
 141        }
 142
 143        var timestamp = now ?? DateTimeOffset.UtcNow;
 144        var normalizedTitle = TitleNormalizer.Normalize(trimmedTitle);
 145        var normalizedUrl = UrlNormalizer.Normalize(originalUrl);
 146
 147        var trimmedAtsTenant = string.IsNullOrWhiteSpace(atsTenant) ? null : atsTenant.Trim();
 148        var trimmedReqId = string.IsNullOrWhiteSpace(requisitionId) ? null : requisitionId.Trim();
 149
 150        string? dedupKeyA = null;
 151        if (!string.IsNullOrWhiteSpace(trimmedAtsTenant) && !string.IsNullOrWhiteSpace(trimmedReqId))
 152        {
 153            dedupKeyA = $"{trimmedAtsTenant}|{trimmedReqId}";
 154        }
 155
 156        string? dedupKeyB = normalizedUrl;
 157
 158        string? dedupKeyC = null;
 159        if (string.IsNullOrWhiteSpace(trimmedAtsTenant) && !string.IsNullOrWhiteSpace(trimmedReqId))
 160        {
 161            dedupKeyC = $"{companyId:D}|{trimmedReqId}";
 162        }
 163
 164        DateTimeOffset? initialDecidedAt = decidedAt;
 165        if (initialDecidedAt is null && (disposition == PostingDisposition.ScreenedOut || disposition == PostingDisposit
 166        {
 167            initialDecidedAt = timestamp;
 168        }
 169
 170        return new Posting
 171        {
 172            Id = actualId,
 173            OwnerId = ownerId,
 174            CompanyId = companyId,
 175            Title = trimmedTitle,
 176            NormalizedTitle = normalizedTitle,
 177            OriginalUrl = originalUrl,
 178            NormalizedUrl = normalizedUrl,
 179            SourceKind = sourceKind,
 180            AtsTenant = trimmedAtsTenant,
 181            RequisitionId = trimmedReqId,
 182            DedupKeyA = dedupKeyA,
 183            DedupKeyB = dedupKeyB,
 184            DedupKeyC = dedupKeyC,
 185            Location = location?.Trim(),
 186            RemoteType = remoteType,
 187            Compensation = compensation ?? new(),
 188            CompHighPriority = compHighPriority,
 189            PostedDate = postedDate,
 190            ClosedDate = closedDate,
 191            FirstSeenAt = timestamp,
 192            LastVerifiedAt = timestamp,
 193            Score = score,
 194            CultureLevel = cultureLevel,
 195            CultureSummary = cultureSummary?.Trim(),
 196            Disposition = disposition,
 197            DispositionReason = dispositionReason?.Trim(),
 198            DispositionCriterionId = dispositionCriterionId,
 199            ResurfacePolicy = resurfacePolicy,
 200            DecidedAt = initialDecidedAt,
 201            DuplicateOfId = duplicateOfId,
 202            ScreeningNoteId = screeningNoteId,
 203            VersionToken = Guid.CreateVersion7(),
 204            CreatedAt = timestamp,
 205            UpdatedAt = timestamp
 206        };
 207    }
 208
 209    public static Posting Rehydrate(
 210        Guid id,
 211        string ownerId,
 212        Guid companyId,
 213        string title,
 214        string normalizedTitle,
 215        string? originalUrl,
 216        string? normalizedUrl,
 217        SourceKind sourceKind,
 218        string? atsTenant,
 219        string? requisitionId,
 220        string? dedupKeyA,
 221        string? dedupKeyB,
 222        string? dedupKeyC,
 223        string? location,
 224        RemoteType remoteType,
 225        Compensation compensation,
 226        string? postedDate,
 227        DateTimeOffset firstSeenAt,
 228        DateTimeOffset lastVerifiedAt,
 229        string? closedDate,
 230        decimal? score,
 231        CultureLevel cultureLevel,
 232        string? cultureSummary,
 233        PostingDisposition disposition,
 234        string? dispositionReason,
 235        Guid? dispositionCriterionId,
 236        ResurfacePolicy resurfacePolicy,
 237        DateTimeOffset? decidedAt,
 238        Guid? duplicateOfId,
 239        Guid? screeningNoteId,
 240        Guid versionToken,
 241        DateTimeOffset createdAt,
 242        DateTimeOffset updatedAt,
 243        bool? compHighPriority = null)
 244    {
 245        return new Posting
 246        {
 247            Id = id,
 248            OwnerId = ownerId,
 249            CompanyId = companyId,
 250            Title = title,
 251            NormalizedTitle = normalizedTitle,
 252            OriginalUrl = originalUrl,
 253            NormalizedUrl = normalizedUrl,
 254            SourceKind = sourceKind,
 255            AtsTenant = atsTenant,
 256            RequisitionId = requisitionId,
 257            DedupKeyA = dedupKeyA,
 258            DedupKeyB = dedupKeyB,
 259            DedupKeyC = dedupKeyC,
 260            Location = location,
 261            RemoteType = remoteType,
 262            Compensation = compensation,
 263            CompHighPriority = compHighPriority,
 264            PostedDate = postedDate,
 265            FirstSeenAt = firstSeenAt,
 266            LastVerifiedAt = lastVerifiedAt,
 267            ClosedDate = closedDate,
 268            Score = score,
 269            CultureLevel = cultureLevel,
 270            CultureSummary = cultureSummary,
 271            Disposition = disposition,
 272            DispositionReason = dispositionReason,
 273            DispositionCriterionId = dispositionCriterionId,
 274            ResurfacePolicy = resurfacePolicy,
 275            DecidedAt = decidedAt,
 276            DuplicateOfId = duplicateOfId,
 277            ScreeningNoteId = screeningNoteId,
 278            VersionToken = versionToken,
 279            CreatedAt = createdAt,
 280            UpdatedAt = updatedAt
 281        };
 282    }
 283
 284    public void UpdateLastVerified(DateTimeOffset timestamp)
 285    {
 286        LastVerifiedAt = timestamp;
 287        UpdatedAt = timestamp;
 288        VersionToken = Guid.CreateVersion7();
 289    }
 290
 291    public void UpgradeIdentifiers(string? atsTenant, string? requisitionId, DateTimeOffset timestamp)
 292    {
 293        var trimmedAtsTenant = string.IsNullOrWhiteSpace(atsTenant) ? AtsTenant : atsTenant.Trim();
 294        var trimmedReqId = string.IsNullOrWhiteSpace(requisitionId) ? RequisitionId : requisitionId.Trim();
 295
 296        AtsTenant = trimmedAtsTenant;
 297        RequisitionId = trimmedReqId;
 298
 299        if (!string.IsNullOrWhiteSpace(trimmedAtsTenant) && !string.IsNullOrWhiteSpace(trimmedReqId))
 300        {
 301            DedupKeyA = $"{trimmedAtsTenant}|{trimmedReqId}";
 302            DedupKeyC = null;
 303        }
 304        else if (string.IsNullOrWhiteSpace(trimmedAtsTenant) && !string.IsNullOrWhiteSpace(trimmedReqId))
 305        {
 306            DedupKeyA = null;
 307            DedupKeyC = $"{CompanyId:D}|{trimmedReqId}";
 308        }
 309
 310        UpdatedAt = timestamp;
 311        VersionToken = Guid.CreateVersion7();
 312    }
 313
 314    public void Transition(
 315        PostingDisposition targetDisposition,
 316        string? reason,
 317        Guid? criterionId,
 318        ResurfacePolicy resurfacePolicy,
 319        DateTimeOffset timestamp,
 320        string? closedDate = null)
 321    {
 322        Disposition = targetDisposition;
 323        DispositionReason = reason?.Trim();
 324        DispositionCriterionId = criterionId;
 325        ResurfacePolicy = resurfacePolicy;
 326        if (closedDate is not null)
 327        {
 328            ClosedDate = closedDate;
 329        }
 330
 331        if (targetDisposition == PostingDisposition.ScreenedOut ||
 332            targetDisposition == PostingDisposition.Closed ||
 333            targetDisposition == PostingDisposition.Rejected)
 334        {
 335            DecidedAt = timestamp;
 336        }
 337        else if (targetDisposition == PostingDisposition.Lead)
 338        {
 339            DecidedAt = null;
 340        }
 341
 342        UpdatedAt = timestamp;
 343        VersionToken = Guid.CreateVersion7();
 344    }
 345
 346    public void TransitionToApplied(DateTimeOffset timestamp)
 347    {
 348        Disposition = PostingDisposition.Applied;
 349        DecidedAt = null;
 350        UpdatedAt = timestamp;
 351        VersionToken = Guid.CreateVersion7();
 352    }
 353
 354    public void SynchronizeFromApplicationEvent(
 355        PostingDisposition terminalDisposition,
 356        string? reason,
 357        DateTimeOffset timestamp)
 358    {
 359        Disposition = terminalDisposition;
 360        if (!string.IsNullOrWhiteSpace(reason))
 361        {
 362            var trimmed = reason.Trim();
 363            DispositionReason = trimmed.Length > MaxDispositionReasonLength
 364                ? trimmed[..MaxDispositionReasonLength]
 365                : trimmed;
 366        }
 367
 368        DecidedAt = timestamp;
 369        UpdatedAt = timestamp;
 370        VersionToken = Guid.CreateVersion7();
 371    }
 372
 373    public List<string> ApplyExplicitUpdate(
 374        Guid? companyId,
 375        string? title,
 376        string? originalUrl,
 377        SourceKind? sourceKind,
 378        string? atsTenant,
 379        string? requisitionId,
 380        string? location,
 381        RemoteType? remoteType,
 382        Compensation? compensation,
 383        string? postedDate,
 384        decimal? score,
 385        CultureLevel? cultureLevel,
 386        string? cultureSummary,
 387        Guid? duplicateOfId,
 388        Guid? screeningNoteId,
 389        DateTimeOffset timestamp,
 390        bool? compHighPriority = null)
 391    {
 392        var changedFields = new List<string>();
 393
 394        if (companyId.HasValue && companyId.Value != CompanyId)
 395        {
 396            CompanyId = companyId.Value;
 397            changedFields.Add("company_id");
 398        }
 399
 400        if (!string.IsNullOrWhiteSpace(title) && title.Trim() != Title)
 401        {
 402            Title = title.Trim();
 403            NormalizedTitle = TitleNormalizer.Normalize(Title);
 404            changedFields.Add("title");
 405        }
 406
 407        if (originalUrl is not null && originalUrl != OriginalUrl)
 408        {
 409            OriginalUrl = originalUrl;
 410            NormalizedUrl = UrlNormalizer.Normalize(originalUrl);
 411            DedupKeyB = NormalizedUrl;
 412            changedFields.Add("url");
 413        }
 414
 415        if (sourceKind.HasValue && sourceKind.Value != SourceKind)
 416        {
 417            SourceKind = sourceKind.Value;
 418            changedFields.Add("source_kind");
 419        }
 420
 421        if (atsTenant is not null && atsTenant != AtsTenant)
 422        {
 423            AtsTenant = atsTenant.Trim();
 424            changedFields.Add("ats_tenant");
 425        }
 426
 427        if (requisitionId is not null && requisitionId != RequisitionId)
 428        {
 429            RequisitionId = requisitionId.Trim();
 430            changedFields.Add("requisition_id");
 431        }
 432
 433        // Recompute dedup keys if tenant or req id changed
 434        if (changedFields.Contains("ats_tenant") || changedFields.Contains("requisition_id") || changedFields.Contains("
 435        {
 436            if (!string.IsNullOrWhiteSpace(AtsTenant) && !string.IsNullOrWhiteSpace(RequisitionId))
 437            {
 438                DedupKeyA = $"{AtsTenant}|{RequisitionId}";
 439                DedupKeyC = null;
 440            }
 441            else if (string.IsNullOrWhiteSpace(AtsTenant) && !string.IsNullOrWhiteSpace(RequisitionId))
 442            {
 443                DedupKeyA = null;
 444                DedupKeyC = $"{CompanyId:D}|{RequisitionId}";
 445            }
 446            else
 447            {
 448                DedupKeyA = null;
 449                DedupKeyC = null;
 450            }
 451        }
 452
 453        if (location is not null && location != Location)
 454        {
 455            Location = location.Trim();
 456            changedFields.Add("location");
 457        }
 458
 459        if (remoteType.HasValue && remoteType.Value != RemoteType)
 460        {
 461            RemoteType = remoteType.Value;
 462            changedFields.Add("remote_type");
 463        }
 464
 465        if (compensation is not null && compensation != Compensation)
 466        {
 467            Compensation = compensation;
 468            changedFields.Add("compensation");
 469        }
 470
 471        if (postedDate is not null && postedDate != PostedDate)
 472        {
 473            PostedDate = postedDate;
 474            changedFields.Add("posted_date");
 475        }
 476
 477        if (score.HasValue && score.Value != Score)
 478        {
 479            if (score.Value < 0.0m || score.Value > 10.0m)
 480            {
 481                throw new ArgumentException("Score must be between 0.0 and 10.0.", nameof(score));
 482            }
 483            Score = score.Value;
 484            changedFields.Add("score");
 485        }
 486
 487        if (cultureLevel.HasValue && cultureLevel.Value != CultureLevel)
 488        {
 489            CultureLevel = cultureLevel.Value;
 490            changedFields.Add("culture_level");
 491        }
 492
 493        if (cultureSummary is not null && cultureSummary != CultureSummary)
 494        {
 495            CultureSummary = cultureSummary.Trim();
 496            changedFields.Add("culture_summary");
 497        }
 498
 499        if (duplicateOfId.HasValue && duplicateOfId.Value != DuplicateOfId)
 500        {
 501            if (duplicateOfId.Value == Id)
 502            {
 503                throw new ArgumentException("A posting cannot be a duplicate of itself.", nameof(duplicateOfId));
 504            }
 505            DuplicateOfId = duplicateOfId.Value;
 506            changedFields.Add("duplicate_of_id");
 507        }
 508
 509        if (screeningNoteId.HasValue && screeningNoteId.Value != ScreeningNoteId)
 510        {
 511            ScreeningNoteId = screeningNoteId.Value;
 512            changedFields.Add("screening_note_id");
 513        }
 514
 515        if (compHighPriority.HasValue && compHighPriority.Value != CompHighPriority)
 516        {
 517            CompHighPriority = compHighPriority.Value;
 518            changedFields.Add("comp_high_priority");
 519        }
 520
 521        if (changedFields.Count > 0)
 522        {
 523            UpdatedAt = timestamp;
 524            VersionToken = Guid.CreateVersion7();
 525        }
 526
 527        return changedFields;
 528    }
 529}