feat(data): seed default Lists (My Day, Important, Planned)

This commit is contained in:
mika kuns
2026-04-20 10:02:07 +02:00
parent 928dde1358
commit bd8a4d0565
4 changed files with 72 additions and 2 deletions

View File

@@ -0,0 +1,41 @@
using ClaudeDo.Data;
using ClaudeDo.Data.Seeding;
using Microsoft.EntityFrameworkCore;
using Xunit;
namespace ClaudeDo.Worker.Tests.UiSchema;
public class DefaultListSeedTests : IDisposable
{
private readonly string _dbPath = Path.Combine(Path.GetTempPath(), $"claudedo-seed-{Guid.NewGuid():N}.db");
private ClaudeDoDbContext NewContext()
{
var opts = new DbContextOptionsBuilder<ClaudeDoDbContext>()
.UseSqlite($"Data Source={_dbPath}").Options;
var ctx = new ClaudeDoDbContext(opts);
ctx.Database.EnsureCreated();
return ctx;
}
[Fact]
public async Task Seeds_MyDay_Important_Planned_Lists_Idempotently()
{
await using (var ctx = NewContext())
{
await DefaultListsSeeder.SeedAsync(ctx);
await DefaultListsSeeder.SeedAsync(ctx); // idempotent
}
await using var verify = NewContext();
var names = verify.Lists.Select(l => l.Name).OrderBy(n => n).ToList();
Assert.Equal(new[] { "Important", "My Day", "Planned" }, names);
}
public void Dispose()
{
try { if (File.Exists(_dbPath)) File.Delete(_dbPath); } catch { }
try { if (File.Exists(_dbPath + "-wal")) File.Delete(_dbPath + "-wal"); } catch { }
try { if (File.Exists(_dbPath + "-shm")) File.Delete(_dbPath + "-shm"); } catch { }
}
}