feat(domain): withdrawal cancels the registratie process (S-11b, refs #12) #89

Merged
not merged 9 commits from feat/12-withdrawal-workflow into main 2026-07-16 11:09:29 +00:00
5 changed files with 78 additions and 9 deletions
Showing only changes of commit 2a6874ef6d - Show all commits

View File

@@ -19,7 +19,7 @@ public class BeoordeelRegistratieTests
} }
private static FakeUserTaskClient TaskFor(Registration registration) => private static FakeUserTaskClient TaskFor(Registration registration) =>
new([new BeoordelingTask("task-1", registration.Id)]); new([new BeoordelingTask("task-1", "exec-1", registration.Id)]);
[Fact] [Fact]
public async Task Goedkeuren_sets_the_zaak_status_via_the_acl_and_marks_the_registration_ingeschreven() public async Task Goedkeuren_sets_the_zaak_status_via_the_acl_and_marks_the_registration_ingeschreven()

View File

@@ -47,6 +47,7 @@ internal sealed class FakeUserTaskClient(IReadOnlyList<BeoordelingTask> open) :
{ {
public (string TaskId, string Behandelaar)? Claimed { get; private set; } public (string TaskId, string Behandelaar)? Claimed { get; private set; }
public (string TaskId, BeoordelingsBesluit Besluit)? Completed { get; private set; } public (string TaskId, BeoordelingsBesluit Besluit)? Completed { get; private set; }
public string? WithdrawnExecutionId { get; private set; }
public Task<IReadOnlyList<BeoordelingTask>> GetOpenBeoordelingenAsync(CancellationToken ct = default) public Task<IReadOnlyList<BeoordelingTask>> GetOpenBeoordelingenAsync(CancellationToken ct = default)
=> Task.FromResult(open); => Task.FromResult(open);
@@ -62,6 +63,12 @@ internal sealed class FakeUserTaskClient(IReadOnlyList<BeoordelingTask> open) :
Completed = (taskId, besluit); Completed = (taskId, besluit);
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task WithdrawBeoordelingAsync(string executionId, CancellationToken ct = default)
{
WithdrawnExecutionId = executionId;
return Task.CompletedTask;
}
} }
/// <summary>A fake ACL client that records the bsn it was asked to open a zaak for and returns a /// <summary>A fake ACL client that records the bsn it was asked to open a zaak for and returns a

View File

