From a111e5cc203efb84e6261d25099747aad64a154a Mon Sep 17 00:00:00 2001 From: Niek Otten Date: Tue, 30 Jun 2026 15:11:06 +0200 Subject: [PATCH] test(event-subscriber): ratchet projector mutation baseline to 100% (refs #7) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sharpen the projector tests so Stryker has no survivors (was 75%): assert a replayed delivery never reaches the store (upsert count, not just row count), that two distinct zaken get distinct rows (pins the idempotency key), that rebuild clears stale rows, and a Theory over wrong kanaal/resource/actie combinations (pins the zaken/zaak/create guard). Add the per-service Stryker config + solution; break threshold 90 (CLAUDE.md §5). Co-Authored-By: Claude Opus 4.8 (1M context) --- .../EventSubscriber.Tests/InMemoryStores.cs | 5 ++ .../NotificationProjectorTests.cs | 56 +++++++++++++------ .../event-subscriber/EventSubscriber.slnx | 4 ++ services/event-subscriber/stryker-config.json | 12 ++++ 4 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 services/event-subscriber/EventSubscriber.slnx create mode 100644 services/event-subscriber/stryker-config.json diff --git a/services/event-subscriber/EventSubscriber.Tests/InMemoryStores.cs b/services/event-subscriber/EventSubscriber.Tests/InMemoryStores.cs index 4972de2..618e78f 100644 --- a/services/event-subscriber/EventSubscriber.Tests/InMemoryStores.cs +++ b/services/event-subscriber/EventSubscriber.Tests/InMemoryStores.cs @@ -20,8 +20,13 @@ internal sealed class InMemoryProjectionStore : IProjectionStore { private readonly Dictionary _byId = []; + /// How many times a write was attempted — lets a test prove a deduped delivery + /// never reaches the store (an idempotent upsert hides the difference in row count alone). + public int UpsertCount { get; private set; } + public Task UpsertAsync(RegisterEntry entry, CancellationToken ct = default) { + UpsertCount++; _byId[entry.Id] = entry; return Task.CompletedTask; } diff --git a/services/event-subscriber/EventSubscriber.Tests/NotificationProjectorTests.cs b/services/event-subscriber/EventSubscriber.Tests/NotificationProjectorTests.cs index daca566..65d1092 100644 --- a/services/event-subscriber/EventSubscriber.Tests/NotificationProjectorTests.cs +++ b/services/event-subscriber/EventSubscriber.Tests/NotificationProjectorTests.cs @@ -38,32 +38,52 @@ public sealed class NotificationProjectorTests } [Fact] - public async Task a_notification_on_another_kanaal_is_ignored() - { - await Projector().HandleAsync(new Notification("documenten", "enkelvoudiginformatieobject", "create", new Uri(ZaakUrl))); - - Assert.Empty(await _store.AllAsync()); - } - - [Fact] - public async Task a_zaak_update_is_ignored_by_the_minimal_projection() - { - await Projector().HandleAsync(new Notification("zaken", "zaak", "update", new Uri(ZaakUrl))); - - Assert.Empty(await _store.AllAsync()); - } - - [Fact] - public async Task rebuild_repopulates_the_projection_from_the_notification_log() + public async Task a_replayed_notification_never_reaches_the_projection_store() { var projector = Projector(); await projector.HandleAsync(ZaakCreated()); - await _store.ClearAsync(); + await projector.HandleAsync(ZaakCreated()); + + // The duplicate is dropped at the log, before the (idempotent) upsert — so the store + // is written exactly once. Row count alone can't see this; the upsert count can. + Assert.Equal(1, _store.UpsertCount); + } + + [Fact] + public async Task two_different_zaken_each_get_their_own_row() + { + var projector = Projector(); + await projector.HandleAsync(ZaakCreated()); + await projector.HandleAsync(ZaakCreated(ZaakUrl[..^1] + "2")); // a distinct zaak url + + Assert.Equal(2, (await _store.AllAsync()).Count); + } + + [Theory] + [InlineData("documenten", "enkelvoudiginformatieobject", "create")] // wrong kanaal + resource + [InlineData("documenten", "zaak", "create")] // wrong kanaal only + [InlineData("zaken", "status", "create")] // wrong resource only + [InlineData("zaken", "zaak", "update")] // wrong actie + [InlineData("zaken", "zaak", "destroy")] // wrong actie + public async Task only_a_zaken_zaak_create_notification_is_projected(string kanaal, string resource, string actie) + { + await Projector().HandleAsync(new Notification(kanaal, resource, actie, new Uri(ZaakUrl))); + Assert.Empty(await _store.AllAsync()); + } + + [Fact] + public async Task rebuild_clears_stale_rows_and_repopulates_from_the_notification_log() + { + var projector = Projector(); + await projector.HandleAsync(ZaakCreated()); + // A stale row that is not backed by any logged notification must not survive a rebuild. + await _store.UpsertAsync(new RegisterEntry("stale-9999", RegistrationStatus.Ingediend)); await projector.RebuildAsync(); var entry = Assert.Single(await _store.AllAsync()); + Assert.Equal("11111111-1111-1111-1111-111111111111", entry.Id); Assert.Equal(RegistrationStatus.Ingediend, entry.Status); } } diff --git a/services/event-subscriber/EventSubscriber.slnx b/services/event-subscriber/EventSubscriber.slnx new file mode 100644 index 0000000..0f26041 --- /dev/null +++ b/services/event-subscriber/EventSubscriber.slnx @@ -0,0 +1,4 @@ + + + + diff --git a/services/event-subscriber/stryker-config.json b/services/event-subscriber/stryker-config.json new file mode 100644 index 0000000..c99d4e4 --- /dev/null +++ b/services/event-subscriber/stryker-config.json @@ -0,0 +1,12 @@ +{ + "stryker-config": { + "solution": "EventSubscriber.slnx", + "test-projects": ["EventSubscriber.Tests/EventSubscriber.Tests.csproj"], + "reporters": ["progress", "html"], + "thresholds": { + "high": 95, + "low": 90, + "break": 90 + } + } +}