Schema: LeaderSkinShopSeries -> Products (owned rewards) + owned SetCompletionRewards on the series; ViewerLeaderSkinSetClaim composite PK (ViewerId, SeriesId) backs the /buy_set_item idempotent-claim check. Importer mirrors SleeveShopImporter: idempotent find-or-create, owned collections rewritten wholesale on rerun. 16 series, 104 products. Controller (extends existing /set with 5 new endpoints): - /products: dict-keyed-by-series_id-string wire shape. is_completed per-viewer, rewards.status from ViewerLeaderSkinSetClaim (0=no set sale, 1=available, 2=claimed) matching client RewardStatus enum. - /buy: single skin, sales_type 1/2 dispatch, 3=>501. - /buy_set: whole series at SetPrice; requires set_sales_status != 0; grants every product's rewards (RewardGrantService idempotent on already-owned cosmetics, so partial-set buys don't double-add). - /buy_set_item: requires viewer owns every skin in series; idempotent on re-claim (returns 200 + empty reward_list, not 400) so client retries don't error. - /ids: flat owned-skin-id list for badge refresh. 496 tests pass (was 486; +10 leader-skin-shop tests). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
66 lines
2.8 KiB
C#
66 lines
2.8 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SVSim.Bootstrap.Importers;
|
|
using SVSim.Database;
|
|
using SVSim.Database.Models;
|
|
using SVSim.UnitTests.Infrastructure;
|
|
|
|
namespace SVSim.UnitTests.Importers;
|
|
|
|
public class LeaderSkinShopImporterTests
|
|
{
|
|
private static string SeedDir => Path.Combine(AppContext.BaseDirectory, "Data", "seeds");
|
|
|
|
[Test]
|
|
public async Task Imports_series_products_and_set_rewards_from_seed_file()
|
|
{
|
|
using var factory = new SVSimTestFactory();
|
|
using var scope = factory.Services.CreateScope();
|
|
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
|
|
|
await new LeaderSkinShopImporter().ImportAsync(db, SeedDir);
|
|
|
|
var series = await db.LeaderSkinShopSeries
|
|
.Include(s => s.SetCompletionRewards)
|
|
.Include(s => s.Products).ThenInclude(p => p.Rewards)
|
|
.OrderBy(s => s.Id)
|
|
.ToListAsync();
|
|
|
|
Assert.That(series.Count, Is.GreaterThan(0));
|
|
|
|
// Spot-check series 100 (Shingeki no Bahamut) — set sale active with 2000c/2000r set price
|
|
var s100 = series.First(s => s.Id == 100);
|
|
Assert.That(s100.SetSalesStatus, Is.EqualTo(1));
|
|
Assert.That(s100.SetPriceCrystal, Is.EqualTo(2000));
|
|
Assert.That(s100.SetPriceRupy, Is.EqualTo(2000));
|
|
Assert.That(s100.Products.Count, Is.GreaterThan(0));
|
|
|
|
// Spot-check a series with set-completion rewards (series 103 in capture has 2)
|
|
var withRewards = series.FirstOrDefault(s => s.SetCompletionRewards.Count > 0);
|
|
Assert.That(withRewards, Is.Not.Null, "at least one series should have set-completion rewards");
|
|
Assert.That(withRewards!.SetCompletionRewards.All(r => r.RewardDetailId > 0), Is.True);
|
|
|
|
// Per-product rewards (the captured shape — skin + emblem + sleeve triplet)
|
|
var firstProduct = s100.Products.OrderBy(p => p.Id).First();
|
|
Assert.That(firstProduct.LeaderSkinId, Is.GreaterThan(0));
|
|
Assert.That(firstProduct.Rewards.Count, Is.EqualTo(3));
|
|
}
|
|
|
|
[Test]
|
|
public async Task Is_idempotent_on_rerun()
|
|
{
|
|
using var factory = new SVSimTestFactory();
|
|
using var scope = factory.Services.CreateScope();
|
|
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
|
|
|
await new LeaderSkinShopImporter().ImportAsync(db, SeedDir);
|
|
int seriesBefore = await db.LeaderSkinShopSeries.CountAsync();
|
|
int productsBefore = await db.LeaderSkinShopProducts.CountAsync();
|
|
|
|
await new LeaderSkinShopImporter().ImportAsync(db, SeedDir);
|
|
|
|
Assert.That(await db.LeaderSkinShopSeries.CountAsync(), Is.EqualTo(seriesBefore));
|
|
Assert.That(await db.LeaderSkinShopProducts.CountAsync(), Is.EqualTo(productsBefore));
|
|
}
|
|
}
|