Added fail ingestion tests.
This commit is contained in:
@@ -26,7 +26,7 @@ public class VoiceWorkUpdater(AppDbContext dbContext, ITimeProvider timeProvider
|
||||
continue;
|
||||
}
|
||||
|
||||
Upsert(ingest, upsertContext);
|
||||
result.Status = Upsert(ingest, upsertContext);
|
||||
}
|
||||
|
||||
await dbContext.SaveChangesAsync(cancellationToken);
|
||||
@@ -119,20 +119,29 @@ public class VoiceWorkUpdater(AppDbContext dbContext, ITimeProvider timeProvider
|
||||
|
||||
if (voiceWork.SalesDate is not null && ingest.SalesDate is null)
|
||||
{
|
||||
string message = $"Voice work has a sales date of {voiceWork.SalesDate.Value.ToShortDateString()}, but parsed ingest does not";
|
||||
string message = $"Voice work has a sales date of {voiceWork.SalesDate.Value.ToShortDateString()}, but ingest does not";
|
||||
result.Issues.Add(new(message, VoiceWorkUpsertIssueSeverity.Error));
|
||||
}
|
||||
}
|
||||
|
||||
private void Upsert(VoiceWorkIngest ingest, VoiceWorkUpsertContext upsertContext)
|
||||
private VoiceWorkUpsertStatus Upsert(VoiceWorkIngest ingest, VoiceWorkUpsertContext upsertContext)
|
||||
{
|
||||
UpsertCircle(ingest, upsertContext);
|
||||
UpsertVoiceWork(ingest, upsertContext);
|
||||
|
||||
VoiceWork voiceWork = UpsertVoiceWork(ingest, upsertContext);
|
||||
|
||||
UpsertTags(ingest, upsertContext);
|
||||
UpsertVoiceWorkTags(ingest, upsertContext);
|
||||
UpsertCreators(ingest, upsertContext);
|
||||
UpsertVoiceWorkCreators(ingest, upsertContext);
|
||||
UpsertVoiceWorkSupportedLanguages(ingest, upsertContext);
|
||||
|
||||
return dbContext.Entry(voiceWork).State switch
|
||||
{
|
||||
EntityState.Added => VoiceWorkUpsertStatus.Inserted,
|
||||
EntityState.Modified => VoiceWorkUpsertStatus.Updated,
|
||||
_ => VoiceWorkUpsertStatus.Unchanged,
|
||||
};
|
||||
}
|
||||
|
||||
private void UpsertCircle(VoiceWorkIngest ingest, VoiceWorkUpsertContext upsertContext)
|
||||
@@ -158,19 +167,11 @@ public class VoiceWorkUpdater(AppDbContext dbContext, ITimeProvider timeProvider
|
||||
return circle;
|
||||
}
|
||||
|
||||
private void UpsertVoiceWork(VoiceWorkIngest ingest, VoiceWorkUpsertContext upsertContext)
|
||||
private VoiceWork UpsertVoiceWork(VoiceWorkIngest ingest, VoiceWorkUpsertContext upsertContext)
|
||||
{
|
||||
VoiceWork voiceWork = GetOrAddVoiceWork(ingest, upsertContext);
|
||||
VoiceWorkUpsertState state = ComputeVoiceWorkUpsertState(voiceWork, ingest, upsertContext);
|
||||
|
||||
//bool isAdded = dbContext.Entry(voiceWork).State == EntityState.Added;
|
||||
//bool isWithinCurrentScanAnchor = voiceWork.LastScannedDate == upsertContext.CurrentScanAnchor.DateTime;
|
||||
//bool isWithinPreviousScanAnchor = voiceWork.LastScannedDate == upsertContext.PreviousScanAnchor.DateTime;
|
||||
//bool hasGoneOnSale = voiceWork.SalesDate is null && ingest.SalesDate is not null;
|
||||
|
||||
//bool isNewUpcoming = ingest.SalesDate is null && (isAdded || isWithinCurrentScanAnchor || (isWithinPreviousScanAnchor && upsertContext.PreviousScanAnchor.DateTime.Hour == 16));
|
||||
//bool isNewOnSale = ingest.SalesDate is not null && (isAdded || hasGoneOnSale || isWithinCurrentScanAnchor);
|
||||
|
||||
voiceWork.Circle = upsertContext.Circles[ingest.MakerId];
|
||||
voiceWork.ProductName = ingest.Title;
|
||||
voiceWork.Description = ingest.Description;
|
||||
@@ -199,6 +200,8 @@ public class VoiceWorkUpdater(AppDbContext dbContext, ITimeProvider timeProvider
|
||||
voiceWork.PlannedReleaseDate = ingest.RegistrationDate > upsertContext.CurrentScanAnchor ? ingest.RegistrationDate : null;
|
||||
voiceWork.Status = state.IsNewUpcoming ? (byte)VoiceWorkStatus.NewAndUpcoming : (byte)VoiceWorkStatus.Upcoming;
|
||||
}
|
||||
|
||||
return voiceWork;
|
||||
}
|
||||
|
||||
private VoiceWork GetOrAddVoiceWork(VoiceWorkIngest ingest, VoiceWorkUpsertContext upsertContext)
|
||||
@@ -218,11 +221,7 @@ public class VoiceWorkUpdater(AppDbContext dbContext, ITimeProvider timeProvider
|
||||
}
|
||||
|
||||
private sealed record VoiceWorkUpsertState(
|
||||
bool IsAdded,
|
||||
bool ScannedThisAnchor,
|
||||
bool ScannedPrevAt4pm,
|
||||
bool WentOnSale,
|
||||
bool HasSalesDate,
|
||||
bool IsNewUpcoming,
|
||||
bool IsNewOnSale
|
||||
);
|
||||
@@ -243,11 +242,7 @@ public class VoiceWorkUpdater(AppDbContext dbContext, ITimeProvider timeProvider
|
||||
bool isNewOnSale = hasSales && (isAdded || wentOnSale || scannedThis);
|
||||
|
||||
return new VoiceWorkUpsertState(
|
||||
IsAdded: isAdded,
|
||||
ScannedThisAnchor: scannedThis,
|
||||
ScannedPrevAt4pm: scannedPrevAt4pm,
|
||||
WentOnSale: wentOnSale,
|
||||
HasSalesDate: hasSales,
|
||||
IsNewUpcoming: isNewUpcoming,
|
||||
IsNewOnSale: isNewOnSale
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user