RED: ExpireRegistrationWorker loads the registration a RegistratieVerlopen job correlates to and expires it (idempotent on redelivery, throws on unknown so the job is redelivered); RegistratieVerlopenProcessor drains the parked jobs and completes each, leaving a failing one un-completed (§8.6). Mirrors the OpenZaak and escalation worker/processor pairs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
66 lines
2.4 KiB
C#
66 lines
2.4 KiB
C#
using Big.Application;
|
|
using Big.Domain;
|
|
|
|
namespace Big.Tests;
|
|
|
|
// S-10a (#102): the application handler behind the RegistratieVerlopen external-worker job. The 30-day
|
|
// document-wait timer fired, so the correlated registration is expired to VERLOPEN. Mirrors
|
|
// OpenZaakWorker — pure application logic over ports, idempotent under at-least-once delivery (§8.6).
|
|
public class ExpireRegistrationWorkerTests
|
|
{
|
|
private const string Bsn = "123456782";
|
|
|
|
private static Registration Submitted(string processInstanceId = "proc-1")
|
|
{
|
|
var registration = Registration.Submit(Bsn);
|
|
registration.RecordProcessStarted(processInstanceId);
|
|
return registration;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Expires_the_registration_the_job_correlates_to()
|
|
{
|
|
var store = new FakeRegistrationStore();
|
|
var registration = Submitted();
|
|
store.Seed(registration);
|
|
|
|
await new ExpireRegistrationWorker(store).HandleAsync(
|
|
new RegistratieVerlopenJob("job-7", registration.Id));
|
|
|
|
var saved = await store.GetAsync(registration.Id);
|
|
Assert.Equal(RegistrationStatus.Verlopen, saved!.Status);
|
|
Assert.Equal(1, store.SaveCount);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task An_already_verlopen_registration_is_not_persisted_again()
|
|
{
|
|
// A redelivered job (§8.6) finds the aggregate already VERLOPEN: a no-op, not saved again.
|
|
var store = new FakeRegistrationStore();
|
|
var registration = Submitted();
|
|
registration.Expire();
|
|
store.Seed(registration);
|
|
|
|
await new ExpireRegistrationWorker(store).HandleAsync(
|
|
new RegistratieVerlopenJob("job-7", registration.Id));
|
|
|
|
Assert.Equal(0, store.SaveCount);
|
|
Assert.Equal(RegistrationStatus.Verlopen, (await store.GetAsync(registration.Id))!.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task An_unknown_registration_throws_so_the_job_is_redelivered()
|
|
{
|
|
var store = new FakeRegistrationStore();
|
|
|
|
await Assert.ThrowsAsync<InvalidOperationException>(() =>
|
|
new ExpireRegistrationWorker(store).HandleAsync(
|
|
new RegistratieVerlopenJob("job-7", RegistrationId.New())));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Rejects_a_null_job()
|
|
=> await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
|
new ExpireRegistrationWorker(new FakeRegistrationStore()).HandleAsync(null!));
|
|
}
|