Files
register-referentie/services/domain/Big.Tests/ProvideDocumentsTests.cs
T
notandClaude Opus 4.8 ecad42873c 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) <noreply@anthropic.com>
2026-07-20 12:02:32 +02:00

97 lines
4.1 KiB
C#

using Big.Application;
using Big.Domain;
namespace Big.Tests;
// 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, [1, 2, 3], "diploma.pdf", "application/pdf");
[Fact]
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 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: 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 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);
}
[Fact]
public async Task Providing_for_an_unknown_registration_is_not_found()
{
var store = new FakeRegistrationStore();
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_zaak_is_opened_does_not_store_but_still_completes_the_wait()
{
// 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);
registration.RecordProcessStarted("proc-9"); // process started, but no zaak attached
store.Seed(registration);
var workflow = new FakeWorkflowClient();
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(acl.StoredDiploma);
Assert.Equal("proc-9", workflow.CompletedDocumentWaitFor);
}
[Fact]
public async Task Rejects_a_null_command()
=> await Assert.ThrowsAsync<ArgumentNullException>(() =>
new ProvideDocuments(new FakeRegistrationStore(), new FakeWorkflowClient(), new FakeAclClient()).HandleAsync(null!));
}