From ecad42873cee5711b036e660e72e10162bdac220 Mon Sep 17 00:00:00 2001 From: Niek Otten Date: Mon, 20 Jul 2026 12:02:32 +0200 Subject: [PATCH] test(domain): providing documents stores the diploma via the ACL then completes the wait (refs #103) RED: ProvideDocuments now carries the file bytes, stores them against the zaak via IAclClient before completing the WachtOpDocumenten wait; owner-scoped; best-effort when no zaak/process exists yet. Co-Authored-By: Claude Opus 4.8 (1M context) --- services/domain/Big.Tests/Fakes.cs | 9 ++++ .../domain/Big.Tests/ProvideDocumentsTests.cs | 47 ++++++++++++------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/services/domain/Big.Tests/Fakes.cs b/services/domain/Big.Tests/Fakes.cs index f183fda..ef539ef 100644 --- a/services/domain/Big.Tests/Fakes.cs +++ b/services/domain/Big.Tests/Fakes.cs @@ -110,4 +110,13 @@ internal sealed class FakeAclClient(Uri? zaakUrl = null) : IAclClient ApprovedZaakUrl = zaakUrl; return Task.CompletedTask; } + + public (Uri ZaakUrl, byte[] Content, string FileName, string ContentType)? StoredDiploma { get; private set; } + public static readonly Uri DefaultDocumentUrl = new("http://openzaak/documenten/api/v1/enkelvoudiginformatieobjecten/doc"); + + public Task StoreDiplomaAsync(Uri zaakUrl, byte[] content, string fileName, string contentType, CancellationToken ct = default) + { + StoredDiploma = (zaakUrl, content, fileName, contentType); + return Task.FromResult(DefaultDocumentUrl); + } } diff --git a/services/domain/Big.Tests/ProvideDocumentsTests.cs b/services/domain/Big.Tests/ProvideDocumentsTests.cs index 308d863..ed956e6 100644 --- a/services/domain/Big.Tests/ProvideDocumentsTests.cs +++ b/services/domain/Big.Tests/ProvideDocumentsTests.cs @@ -3,52 +3,60 @@ 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.) +// S-10a/S-10b (#102/#103): the "documents received" use case. A zorgprofessional supplies the diploma +// their registration is waiting for; the handler stores it in ZGW via the ACL and completes the +// WachtOpDocumenten task via the Workflow Client so the process continues to beoordeling. Owner-scoped +// by the caller's bsn, like WithdrawRegistration. public class ProvideDocumentsTests { private const string Bsn = "123456782"; + private static readonly Uri Zaak = new("http://openzaak/zaken/api/v1/zaken/abc"); private static Registration Submitted(string processInstanceId = "proc-1") { var registration = Registration.Submit(Bsn); registration.RecordProcessStarted(processInstanceId); + registration.AttachZaak(Zaak); return registration; } - private static ProvideDocumentsCommand Command(RegistrationId id, string bsn = Bsn) => new(id, bsn); + private static ProvideDocumentsCommand Command(RegistrationId id, string bsn = Bsn) => + new(id, bsn, [1, 2, 3], "diploma.pdf", "application/pdf"); [Fact] - public async Task Providing_documents_completes_the_document_wait() + public async Task Providing_documents_stores_the_diploma_and_completes_the_wait() { var store = new FakeRegistrationStore(); var registration = Submitted("proc-42"); store.Seed(registration); var workflow = new FakeWorkflowClient(); - var handler = new ProvideDocuments(store, workflow); + var acl = new FakeAclClient(); + var handler = new ProvideDocuments(store, workflow, acl); var outcome = await handler.HandleAsync(Command(registration.Id)); Assert.Equal(ProvideDocumentsOutcome.Accepted, outcome); + // Stored against the registration's zaak, carrying the uploaded bytes + file metadata. + Assert.Equal((Zaak, new byte[] { 1, 2, 3 }, "diploma.pdf", "application/pdf"), acl.StoredDiploma); + // …and the wait is completed so beoordeling can proceed. 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. + // Owner-scoping: another bsn is told NotFound; nothing is stored or completed. var store = new FakeRegistrationStore(); var registration = Submitted(); store.Seed(registration); var workflow = new FakeWorkflowClient(); - var handler = new ProvideDocuments(store, workflow); + var acl = new FakeAclClient(); + var handler = new ProvideDocuments(store, workflow, acl); var outcome = await handler.HandleAsync(Command(registration.Id, bsn: "999999990")); Assert.Equal(ProvideDocumentsOutcome.NotFound, outcome); + Assert.Null(acl.StoredDiploma); Assert.Null(workflow.CompletedDocumentWaitFor); } @@ -56,30 +64,33 @@ public class ProvideDocumentsTests public async Task Providing_for_an_unknown_registration_is_not_found() { var store = new FakeRegistrationStore(); - var handler = new ProvideDocuments(store, new FakeWorkflowClient()); + var handler = new ProvideDocuments(store, new FakeWorkflowClient(), new FakeAclClient()); 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() + public async Task Providing_before_a_zaak_is_opened_does_not_store_but_still_completes_the_wait() { - // No process yet → no wait task to complete; the request still stands (best-effort, mirroring - // WithdrawRegistration) and the Workflow Client is not called. + // No zaak yet → nothing to file the document against, but the request still stands (best-effort, + // mirroring WithdrawRegistration). The wait is completed if a process is running. var store = new FakeRegistrationStore(); - var registration = Registration.Submit(Bsn); // no RecordProcessStarted + var registration = Registration.Submit(Bsn); + registration.RecordProcessStarted("proc-9"); // process started, but no zaak attached store.Seed(registration); var workflow = new FakeWorkflowClient(); - var handler = new ProvideDocuments(store, workflow); + var acl = new FakeAclClient(); + var handler = new ProvideDocuments(store, workflow, acl); var outcome = await handler.HandleAsync(Command(registration.Id)); Assert.Equal(ProvideDocumentsOutcome.Accepted, outcome); - Assert.Null(workflow.CompletedDocumentWaitFor); + Assert.Null(acl.StoredDiploma); + Assert.Equal("proc-9", workflow.CompletedDocumentWaitFor); } [Fact] public async Task Rejects_a_null_command() => await Assert.ThrowsAsync(() => - new ProvideDocuments(new FakeRegistrationStore(), new FakeWorkflowClient()).HandleAsync(null!)); + new ProvideDocuments(new FakeRegistrationStore(), new FakeWorkflowClient(), new FakeAclClient()).HandleAsync(null!)); }