From 7ceb22d46d8f47da0c4e558511f0cce77869edfe Mon Sep 17 00:00:00 2001 From: Niek Otten Date: Mon, 20 Jul 2026 10:36:21 +0200 Subject: [PATCH] test(domain): providing documents completes the WachtOpDocumenten wait (refs #102) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RED: the ProvideDocuments use case completes the document wait via the Workflow Client, owner-scoped by the caller's bsn (a different bsn is NotFound), and is best-effort when no process was started yet — mirroring WithdrawRegistration. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../domain/Big.Tests/ProvideDocumentsTests.cs | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 services/domain/Big.Tests/ProvideDocumentsTests.cs diff --git a/services/domain/Big.Tests/ProvideDocumentsTests.cs b/services/domain/Big.Tests/ProvideDocumentsTests.cs new file mode 100644 index 0000000..308d863 --- /dev/null +++ b/services/domain/Big.Tests/ProvideDocumentsTests.cs @@ -0,0 +1,85 @@ +using Big.Application; +using Big.Domain; + +namespace Big.Tests; + +// S-10a (#102): the "documents received" use case. A zorgprofessional supplies the documents their +// registration is waiting for; the handler completes the WachtOpDocumenten task via the Workflow Client +// so the process leaves the 30-day wait and continues to beoordeling. Owner-scoped by the caller's bsn, +// like WithdrawRegistration. (The real file upload + ZGW storage is S-10b; this is the trigger path.) +public class ProvideDocumentsTests +{ + private const string Bsn = "123456782"; + + private static Registration Submitted(string processInstanceId = "proc-1") + { + var registration = Registration.Submit(Bsn); + registration.RecordProcessStarted(processInstanceId); + return registration; + } + + private static ProvideDocumentsCommand Command(RegistrationId id, string bsn = Bsn) => new(id, bsn); + + [Fact] + public async Task Providing_documents_completes_the_document_wait() + { + var store = new FakeRegistrationStore(); + var registration = Submitted("proc-42"); + store.Seed(registration); + var workflow = new FakeWorkflowClient(); + var handler = new ProvideDocuments(store, workflow); + + var outcome = await handler.HandleAsync(Command(registration.Id)); + + Assert.Equal(ProvideDocumentsOutcome.Accepted, outcome); + Assert.Equal("proc-42", workflow.CompletedDocumentWaitFor); + } + + [Fact] + public async Task A_different_bsn_cannot_provide_documents() + { + // Owner-scoping: only the registration's own bsn may supply its documents. Another bsn is told + // NotFound (existence not revealed) and the wait is not completed. + var store = new FakeRegistrationStore(); + var registration = Submitted(); + store.Seed(registration); + var workflow = new FakeWorkflowClient(); + var handler = new ProvideDocuments(store, workflow); + + var outcome = await handler.HandleAsync(Command(registration.Id, bsn: "999999990")); + + Assert.Equal(ProvideDocumentsOutcome.NotFound, outcome); + Assert.Null(workflow.CompletedDocumentWaitFor); + } + + [Fact] + public async Task Providing_for_an_unknown_registration_is_not_found() + { + var store = new FakeRegistrationStore(); + var handler = new ProvideDocuments(store, new FakeWorkflowClient()); + + Assert.Equal(ProvideDocumentsOutcome.NotFound, await handler.HandleAsync(Command(RegistrationId.New()))); + } + + [Fact] + public async Task Providing_before_a_process_started_is_accepted_without_calling_the_workflow() + { + // No process yet → no wait task to complete; the request still stands (best-effort, mirroring + // WithdrawRegistration) and the Workflow Client is not called. + var store = new FakeRegistrationStore(); + var registration = Registration.Submit(Bsn); // no RecordProcessStarted + store.Seed(registration); + var workflow = new FakeWorkflowClient(); + var handler = new ProvideDocuments(store, workflow); + + var outcome = await handler.HandleAsync(Command(registration.Id)); + + Assert.Equal(ProvideDocumentsOutcome.Accepted, outcome); + Assert.Null(workflow.CompletedDocumentWaitFor); + } + + [Fact] + public async Task Rejects_a_null_command() + => await Assert.ThrowsAsync(() => + new ProvideDocuments(new FakeRegistrationStore(), new FakeWorkflowClient()).HandleAsync(null!)); +}