test(event-subscriber): the projection is sourced from register records (refs #153)
Ports, schema and failing tests for the subscriber half of S-19b-2, ahead of the implementation. The subscriber now listens on the `objecten` kanaal instead of `zaken`. An Objecten notification carries no record data — only the object URL — so the record is read back through the ACL (§8.1), and the zaak-shaped surface goes away: IsZaakCreated / IsZaakStatusSet / ZaakUrl / ZaakId and ToEntry's `Resource == "status"` mapping are replaced by IsRegisterRecordWritten + ObjectUrl. The notification log now holds the projected row itself (register id, status, reference), so a rebuild is a replay with no mapping rules and no upstream reads. The migration drops the old columns rather than renaming them — EF scaffolded renames that would have carried ZGW values into columns meaning something else — and empties both tables, since a pre-slice row is neither reprojectable nor re-derivable from the new source. Red: HandleAsync recognises a register write but does not yet read or project it, so the seven projection assertions fail on an empty store.
This commit is contained in:
@@ -2,13 +2,14 @@ using EventSubscriber.Application;
|
||||
|
||||
namespace EventSubscriber.Tests;
|
||||
|
||||
/// <summary>Behaviour of the projector that turns NRC notifications into projection rows.
|
||||
/// The walking skeleton reacts only to a zaak being created (status INGEDIEND) and must
|
||||
/// tolerate duplicate and out-of-order deliveries (CLAUDE.md §8.6).</summary>
|
||||
/// <summary>Behaviour of the projector that turns NRC notifications into projection rows. Since
|
||||
/// S-19b-2 the source is the register in Objecten (ADR-0030), not ZGW zaak events: a notification
|
||||
/// carries only the object URL, so the record is read back through the ACL. Duplicate and
|
||||
/// out-of-order deliveries must be tolerated (CLAUDE.md §8.6).</summary>
|
||||
public sealed class NotificationProjectorTests
|
||||
{
|
||||
private const string ZaakUrl = "http://openzaak:8000/zaken/api/v1/zaken/11111111-1111-1111-1111-111111111111";
|
||||
private const string StatusUrl = "http://openzaak:8000/zaken/api/v1/statussen/22222222-2222-2222-2222-222222222222";
|
||||
private const string ObjectUrl = "http://objecten.local:8000/api/v2/objects/11111111-1111-1111-1111-111111111111";
|
||||
private const string ZaakId = "99999999-9999-9999-9999-999999999999";
|
||||
|
||||
private readonly InMemoryNotificationLog _log = new();
|
||||
private readonly InMemoryProjectionStore _store = new();
|
||||
@@ -16,46 +17,56 @@ public sealed class NotificationProjectorTests
|
||||
|
||||
private NotificationProjector Projector() => new(_log, _store, _acl);
|
||||
|
||||
private static Notification ZaakCreated(string url = ZaakUrl)
|
||||
=> new("zaken", "zaak", "create", new Uri(url));
|
||||
|
||||
// A status-set notification: resourceUrl is the status resource, hoofdObject is the zaak it belongs to.
|
||||
private static Notification StatusSet(string zaakUrl = ZaakUrl, string statusUrl = StatusUrl)
|
||||
=> new("zaken", "status", "create", new Uri(statusUrl), new Uri(zaakUrl));
|
||||
|
||||
[Fact]
|
||||
public async Task creating_a_zaak_writes_one_row_with_status_ingediend()
|
||||
/// <summary>A register write as Objecten publishes it: the object is both hoofdObject and
|
||||
/// resourceUrl, and the record itself is only reachable by reading that object.</summary>
|
||||
private Notification RecordWritten(string actie = "create", string url = ObjectUrl, string status = RegistrationStatus.Ingediend, string zaakId = ZaakId)
|
||||
{
|
||||
await Projector().HandleAsync(ZaakCreated());
|
||||
|
||||
var entry = Assert.Single(await _store.AllAsync());
|
||||
Assert.Equal("11111111-1111-1111-1111-111111111111", entry.Id);
|
||||
Assert.Equal(RegistrationStatus.Ingediend, entry.Status);
|
||||
// Enriched with the zaak's reference (identificatie), fetched via the ACL (#78).
|
||||
Assert.Equal("REG-11111111-1111-1111-1111-111111111111", entry.Reference);
|
||||
_acl.Records[url] = new RegisterRecord(zaakId, status, "REG-2026-0001");
|
||||
return new Notification("objecten", "object", actie, new Uri(url), new Uri(url));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task rebuild_reproduces_the_reference_without_re_reading_via_the_acl()
|
||||
public async Task a_register_record_write_is_projected_as_a_row_keyed_on_the_registration()
|
||||
{
|
||||
var projector = Projector();
|
||||
await projector.HandleAsync(ZaakCreated());
|
||||
var callsAfterProjection = _acl.CallCount;
|
||||
|
||||
await projector.RebuildAsync();
|
||||
await Projector().HandleAsync(RecordWritten());
|
||||
|
||||
var entry = Assert.Single(await _store.AllAsync());
|
||||
Assert.Equal("REG-11111111-1111-1111-1111-111111111111", entry.Reference);
|
||||
// Rebuild replays the log (which stored the reference) — no extra ACL calls (#78, ADR-0008).
|
||||
Assert.Equal(callsAfterProjection, _acl.CallCount);
|
||||
// Keyed on the record's own id (the zaak id), not on the Objecten object's uuid — the
|
||||
// projection row and the register record are the same registration.
|
||||
Assert.Equal(ZaakId, entry.Id);
|
||||
Assert.Equal(RegistrationStatus.Ingediend, entry.Status);
|
||||
Assert.Equal("REG-2026-0001", entry.Reference);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task approval_updates_the_same_row_from_ingediend_to_ingeschreven()
|
||||
{
|
||||
var projector = Projector();
|
||||
await projector.HandleAsync(RecordWritten());
|
||||
// The ACL PATCHes the same object on approval, so Objecten publishes an `update`.
|
||||
await projector.HandleAsync(RecordWritten("update", status: RegistrationStatus.Ingeschreven));
|
||||
|
||||
var entry = Assert.Single(await _store.AllAsync());
|
||||
Assert.Equal(ZaakId, entry.Id);
|
||||
Assert.Equal(RegistrationStatus.Ingeschreven, entry.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task an_object_whose_record_is_gone_is_not_projected()
|
||||
{
|
||||
// Nothing seeded in the fake ACL: the object was deleted before this (redelivered)
|
||||
// notification was handled. Not an error — there is simply nothing to project (§8.6).
|
||||
await Projector().HandleAsync(new Notification("objecten", "object", "create", new Uri(ObjectUrl)));
|
||||
|
||||
Assert.Empty(await _store.AllAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task replaying_the_same_notification_keeps_a_single_row()
|
||||
{
|
||||
var projector = Projector();
|
||||
await projector.HandleAsync(ZaakCreated());
|
||||
await projector.HandleAsync(ZaakCreated());
|
||||
await projector.HandleAsync(RecordWritten());
|
||||
await projector.HandleAsync(RecordWritten());
|
||||
|
||||
Assert.Single(await _store.AllAsync());
|
||||
}
|
||||
@@ -64,8 +75,8 @@ public sealed class NotificationProjectorTests
|
||||
public async Task a_replayed_notification_never_reaches_the_projection_store()
|
||||
{
|
||||
var projector = Projector();
|
||||
await projector.HandleAsync(ZaakCreated());
|
||||
await projector.HandleAsync(ZaakCreated());
|
||||
await projector.HandleAsync(RecordWritten());
|
||||
await projector.HandleAsync(RecordWritten());
|
||||
|
||||
// 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.
|
||||
@@ -73,77 +84,59 @@ public sealed class NotificationProjectorTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task two_different_zaken_each_get_their_own_row()
|
||||
public async Task two_different_registrations_each_get_their_own_row()
|
||||
{
|
||||
var projector = Projector();
|
||||
await projector.HandleAsync(ZaakCreated());
|
||||
await projector.HandleAsync(ZaakCreated(ZaakUrl[..^1] + "2")); // a distinct zaak url
|
||||
await projector.HandleAsync(RecordWritten());
|
||||
await projector.HandleAsync(RecordWritten(url: ObjectUrl[..^1] + "2", zaakId: "other-zaak"));
|
||||
|
||||
Assert.Equal(2, (await _store.AllAsync()).Count);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("documenten", "enkelvoudiginformatieobject", "create")] // wrong kanaal + resource
|
||||
[InlineData("documenten", "zaak", "create")] // wrong kanaal only
|
||||
[InlineData("zaken", "zaak", "update")] // wrong actie
|
||||
[InlineData("zaken", "zaak", "destroy")] // wrong actie
|
||||
[InlineData("zaken", "status", "update")] // a status change we ignore
|
||||
[InlineData("zaken", "resultaat", "create")] // not a status we project
|
||||
[InlineData("zaken", "zaak", "create")] // the ZGW source S-19b-2 replaced
|
||||
[InlineData("zaken", "status", "create")] // ditto
|
||||
[InlineData("objecten", "object", "destroy")] // a delete we do not project
|
||||
[InlineData("documenten", "object", "create")] // wrong kanaal
|
||||
public async Task an_unrelated_notification_is_not_projected(string kanaal, string resource, string actie)
|
||||
{
|
||||
await Projector().HandleAsync(new Notification(kanaal, resource, actie, new Uri(ZaakUrl)));
|
||||
_acl.Records[ObjectUrl] = new RegisterRecord(ZaakId, RegistrationStatus.Ingediend, "REG-2026-0001");
|
||||
|
||||
await Projector().HandleAsync(new Notification(kanaal, resource, actie, new Uri(ObjectUrl)));
|
||||
|
||||
Assert.Empty(await _store.AllAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task setting_a_status_projects_ingeschreven_keyed_on_the_zaak_not_the_status()
|
||||
{
|
||||
await Projector().HandleAsync(StatusSet());
|
||||
|
||||
var entry = Assert.Single(await _store.AllAsync());
|
||||
// Keyed on the zaak (hoofdObject), not the status resource URL.
|
||||
Assert.Equal("11111111-1111-1111-1111-111111111111", entry.Id);
|
||||
Assert.Equal(RegistrationStatus.Ingeschreven, entry.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task approving_updates_the_existing_zaak_row_from_ingediend_to_ingeschreven()
|
||||
public async Task rebuild_reproduces_the_row_without_re_reading_through_the_acl()
|
||||
{
|
||||
var projector = Projector();
|
||||
await projector.HandleAsync(ZaakCreated());
|
||||
await projector.HandleAsync(StatusSet());
|
||||
|
||||
var entry = Assert.Single(await _store.AllAsync());
|
||||
Assert.Equal("11111111-1111-1111-1111-111111111111", entry.Id);
|
||||
Assert.Equal(RegistrationStatus.Ingeschreven, entry.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task rebuild_reproduces_the_approved_status()
|
||||
{
|
||||
var projector = Projector();
|
||||
await projector.HandleAsync(ZaakCreated());
|
||||
await projector.HandleAsync(StatusSet());
|
||||
await projector.HandleAsync(RecordWritten());
|
||||
await projector.HandleAsync(RecordWritten("update", status: RegistrationStatus.Ingeschreven));
|
||||
var callsAfterProjection = _acl.CallCount;
|
||||
|
||||
await projector.RebuildAsync();
|
||||
|
||||
var entry = Assert.Single(await _store.AllAsync());
|
||||
Assert.Equal(RegistrationStatus.Ingeschreven, entry.Status);
|
||||
Assert.Equal("REG-2026-0001", entry.Reference);
|
||||
// The log holds the projected row itself, so a rebuild needs neither the ACL nor
|
||||
// Objecten (§8.4, ADR-0030).
|
||||
Assert.Equal(callsAfterProjection, _acl.CallCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task rebuild_clears_stale_rows_and_repopulates_from_the_notification_log()
|
||||
{
|
||||
var projector = Projector();
|
||||
await projector.HandleAsync(ZaakCreated());
|
||||
await projector.HandleAsync(RecordWritten());
|
||||
// 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(ZaakId, entry.Id);
|
||||
Assert.Equal(RegistrationStatus.Ingediend, entry.Status);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user