feat(data): add ListRepository.DeleteConfigAsync
This commit is contained in:
@@ -88,4 +88,12 @@ public sealed class ListRepository
|
||||
}
|
||||
await _context.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteConfigAsync(string listId, CancellationToken ct = default)
|
||||
{
|
||||
var affected = await _context.ListConfigs
|
||||
.Where(c => c.ListId == listId)
|
||||
.ExecuteDeleteAsync(ct);
|
||||
return affected > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Data.Repositories;
|
||||
using ClaudeDo.Worker.Tests.Infrastructure;
|
||||
using Xunit;
|
||||
|
||||
namespace ClaudeDo.Worker.Tests.Repositories;
|
||||
|
||||
public sealed class ListRepositoryDeleteConfigTests : IDisposable
|
||||
{
|
||||
private readonly DbFixture _db = new();
|
||||
private readonly ClaudeDoDbContext _ctx;
|
||||
private readonly ListRepository _repo;
|
||||
|
||||
public ListRepositoryDeleteConfigTests()
|
||||
{
|
||||
_ctx = _db.CreateContext();
|
||||
_repo = new ListRepository(_ctx);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_ctx.Dispose();
|
||||
_db.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteConfigAsync_RemovesExistingRow()
|
||||
{
|
||||
var listId = Guid.NewGuid().ToString();
|
||||
await _repo.AddAsync(new ListEntity
|
||||
{
|
||||
Id = listId, Name = "L", CreatedAt = DateTime.UtcNow,
|
||||
});
|
||||
await _repo.SetConfigAsync(new ListConfigEntity
|
||||
{
|
||||
ListId = listId,
|
||||
Model = "opus",
|
||||
SystemPrompt = "hello",
|
||||
AgentPath = "/tmp/a.md",
|
||||
});
|
||||
|
||||
var removed = await _repo.DeleteConfigAsync(listId);
|
||||
|
||||
Assert.True(removed);
|
||||
Assert.Null(await _repo.GetConfigAsync(listId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteConfigAsync_ReturnsFalseWhenAbsent()
|
||||
{
|
||||
var removed = await _repo.DeleteConfigAsync(Guid.NewGuid().ToString());
|
||||
|
||||
Assert.False(removed);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user