Files
register-referentie/services/domain/Big.Tests/SubmitRegistrationTests.cs
Niek Otten 6955e0ff98 feat(workflow): emit diplomaOrigin start variable + accept it on submit (S-13, refs #14)
The Workflow Client now posts diplomaOrigin alongside registrationId when starting
the process, and the domain submit endpoint accepts an optional diplomaOrigin
(defaulting to domestic) so a foreign submission can be driven end-to-end. Adds the
aggregate + submit-forwarding tests now that the plumbing is in place.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-17 11:55:45 +02:00

80 lines
3.0 KiB
C#

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 FakeRegistrationStore();
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);
// Persisted twice: once before starting the process, once after recording the instance id.
Assert.Equal(2, store.SaveCount);
}
[Fact]
public async Task Submitting_a_foreign_diploma_carries_its_origin_to_the_process()
{
var store = new FakeRegistrationStore();
var workflow = new FakeWorkflowClient();
var handler = new SubmitRegistration(store, workflow);
var id = await handler.HandleAsync(new SubmitRegistrationCommand("123456782", DiplomaOrigin.Buitenlands));
Assert.Equal(DiplomaOrigin.Buitenlands, (await store.GetAsync(id))!.DiplomaOrigin);
Assert.Equal(DiplomaOrigin.Buitenlands, workflow.StartedWithOrigin);
}
[Fact]
public async Task Rejects_a_null_command_without_touching_the_store_or_workflow()
{
var store = new FakeRegistrationStore();
var workflow = new FakeWorkflowClient();
var handler = new SubmitRegistration(store, workflow);
await Assert.ThrowsAsync<ArgumentNullException>(() => handler.HandleAsync(null!));
Assert.Equal(0, store.SaveCount);
Assert.Null(workflow.StartedFor);
}
[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 FakeRegistrationStore();
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 FakeRegistrationStore();
var workflow = new FakeWorkflowClient();
var handler = new SubmitRegistration(store, workflow);
await Assert.ThrowsAnyAsync<ArgumentException>(
() => handler.HandleAsync(new SubmitRegistrationCommand("")));
Assert.Null(workflow.StartedFor);
}
}