@@ -158,13 +158,14 @@ public class FlowableWorkflowClientTests
var capture = new RequestCapture(); var capture = new RequestCapture();
var client = Client(capture.Responds(HttpStatusCode.OK, var client = Client(capture.Responds(HttpStatusCode.OK,
$$""" $$"""
{"data":[{"id":"task-1","variables":[{"name":"registrationId","type":"string","value":"{{rid}}"}]}],"total":1} {"data":[{"id":"task-1","executionId":"exec-1","variables":[{"name":"registrationId","type":"string","value":"{{rid}}"}]}],"total":1}
""")); """));
var tasks = await client.GetOpenBeoordelingenAsync(); var tasks = await client.GetOpenBeoordelingenAsync();
var task = Assert.Single(tasks); var task = Assert.Single(tasks);
Assert.Equal("task-1", task.TaskId); Assert.Equal("task-1", task.TaskId);
Assert.Equal("exec-1", task.ExecutionId);
Assert.Equal(rid, task.RegistrationId); Assert.Equal(rid, task.RegistrationId);
Assert.Equal(HttpMethod.Post, capture.Seen!.Method); Assert.Equal(HttpMethod.Post, capture.Seen!.Method);
Assert.Equal("http://flowable/flowable-rest/service/query/tasks", Assert.Equal("http://flowable/flowable-rest/service/query/tasks",
@@ -242,6 +243,32 @@ public class FlowableWorkflowClientTests
Assert.Contains($"\"value\":\"{expected}\"", capture.Body); Assert.Contains($"\"value\":\"{expected}\"", capture.Body);
} }
[Fact]
public async Task Withdraw_beoordeling_delivers_the_message_to_the_task_execution()
{
var capture = new RequestCapture();
var client = Client(capture.Responds(HttpStatusCode.OK));
await client.WithdrawBeoordelingAsync("exec-1");
// A PUT messageEventReceived on the execution trips the Beoordelen boundary event (ADR-0014).
Assert.Equal(HttpMethod.Put, capture.Seen!.Method);
Assert.Equal("http://flowable/flowable-rest/service/runtime/executions/exec-1",
capture.Seen.RequestUri!.ToString());
Assert.Equal("rest-admin:test", DecodeBasic(capture.Seen));
Assert.Contains("\"action\":\"messageEventReceived\"", capture.Body);
Assert.Contains("\"messageName\":\"RegistratieIngetrokken\"", capture.Body);
}
[Fact]
public async Task Withdraw_beoordeling_throws_when_flowable_rejects_the_request()
{
var capture = new RequestCapture();
var client = Client(capture.Responds(HttpStatusCode.InternalServerError));
await Assert.ThrowsAsync<HttpRequestException>(() => client.WithdrawBeoordelingAsync("exec-1"));
}
[Fact] [Fact]
public async Task Complete_beoordeling_throws_when_flowable_rejects_the_request() public async Task Complete_beoordeling_throws_when_flowable_rejects_the_request()
{ {

View File

@@ -18,7 +18,7 @@ public class WerkbakTests
registration.AttachZaak(FakeAclClient.DefaultZaakUrl); registration.AttachZaak(FakeAclClient.DefaultZaakUrl);
registration.TakeIntoBehandeling(); registration.TakeIntoBehandeling();
store.Seed(registration); store.Seed(registration);
var tasks = new FakeUserTaskClient([new BeoordelingTask("task-1", registration.Id)]); var tasks = new FakeUserTaskClient([new BeoordelingTask("task-1", "exec-1",registration.Id)]);
var werkbak = new Werkbak(tasks, store); var werkbak = new Werkbak(tasks, store);
var items = await werkbak.GetAsync(); var items = await werkbak.GetAsync();
@@ -41,7 +41,7 @@ public class WerkbakTests
public async Task Skips_a_task_whose_registration_is_unknown() public async Task Skips_a_task_whose_registration_is_unknown()
{ {
// Defensive: the werkbak never invents an item for a task the domain has no aggregate for. // Defensive: the werkbak never invents an item for a task the domain has no aggregate for.
var tasks = new FakeUserTaskClient([new BeoordelingTask("task-1", RegistrationId.New())]); var tasks = new FakeUserTaskClient([new BeoordelingTask("task-1", "exec-1",RegistrationId.New())]);
var werkbak = new Werkbak(tasks, new FakeRegistrationStore()); var werkbak = new Werkbak(tasks, new FakeRegistrationStore());
Assert.Empty(await werkbak.GetAsync()); Assert.Empty(await werkbak.GetAsync());
@@ -56,7 +56,7 @@ public class WerkbakTests
var registration = Registration.Submit("123456782"); var registration = Registration.Submit("123456782");
registration.Withdraw(); registration.Withdraw();
store.Seed(registration); store.Seed(registration);
var tasks = new FakeUserTaskClient([new BeoordelingTask("task-1", registration.Id)]); var tasks = new FakeUserTaskClient([new BeoordelingTask("task-1", "exec-1",registration.Id)]);
var werkbak = new Werkbak(tasks, store); var werkbak = new Werkbak(tasks, store);
Assert.Empty(await werkbak.GetAsync()); Assert.Empty(await werkbak.GetAsync());

View File

@@ -5,13 +5,15 @@ namespace Big.Tests;
public class WithdrawRegistrationTests public class WithdrawRegistrationTests
{ {
private static FakeUserTaskClient NoTasks() => new([]);
[Fact] [Fact]
public async Task Withdrawing_marks_the_registration_ingetrokken_and_persists_it() public async Task Withdrawing_marks_the_registration_ingetrokken_and_persists_it()
{ {
var store = new FakeRegistrationStore(); var store = new FakeRegistrationStore();
var registration = Registration.Submit("123456782"); var registration = Registration.Submit("123456782");
store.Seed(registration); store.Seed(registration);
var handler = new WithdrawRegistration(store); var handler = new WithdrawRegistration(store, NoTasks());
await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id)); await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id));
@@ -20,11 +22,44 @@ public class WithdrawRegistrationTests
Assert.Equal(1, store.SaveCount); Assert.Equal(1, store.SaveCount);
} }
[Fact]
public async Task Withdrawing_cancels_the_open_beoordelen_task_via_its_execution()
{
var store = new FakeRegistrationStore();
var registration = Registration.Submit("123456782");
store.Seed(registration);
var tasks = new FakeUserTaskClient([new BeoordelingTask("task-1", "exec-1", registration.Id)]);
var handler = new WithdrawRegistration(store, tasks);
await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id));
// The withdrawal message is delivered to the Beoordelen task's execution, tripping the
// boundary event that ends the process (ADR-0014).
Assert.Equal("exec-1", tasks.WithdrawnExecutionId);
}
[Fact]
public async Task Withdrawing_with_no_open_task_still_marks_ingetrokken()
{
// If the process has not parked at Beoordelen yet (or already ended), the withdrawal stands:
// the aggregate is INGETROKKEN and nothing is cancelled.
var store = new FakeRegistrationStore();
var registration = Registration.Submit("123456782");
store.Seed(registration);
var tasks = NoTasks();
var handler = new WithdrawRegistration(store, tasks);
await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id));
Assert.Equal(RegistrationStatus.Ingetrokken, (await store.GetAsync(registration.Id))!.Status);
Assert.Null(tasks.WithdrawnExecutionId);
}
[Fact] [Fact]
public async Task Rejects_a_null_command_without_touching_the_store() public async Task Rejects_a_null_command_without_touching_the_store()
{ {
var store = new FakeRegistrationStore(); var store = new FakeRegistrationStore();
var handler = new WithdrawRegistration(store); var handler = new WithdrawRegistration(store, NoTasks());
await Assert.ThrowsAsync<ArgumentNullException>(() => handler.HandleAsync(null!)); await Assert.ThrowsAsync<ArgumentNullException>(() => handler.HandleAsync(null!));
Assert.Equal(0, store.SaveCount); Assert.Equal(0, store.SaveCount);
@@ -34,7 +69,7 @@ public class WithdrawRegistrationTests
public async Task Withdrawing_an_unknown_registration_throws() public async Task Withdrawing_an_unknown_registration_throws()
{ {
var store = new FakeRegistrationStore(); var store = new FakeRegistrationStore();
var handler = new WithdrawRegistration(store); var handler = new WithdrawRegistration(store, NoTasks());
var ex = await Assert.ThrowsAsync<InvalidOperationException>( var ex = await Assert.ThrowsAsync<InvalidOperationException>(
() => handler.HandleAsync(new WithdrawRegistrationCommand(RegistrationId.New()))); () => handler.HandleAsync(new WithdrawRegistrationCommand(RegistrationId.New())));
@@ -48,7 +83,7 @@ public class WithdrawRegistrationTests
var store = new FakeRegistrationStore(); var store = new FakeRegistrationStore();
var registration = Registration.Submit("123456782"); var registration = Registration.Submit("123456782");
store.Seed(registration); store.Seed(registration);
var handler = new WithdrawRegistration(store); var handler = new WithdrawRegistration(store, NoTasks());
await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id)); await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id));
await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id)); await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id));