Added English localization integration tests.
This commit is contained in:
@@ -10,7 +10,7 @@ namespace JSMR.Infrastructure.Ingestion;
|
||||
|
||||
public class EnglishVoiceWorkUpdater(AppDbContext dbContext, ILanguageIdentifier languageIdentifier) : IVoiceWorkUpdater
|
||||
{
|
||||
public async Task<int[]> UpsertAsync(IReadOnlyCollection<VoiceWorkIngest> ingests, CancellationToken cancellationToken)
|
||||
public async Task<VoiceWorkUpsertResult[]> UpsertAsync(IReadOnlyCollection<VoiceWorkIngest> ingests, CancellationToken cancellationToken)
|
||||
{
|
||||
EnglishVoiceWorkUpsertContext upsertContext = await CreateUpsertContextAsync(ingests, cancellationToken);
|
||||
|
||||
@@ -20,20 +20,23 @@ public class EnglishVoiceWorkUpdater(AppDbContext dbContext, ILanguageIdentifier
|
||||
|
||||
VoiceWorkUpsertResult result = upsertContext.Results[ingest.ProductId];
|
||||
|
||||
if (upsertContext.VoiceWorks.TryGetValue(ingest.ProductId, out VoiceWork? voiceWork))
|
||||
{
|
||||
result.VoiceWorkId = upsertContext.VoiceWorks[ingest.ProductId].VoiceWorkId;
|
||||
}
|
||||
|
||||
if (result.Issues.Count > 0)
|
||||
{
|
||||
result.Status = VoiceWorkUpsertStatus.Skipped;
|
||||
continue;
|
||||
}
|
||||
|
||||
UpsertEnglishVoiceWork(ingest, upsertContext);
|
||||
|
||||
result.Status = VoiceWorkUpsertStatus.Updated;
|
||||
|
||||
result.Status = UpsertEnglishVoiceWork(ingest, upsertContext);
|
||||
}
|
||||
|
||||
await dbContext.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return [.. upsertContext.VoiceWorks.Select(x => x.Value.VoiceWorkId)];
|
||||
return [.. upsertContext.Results.Select(x => x.Value)];
|
||||
}
|
||||
|
||||
private async Task<EnglishVoiceWorkUpsertContext> CreateUpsertContextAsync(IReadOnlyCollection<VoiceWorkIngest> ingests, CancellationToken cancellationToken)
|
||||
@@ -68,31 +71,41 @@ public class EnglishVoiceWorkUpdater(AppDbContext dbContext, ILanguageIdentifier
|
||||
|
||||
if (!isTitleEnglish && !isDescriptionEnglish)
|
||||
{
|
||||
string message = $"Prouct title and/or description is not in English";
|
||||
string message = $"Product title and/or description is not in English";
|
||||
result.Issues.Add(new(message, VoiceWorkUpsertIssueSeverity.Information));
|
||||
return;
|
||||
}
|
||||
|
||||
if (upsertContext.Circles.TryGetValue(ingest.MakerId, out Circle? circle) == false)
|
||||
if (upsertContext.Circles.ContainsKey(ingest.MakerId) == false)
|
||||
{
|
||||
string message = $"Unable to find circle for maker id: {ingest.MakerId}";
|
||||
result.Issues.Add(new(message, VoiceWorkUpsertIssueSeverity.Error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (upsertContext.VoiceWorks.TryGetValue(ingest.ProductId, out VoiceWork? voiceWork) == false)
|
||||
if (upsertContext.VoiceWorks.ContainsKey(ingest.ProductId) == false)
|
||||
{
|
||||
string message = $"Unable to find voice work for product id: {ingest.ProductId}";
|
||||
result.Issues.Add(new(message, VoiceWorkUpsertIssueSeverity.Error));
|
||||
}
|
||||
}
|
||||
|
||||
private void UpsertEnglishVoiceWork(VoiceWorkIngest ingest, EnglishVoiceWorkUpsertContext upsertContext)
|
||||
private VoiceWorkUpsertStatus UpsertEnglishVoiceWork(VoiceWorkIngest ingest, EnglishVoiceWorkUpsertContext upsertContext)
|
||||
{
|
||||
EnglishVoiceWork englishVoiceWork = GetOrAddEnglishVoiceWork(ingest, upsertContext);
|
||||
englishVoiceWork.ProductName = ingest.Title;
|
||||
englishVoiceWork.Description = ingest.Description;
|
||||
englishVoiceWork.IsValid = true;
|
||||
|
||||
switch (dbContext.Entry(englishVoiceWork).State)
|
||||
{
|
||||
case EntityState.Added:
|
||||
return VoiceWorkUpsertStatus.Inserted;
|
||||
case EntityState.Modified:
|
||||
return VoiceWorkUpsertStatus.Updated;
|
||||
default:
|
||||
return VoiceWorkUpsertStatus.Unchanged;
|
||||
}
|
||||
}
|
||||
|
||||
private EnglishVoiceWork GetOrAddEnglishVoiceWork(VoiceWorkIngest ingest, EnglishVoiceWorkUpsertContext upsertContext)
|
||||
|
||||
Reference in New Issue
Block a user