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!)); }