test(domain): SubmitRegistration + OpenZaakWorker use cases (refs #6)
Failing application-layer tests over fake ports (IWorkflowClient, IAclClient, IRegistrationStore): - Submit persists an INGEDIEND registration and starts the registratie process, recording the instance id — and persists *before* starting, so the worker can correlate the OpenZaakAanmaken job back to its aggregate (ADR-0009). - The worker opens a zaak via the ACL and attaches it; an unknown registration throws (job left for redelivery); a redelivered job is idempotent and opens no second zaak (§8.6). Handlers are stubs (no persistence / no ACL call) so the tests compile and fail on their assertions; the green commit implements them. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
52
services/domain/Big.Tests/SubmitRegistrationTests.cs
Normal file
52
services/domain/Big.Tests/SubmitRegistrationTests.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Big.Application;
|
||||
using Big.Domain;
|
||||
|
||||
namespace Big.Tests;
|
||||
|
||||
public class SubmitRegistrationTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Submitting_persists_an_ingediend_registration_and_starts_the_process()
|
||||
{
|
||||
var store = new InMemoryRegistrationStore();
|
||||
var workflow = new FakeWorkflowClient(processInstanceId: "proc-42");
|
||||
var handler = new SubmitRegistration(store, workflow);
|
||||
|
||||
var id = await handler.HandleAsync(new SubmitRegistrationCommand("123456782"));
|
||||
|
||||
var saved = await store.GetAsync(id);
|
||||
Assert.NotNull(saved);
|
||||
Assert.Equal("123456782", saved.Bsn);
|
||||
Assert.Equal(RegistrationStatus.Ingediend, saved.Status);
|
||||
Assert.Equal("proc-42", saved.ProcessInstanceId);
|
||||
Assert.Equal(id, workflow.StartedFor);
|
||||
Assert.Null(saved.ZaakUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Submitting_persists_the_registration_before_starting_the_process()
|
||||
{
|
||||
// The worker correlates the OpenZaakAanmaken job back to the aggregate by id, so the
|
||||
// aggregate must already be persisted when the process starts (ADR-0009).
|
||||
var store = new InMemoryRegistrationStore();
|
||||
Registration? visibleAtStart = null;
|
||||
var workflow = new FakeWorkflowClient(onStart: id => visibleAtStart = store.GetAsync(id).Result);
|
||||
var handler = new SubmitRegistration(store, workflow);
|
||||
|
||||
await handler.HandleAsync(new SubmitRegistrationCommand("123456782"));
|
||||
|
||||
Assert.NotNull(visibleAtStart);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Submitting_without_a_bsn_is_rejected_and_starts_no_process()
|
||||
{
|
||||
var store = new InMemoryRegistrationStore();
|
||||
var workflow = new FakeWorkflowClient();
|
||||
var handler = new SubmitRegistration(store, workflow);
|
||||
|
||||
await Assert.ThrowsAnyAsync<ArgumentException>(
|
||||
() => handler.HandleAsync(new SubmitRegistrationCommand("")));
|
||||
Assert.Null(workflow.StartedFor);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user