diff --git a/services/domain/Big.Tests/BeoordeelRegistratieTests.cs b/services/domain/Big.Tests/BeoordeelRegistratieTests.cs index 9ad48de..d86cf8b 100644 --- a/services/domain/Big.Tests/BeoordeelRegistratieTests.cs +++ b/services/domain/Big.Tests/BeoordeelRegistratieTests.cs @@ -19,7 +19,7 @@ public class BeoordeelRegistratieTests } private static FakeUserTaskClient TaskFor(Registration registration) => - new([new BeoordelingTask("task-1", registration.Id)]); + new([new BeoordelingTask("task-1", "exec-1", registration.Id)]); [Fact] public async Task Goedkeuren_sets_the_zaak_status_via_the_acl_and_marks_the_registration_ingeschreven() diff --git a/services/domain/Big.Tests/Fakes.cs b/services/domain/Big.Tests/Fakes.cs index bfd0a54..c866314 100644 --- a/services/domain/Big.Tests/Fakes.cs +++ b/services/domain/Big.Tests/Fakes.cs @@ -47,6 +47,7 @@ internal sealed class FakeUserTaskClient(IReadOnlyList open) : { public (string TaskId, string Behandelaar)? Claimed { get; private set; } public (string TaskId, BeoordelingsBesluit Besluit)? Completed { get; private set; } + public string? WithdrawnExecutionId { get; private set; } public Task> GetOpenBeoordelingenAsync(CancellationToken ct = default) => Task.FromResult(open); @@ -62,6 +63,12 @@ internal sealed class FakeUserTaskClient(IReadOnlyList open) : Completed = (taskId, besluit); return Task.CompletedTask; } + + public Task WithdrawBeoordelingAsync(string executionId, CancellationToken ct = default) + { + WithdrawnExecutionId = executionId; + return Task.CompletedTask; + } } /// A fake ACL client that records the bsn it was asked to open a zaak for and returns a diff --git a/services/domain/Big.Tests/FlowableWorkflowClientTests.cs b/services/domain/Big.Tests/FlowableWorkflowClientTests.cs index f1bf579..6c8ddc0 100644 --- a/services/domain/Big.Tests/FlowableWorkflowClientTests.cs +++ b/services/domain/Big.Tests/FlowableWorkflowClientTests.cs @@ -158,13 +158,14 @@ public class FlowableWorkflowClientTests var capture = new RequestCapture(); 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 task = Assert.Single(tasks); Assert.Equal("task-1", task.TaskId); + Assert.Equal("exec-1", task.ExecutionId); Assert.Equal(rid, task.RegistrationId); Assert.Equal(HttpMethod.Post, capture.Seen!.Method); Assert.Equal("http://flowable/flowable-rest/service/query/tasks", @@ -242,6 +243,32 @@ public class FlowableWorkflowClientTests 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(() => client.WithdrawBeoordelingAsync("exec-1")); + } + [Fact] public async Task Complete_beoordeling_throws_when_flowable_rejects_the_request() { diff --git a/services/domain/Big.Tests/WerkbakTests.cs b/services/domain/Big.Tests/WerkbakTests.cs index 0b3bdcf..cfc8b3c 100644 --- a/services/domain/Big.Tests/WerkbakTests.cs +++ b/services/domain/Big.Tests/WerkbakTests.cs @@ -18,7 +18,7 @@ public class WerkbakTests registration.AttachZaak(FakeAclClient.DefaultZaakUrl); registration.TakeIntoBehandeling(); 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 items = await werkbak.GetAsync(); @@ -41,7 +41,7 @@ public class WerkbakTests 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. - 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()); Assert.Empty(await werkbak.GetAsync()); @@ -56,7 +56,7 @@ public class WerkbakTests var registration = Registration.Submit("123456782"); registration.Withdraw(); 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); Assert.Empty(await werkbak.GetAsync()); diff --git a/services/domain/Big.Tests/WithdrawRegistrationTests.cs b/services/domain/Big.Tests/WithdrawRegistrationTests.cs index 0506db0..eae7852 100644 --- a/services/domain/Big.Tests/WithdrawRegistrationTests.cs +++ b/services/domain/Big.Tests/WithdrawRegistrationTests.cs @@ -5,13 +5,15 @@ namespace Big.Tests; public class WithdrawRegistrationTests { + private static FakeUserTaskClient NoTasks() => new([]); + [Fact] public async Task Withdrawing_marks_the_registration_ingetrokken_and_persists_it() { var store = new FakeRegistrationStore(); var registration = Registration.Submit("123456782"); store.Seed(registration); - var handler = new WithdrawRegistration(store); + var handler = new WithdrawRegistration(store, NoTasks()); await handler.HandleAsync(new WithdrawRegistrationCommand(registration.Id)); @@ -20,11 +22,44 @@ public class WithdrawRegistrationTests 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] public async Task Rejects_a_null_command_without_touching_the_store() { var store = new FakeRegistrationStore(); - var handler = new WithdrawRegistration(store); + var handler = new WithdrawRegistration(store, NoTasks()); await Assert.ThrowsAsync(() => handler.HandleAsync(null!)); Assert.Equal(0, store.SaveCount); @@ -34,7 +69,7 @@ public class WithdrawRegistrationTests public async Task Withdrawing_an_unknown_registration_throws() { var store = new FakeRegistrationStore(); - var handler = new WithdrawRegistration(store); + var handler = new WithdrawRegistration(store, NoTasks()); var ex = await Assert.ThrowsAsync( () => handler.HandleAsync(new WithdrawRegistrationCommand(RegistrationId.New()))); @@ -48,7 +83,7 @@ public class WithdrawRegistrationTests var store = new FakeRegistrationStore(); var registration = Registration.Submit("123456782"); 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));