Update search provider sort logic, and added testing for circle search provider.

This commit is contained in:
2025-08-30 16:21:35 -04:00
parent f221deea36
commit 516060963e
11 changed files with 435 additions and 143 deletions

View File

@@ -0,0 +1,28 @@
using JSMR.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace JSMR.Tests.Fixtures;
public class CircleSearchProviderFixture : MariaDbFixture
{
protected override async Task OnInitializedAsync(AppDbContext context)
{
await SeedAsync(context);
}
private static async Task SeedAsync(AppDbContext context)
{
// Make seeding idempotent (quick existence check)
if (await context.Circles.AnyAsync())
return;
context.Circles.AddRange(
new() { CircleId = 1, Name = "Good Dreams", MakerId = "RG00001" },
new() { CircleId = 2, Name = "Sweet Dreams", Favorite = true, MakerId = "RG00002" },
new() { CircleId = 3, Name = "Nightmare Fuel", Blacklisted = true, MakerId = "RG00003" },
new() { CircleId = 4, Name = "Garbage Studio", Spam = true, MakerId = "RG00004" }
);
await context.SaveChangesAsync();
}
}

View File

@@ -0,0 +1,67 @@
using JSMR.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Testcontainers.MariaDb;
namespace JSMR.Tests.Fixtures;
public class MariaDbFixture : IAsyncLifetime
{
const int MajorVersion = 10;
const int MinorVersion = 11;
const int Build = 6;
public MariaDbContainer? MariaDbContainer { get; private set; }
public string ConnectionString { get; private set; } = default!;
public async Task InitializeAsync()
{
MariaDbContainer = new MariaDbBuilder()
.WithImage($"mariadb:{MajorVersion}.{MinorVersion}.{Build}")
.Build();
await MariaDbContainer.StartAsync();
ConnectionString = MariaDbContainer.GetConnectionString();
await using AppDbContext context = CreateDbContext();
await context.Database.EnsureCreatedAsync();
await OnInitializedAsync(context);
}
protected virtual Task OnInitializedAsync(AppDbContext context)
{
return Task.FromResult(Task.CompletedTask);
}
public async Task DisposeAsync()
{
if (MariaDbContainer is not null)
{
await MariaDbContainer.StopAsync();
await MariaDbContainer.DisposeAsync();
}
}
public AppDbContext CreateDbContext()
{
MySqlServerVersion serverVersion = new(new Version(MajorVersion, MinorVersion, Build));
DbContextOptions<AppDbContext> options = new DbContextOptionsBuilder<AppDbContext>()
.UseMySql(ConnectionString, serverVersion,
o => o.EnableRetryOnFailure())
.EnableSensitiveDataLogging()
.Options;
return new AppDbContext(options);
}
public async Task ResetAsync()
{
await using AppDbContext context = CreateDbContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
}
}

View File

@@ -0,0 +1,65 @@
using JSMR.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace JSMR.Tests.Fixtures;
public class SearchProviderFixture : MariaDbFixture
{
protected override async Task OnInitializedAsync(AppDbContext context)
{
await SeedAsync(context);
}
private static async Task SeedAsync(AppDbContext context)
{
// Make seeding idempotent (quick existence check)
if (await context.Circles.AnyAsync())
return;
context.Circles.AddRange(
new() { CircleId = 1, Name = "Good Dreams", MakerId = "RG00001" },
new() { CircleId = 2, Name = "Sweet Dreams", Favorite = true, MakerId = "RG00002" },
new() { CircleId = 3, Name = "Nightmare Fuel", Blacklisted = true, MakerId = "RG00003" }
);
//context.VoiceWorks.AddRange(
// new() { VoiceWorkId = 1, CircleId = 1, ProductId = "RJ0000001", ProductName = "Today Sounds", Description = "An average product.", Status = (byte)VoiceWorkStatus.Available },
// new() { VoiceWorkId = 2, CircleId = 2, ProductId = "RJ0000002", ProductName = "Super Comfy ASMR", Description = "An amazing product!", Status = (byte)VoiceWorkStatus.NewRelease },
// new() { VoiceWorkId = 4, CircleId = 3, ProductId = "RJ0000003", ProductName = "Low Effort", Description = "A bad product.", Status = (byte)VoiceWorkStatus.Available },
// new() { VoiceWorkId = 5, CircleId = 1, ProductId = "RJ0000004", ProductName = "Tomorrow Sounds", Description = "A average upcoming product.", Status = (byte)VoiceWorkStatus.Upcoming },
// new() { VoiceWorkId = 6, CircleId = 2, ProductId = "RJ0000005", ProductName = "Super Comfy ASMR+", Description = "All your favorite sounds, plus more!", Status = (byte)VoiceWorkStatus.NewAndUpcoming }
//);
context.Tags.AddRange(
new() { TagId = 1, Name = "ASMR" },
new() { TagId = 2, Name = "OL" },
new() { TagId = 3, Name = "ほのぼの" },
new() { TagId = 4, Name = "エルフ/妖精" },
new() { TagId = 5, Name = "ツンデレ", Favorite = true },
new() { TagId = 6, Name = "オールハッピー" },
new() { TagId = 7, Name = "ギャル" },
new() { TagId = 8, Name = "メイド" }
);
context.EnglishTags.AddRange(
new() { EnglishTagId = 1, TagId = 1, Name = "ASMR" },
new() { EnglishTagId = 2, TagId = 2, Name = "Office Lady" },
new() { EnglishTagId = 3, TagId = 3, Name = "Heartwarming" },
new() { EnglishTagId = 4, TagId = 4, Name = "Elf / Fairy" },
new() { EnglishTagId = 5, TagId = 5, Name = "Tsundere" },
new() { EnglishTagId = 6, TagId = 6, Name = "All Happy" },
new() { EnglishTagId = 7, TagId = 7, Name = "Gal" },
new() { EnglishTagId = 8, TagId = 8, Name = "Maid" }
);
context.Creators.AddRange(
new() { CreatorId = 1, Name = "陽向葵ゅか", Favorite = true },
new() { CreatorId = 2, Name = "秋野かえで" },
new() { CreatorId = 3, Name = "柚木つばめ" },
new() { CreatorId = 4, Name = "逢坂成美" },
new() { CreatorId = 5, Name = "山田じぇみ子", Blacklisted = true }
);
await context.SaveChangesAsync();
}
}