## S-10c · Close the ZGW zaak on document-timeout expiry (closes #106) Completes the S-10a/S-10b boundary flagged in ADR-0017: when a registration's 30-day document term lapses, the domain now cancels the **ZGW zaak** as well as marking the aggregate `Verlopen`, so OpenZaak and the register no longer diverge. ### What it does On expiry the `ExpireRegistrationWorker` calls the ACL to set the zaak to a distinct, non-terminal **`Geannuleerd`** status with a **`Vervallen`** resultaat (vs the approval `Afgehandeld` + `Geregistreerd`), resolved **by omschrijving** in the ACL — the ACL-first ordering mirrors approval so a failed ZGW call leaves the job for redelivery rather than diverging the two. **Path:** Flowable P30D timer → `RegistratieVerlopen` job → domain `ExpireRegistrationWorker` → ACL `POST /annuleringen` → ZGW `resultaten` + `statussen` (Geannuleerd) → aggregate `Verlopen`. ### Layers touched (each red→green) - **ACL gateway** — `SetZaakToCancellationStatusAsync` (Geannuleerd + Vervallen by name); approval now resolves its `Geregistreerd` resultaat by name too (a second resultaattype now exists). - **ACL service/API** — `AclService.CancelZaakAsync` + `POST /annuleringen`. - **Domain** — `IAclClient.CancelZaakAsync` + client; expiry worker cancels the zaak before advancing to `Verlopen`, guarded against redelivery double-cancel. - **Seed** — non-terminal `Geannuleerd` statustype (volgnummer 2; `Afgehandeld` → 3) + `Vervallen` resultaattype, both idempotent by omschrijving and sharing the zaaktype's procestype. - **Verify/integration** — ACL↔OpenZaak integration test (live `Geannuleerd` + resultaat); `run-domain-check.sh` fires the real P30D timer and asserts the zaak reaches `Geannuleerd` end-to-end; BDD scenario asserts cancel-on-timeout vs untouched-when-in-time. - **Docs** — ADR-0019 (cancellation modelling decision), demo-script, BACKLOG. ### Design note (ADR-0019) ZGW allows only one eindstatus per zaaktype, so `Geannuleerd` is modelled as a **non-terminal** status (it records a cancellation status + resultaat but does not set `einddatum`). This follows the issue's explicit "distinct statustype + resultaat" outcome; the shared-eindstatus alternative is recorded in the ADR. ### Tests Unit + acceptance all green locally (Acl 38, Big 134, Acceptance 17, Bff 33, EventSubscriber 19). Integration + verify-stack run in CI (need live OpenZaak + selectielijst egress). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed-on: #109
133 lines
5.2 KiB
C#
133 lines
5.2 KiB
C#
using Big.Application;
|
|
using Big.Domain;
|
|
|
|
namespace Big.Tests;
|
|
|
|
/// <summary>An in-memory <see cref="IRegistrationStore"/> for the application-layer tests. Upserts
|
|
/// keyed on the registration id, mirroring the production store (kept distinct from the production
|
|
/// <c>InMemoryRegistrationStore</c> so tests can seed and inspect save counts).</summary>
|
|
internal sealed class FakeRegistrationStore : IRegistrationStore
|
|
{
|
|
private readonly Dictionary<RegistrationId, Registration> _byId = [];
|
|
|
|
public int SaveCount { get; private set; }
|
|
|
|
public Task SaveAsync(Registration registration, CancellationToken ct = default)
|
|
{
|
|
SaveCount++;
|
|
_byId[registration.Id] = registration;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task<Registration?> GetAsync(RegistrationId id, CancellationToken ct = default)
|
|
=> Task.FromResult(_byId.GetValueOrDefault(id));
|
|
|
|
public void Seed(Registration registration) => _byId[registration.Id] = registration;
|
|
}
|
|
|
|
/// <summary>A fake Workflow Client that records the registration it was asked to start a process for
|
|
/// and returns a fixed process-instance id. An optional callback runs at start time, letting a test
|
|
/// assert ordering (e.g. that the registration was persisted before the process started).</summary>
|
|
internal sealed class FakeWorkflowClient(string processInstanceId = "proc-1", Action<RegistrationId>? onStart = null)
|
|
: IWorkflowClient
|
|
{
|
|
public RegistrationId? StartedFor { get; private set; }
|
|
public DiplomaOrigin? StartedWithOrigin { get; private set; }
|
|
public string? WithdrawnProcessInstanceId { get; private set; }
|
|
public string? CompletedDocumentWaitFor { get; private set; }
|
|
|
|
public Task<string> StartRegistrationProcessAsync(
|
|
RegistrationId registrationId, DiplomaOrigin diplomaOrigin, CancellationToken ct = default)
|
|
{
|
|
onStart?.Invoke(registrationId);
|
|
StartedFor = registrationId;
|
|
StartedWithOrigin = diplomaOrigin;
|
|
return Task.FromResult(processInstanceId);
|
|
}
|
|
|
|
public Task WithdrawProcessAsync(string processInstanceId, CancellationToken ct = default)
|
|
{
|
|
WithdrawnProcessInstanceId = processInstanceId;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task CompleteDocumentWaitAsync(string processInstanceId, CancellationToken ct = default)
|
|
{
|
|
CompletedDocumentWaitFor = processInstanceId;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>A fake user-task client for the werkbak/decision use cases: returns a scripted set of
|
|
/// open beoordeling tasks and records claim/complete calls.</summary>
|
|
internal sealed class FakeUserTaskClient(IReadOnlyList<BeoordelingTask> open) : IUserTaskClient
|
|
{
|
|
public (string TaskId, string Behandelaar)? Claimed { get; private set; }
|
|
public (string TaskId, BeoordelingsBesluit Besluit)? Completed { get; private set; }
|
|
|
|
public Task<IReadOnlyList<BeoordelingTask>> GetOpenBeoordelingenAsync(CancellationToken ct = default)
|
|
=> Task.FromResult(open);
|
|
|
|
public Task ClaimAsync(string taskId, string behandelaar, CancellationToken ct = default)
|
|
{
|
|
Claimed = (taskId, behandelaar);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task CompleteBeoordelingAsync(string taskId, BeoordelingsBesluit besluit, CancellationToken ct = default)
|
|
{
|
|
Completed = (taskId, besluit);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>A fake ACL client that records the bsn it was asked to open a zaak for and returns a
|
|
/// fixed zaak URL.</summary>
|
|
internal sealed class FakeAclClient(Uri? zaakUrl = null) : IAclClient
|
|
{
|
|
public static readonly Uri DefaultZaakUrl = new("http://openzaak/zaken/api/v1/zaken/abc");
|
|
|
|
private readonly Uri _zaakUrl = zaakUrl ?? DefaultZaakUrl;
|
|
|
|
public string? OpenedForBsn { get; private set; }
|
|
public string? OpenedWithReference { get; private set; }
|
|
public int CallCount { get; private set; }
|
|
|
|
public Uri? ApprovedZaakUrl { get; private set; }
|
|
public int ApproveCallCount { get; private set; }
|
|
|
|
public Task<Uri> OpenZaakAsync(string bsn, string reference, CancellationToken ct = default)
|
|
{
|
|
CallCount++;
|
|
OpenedForBsn = bsn;
|
|
OpenedWithReference = reference;
|
|
return Task.FromResult(_zaakUrl);
|
|
}
|
|
|
|
public Task ApproveZaakAsync(Uri zaakUrl, CancellationToken ct = default)
|
|
{
|
|
ApproveCallCount++;
|
|
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<Uri> StoreDiplomaAsync(Uri zaakUrl, byte[] content, string fileName, string contentType, CancellationToken ct = default)
|
|
{
|
|
StoredDiploma = (zaakUrl, content, fileName, contentType);
|
|
return Task.FromResult(DefaultDocumentUrl);
|
|
}
|
|
|
|
public Uri? CancelledZaakUrl { get; private set; }
|
|
public int CancelCallCount { get; private set; }
|
|
|
|
public Task CancelZaakAsync(Uri zaakUrl, CancellationToken ct = default)
|
|
{
|
|
CancelCallCount++;
|
|
CancelledZaakUrl = zaakUrl;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|