80 lines
4.2 KiB
C#
80 lines
4.2 KiB
C#
using Flypaper.Storage.Entities;
|
|
using Flypaper.Storage.Research;
|
|
using Flypaper.Tests.Fakes;
|
|
using Flypaper.Tests.Mcp;
|
|
using Shouldly;
|
|
|
|
namespace Flypaper.Tests.Storage;
|
|
|
|
public sealed class ResearchStoreTests : IDisposable
|
|
{
|
|
private readonly McpTestData _data = new();
|
|
private readonly ResearchStore _store;
|
|
|
|
public ResearchStoreTests() => _store = new ResearchStore(_data.Factory, new FixedTimeProvider(McpTestData.Now));
|
|
|
|
[Fact]
|
|
public async Task Entries_are_listed_newest_first_and_filtered_by_kind_and_strategy()
|
|
{
|
|
await _store.CreateEntryAsync(new LabEntryInput("Alt", LabEntryKind.Experiment, "a", new DateTime(2026, 11, 10), Strategies: ["git-drip"]));
|
|
await _store.CreateEntryAsync(new LabEntryInput("Neu", LabEntryKind.Observation, "b", new DateTime(2026, 11, 14), Strategies: ["maze-drip", "git-drip"]));
|
|
await _store.CreateEntryAsync(new LabEntryInput("Heute", LabEntryKind.Experiment, "c"));
|
|
|
|
(await _store.ListEntriesAsync()).Select(e => e.Title).ShouldBe(["Heute", "Neu", "Alt"]);
|
|
(await _store.ListEntriesAsync(LabEntryKind.Experiment)).Select(e => e.Title).ShouldBe(["Heute", "Alt"]);
|
|
(await _store.ListEntriesAsync(strategy: "GIT-drip")).Select(e => e.Title).ShouldBe(["Neu", "Alt"]);
|
|
(await _store.ListEntriesAsync(limit: 1)).ShouldHaveSingleItem().Title.ShouldBe("Heute");
|
|
(await _store.ListEntriesAsync()).First().Date.ShouldBe(McpTestData.Now.UtcDateTime.Date);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Update_changes_only_given_fields_and_empty_values_clear_optional_ones()
|
|
{
|
|
var entry = await _store.CreateEntryAsync(new LabEntryInput("Titel", LabEntryKind.Hypothesis, "Text", Commit: "ABCDEF1", Strategies: ["git-drip"]));
|
|
entry.Commit.ShouldBe("abcdef1");
|
|
|
|
var changed = await _store.UpdateEntryAsync(entry.Id, new LabEntryInput(Text: "Neu"));
|
|
changed.ShouldNotBeNull();
|
|
(changed.Title, changed.Text, changed.Commit, changed.Strategies).ShouldBe(("Titel", "Neu", "abcdef1", "git-drip"));
|
|
|
|
var cleared = await _store.UpdateEntryAsync(entry.Id, new LabEntryInput(Commit: "", Strategies: []));
|
|
cleared.ShouldNotBeNull();
|
|
(cleared.Commit, cleared.Strategies).ShouldBe((null, null));
|
|
|
|
(await _store.UpdateEntryAsync(999, new LabEntryInput(Title: "x"))).ShouldBeNull();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("", "Text", "abc1", "git-drip")]
|
|
[InlineData("Titel", " ", "abc1", "git-drip")]
|
|
[InlineData("Titel", "Text", "not-a-hash", "git-drip")]
|
|
[InlineData("Titel", "Text", "abc1", "Git Drip!")]
|
|
public async Task Invalid_entries_are_rejected(string title, string text, string commit, string strategy) =>
|
|
await Should.ThrowAsync<ArgumentException>(() =>
|
|
_store.CreateEntryAsync(new LabEntryInput(title, LabEntryKind.Method, text, Commit: commit, Strategies: [strategy])));
|
|
|
|
[Fact]
|
|
public async Task Ideas_are_sorted_by_effort_then_efficiency_and_status_sets_implementation_date()
|
|
{
|
|
var hard = await _store.CreateIdeaAsync(new IdeaInput("Schwer", IdeaLevel.High, IdeaLevel.High, "r"));
|
|
var cheap = await _store.CreateIdeaAsync(new IdeaInput("Billig", IdeaLevel.Low, IdeaLevel.Medium, "r"));
|
|
var cheapBetter = await _store.CreateIdeaAsync(new IdeaInput("Billig und gut", IdeaLevel.Low, IdeaLevel.High, "r"));
|
|
|
|
(await _store.ListIdeasAsync()).Select(i => i.Title).ShouldBe(["Billig und gut", "Billig", "Schwer"]);
|
|
|
|
var done = await _store.UpdateIdeaAsync(cheap.Id, new IdeaInput(Status: IdeaStatus.Done, Commit: "abc123"));
|
|
done.ShouldNotBeNull();
|
|
(done.Status, done.ImplementedOn, done.Commit).ShouldBe((IdeaStatus.Done, McpTestData.Now.UtcDateTime.Date, "abc123"));
|
|
|
|
var reopened = await _store.UpdateIdeaAsync(cheap.Id, new IdeaInput(Status: IdeaStatus.Open));
|
|
reopened.ShouldNotBeNull().ImplementedOn.ShouldBeNull();
|
|
|
|
(await _store.ListIdeasAsync(IdeaStatus.Open)).Count.ShouldBe(3);
|
|
hard.Status.ShouldBe(IdeaStatus.Open);
|
|
cheapBetter.Status.ShouldBe(IdeaStatus.Open);
|
|
(await _store.UpdateIdeaAsync(999, new IdeaInput(Status: IdeaStatus.Done))).ShouldBeNull();
|
|
}
|
|
|
|
public void Dispose() => _data.Dispose();
|
|
}
|