diff --git a/src/TrueCV.Infrastructure/Services/CompanyVerifierService.cs b/src/TrueCV.Infrastructure/Services/CompanyVerifierService.cs index 782f05b..c72234a 100644 --- a/src/TrueCV.Infrastructure/Services/CompanyVerifierService.cs +++ b/src/TrueCV.Infrastructure/Services/CompanyVerifierService.cs @@ -51,12 +51,24 @@ public sealed class CompanyVerifierService : ICompanyVerifierService _logger.LogDebug("Verifying company: {CompanyName}", companyName); var flags = new List(); - // Try to find a cached match first + // Try to find a cached match first (but only if it existed at claimed start date) var cachedMatch = await FindCachedMatchAsync(companyName); if (cachedMatch is not null) { - _logger.LogDebug("Found cached company match for: {CompanyName}", companyName); - return CreateResultFromCache(cachedMatch, companyName, startDate, endDate, jobTitle, flags); + // Check if cached company existed at the claimed start date + var cacheValid = !startDate.HasValue || + cachedMatch.IncorporationDate == null || + cachedMatch.IncorporationDate <= startDate.Value; + + if (cacheValid) + { + _logger.LogDebug("Found cached company match for: {CompanyName}", companyName); + return CreateResultFromCache(cachedMatch, companyName, startDate, endDate, jobTitle, flags); + } + else + { + _logger.LogDebug("Cached company {CachedName} was incorporated after claimed start date, searching for alternatives", cachedMatch.CompanyName); + } } // Search Companies House