Added English localization integration tests.

This commit is contained in:
2025-10-25 01:03:59 -04:00
parent 36fcd5379a
commit 99c397b3bc
16 changed files with 492 additions and 158 deletions

View File

@@ -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)

View File

@@ -1,4 +1,5 @@
using JSMR.Domain.Entities;
using JSMR.Application.Scanning.Ports;
using JSMR.Domain.Entities;
namespace JSMR.Infrastructure.Ingestion;

View File

@@ -10,7 +10,7 @@ namespace JSMR.Infrastructure.Ingestion;
public class VoiceWorkUpdater(AppDbContext dbContext, ITimeProvider timeProvider) : IVoiceWorkUpdater
{
public async Task<int[]> UpsertAsync(IReadOnlyCollection<VoiceWorkIngest> ingests, CancellationToken cancellationToken)
public async Task<VoiceWorkUpsertResult[]> UpsertAsync(IReadOnlyCollection<VoiceWorkIngest> ingests, CancellationToken cancellationToken)
{
VoiceWorkUpsertContext upsertContext = await CreateUpsertContextAsync(ingests, cancellationToken);
@@ -31,7 +31,7 @@ public class VoiceWorkUpdater(AppDbContext dbContext, ITimeProvider timeProvider
await dbContext.SaveChangesAsync(cancellationToken);
return [.. upsertContext.VoiceWorks.Select(x => x.Value.VoiceWorkId)];
return [.. upsertContext.Results.Select(x => x.Value)];
}
private async Task<VoiceWorkUpsertContext> CreateUpsertContextAsync(IReadOnlyCollection<VoiceWorkIngest> ingests, CancellationToken cancellationToken)

View File

@@ -1,4 +1,5 @@
using JSMR.Domain.Entities;
using JSMR.Application.Scanning.Ports;
using JSMR.Domain.Entities;
namespace JSMR.Infrastructure.Ingestion;
@@ -12,29 +13,29 @@ public record VoiceWorkUpsertContext(
Dictionary<string, VoiceWorkUpsertResult> Results
);
public class VoiceWorkUpsertResult
{
public int? VoiceWorkId { get; set; }
public ICollection<VoiceWorkUpsertIssue> Issues { get; } = [];
public VoiceWorkUpsertStatus Status { get; set; } = VoiceWorkUpsertStatus.Unchanged;
}
//public class VoiceWorkUpsertResult
//{
// public int? VoiceWorkId { get; set; }
// public ICollection<VoiceWorkUpsertIssue> Issues { get; } = [];
// public VoiceWorkUpsertStatus Status { get; set; } = VoiceWorkUpsertStatus.Unchanged;
//}
public record VoiceWorkUpsertIssue(
string Message,
VoiceWorkUpsertIssueSeverity Severity
);
//public record VoiceWorkUpsertIssue(
// string Message,
// VoiceWorkUpsertIssueSeverity Severity
//);
public enum VoiceWorkUpsertIssueSeverity
{
Information,
Warning,
Error
}
//public enum VoiceWorkUpsertIssueSeverity
//{
// Information,
// Warning,
// Error
//}
public enum VoiceWorkUpsertStatus
{
Unchanged,
Inserted,
Updated,
Skipped
}
//public enum VoiceWorkUpsertStatus
//{
// Unchanged,
// Inserted,
// Updated,
// Skipped
//}