test(domain): Workflow Client, ACL client, store and job processor (refs #6)
Failing infrastructure unit tests (stub HttpMessageHandler, fakes): - FlowableWorkflowClient starts a process with the registrationId variable and returns the instance id; acquires OpenZaakAanmaken jobs (topic/workerId/lock) and parses their registrationId; completes a job with the zaakUrl variable — request URIs match flowable-rest's service/ and external-job-api/ paths. - AclHttpClient POSTs the bsn to the ACL and returns the zaak URL. - InMemoryRegistrationStore saves/reads/upserts by id. - OpenZaakJobProcessor acquires, opens a zaak, completes the job; leaves a failing job uncompleted for redelivery; polls harmlessly when idle. Adapters are stubs so the tests compile and fail on their assertions; the green commit implements them against the REST contract verified on a live Flowable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
77
services/domain/Big.Tests/OpenZaakJobProcessorTests.cs
Normal file
77
services/domain/Big.Tests/OpenZaakJobProcessorTests.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Big.Application;
|
||||
using Big.Domain;
|
||||
using Big.Infrastructure;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace Big.Tests;
|
||||
|
||||
public class OpenZaakJobProcessorTests
|
||||
{
|
||||
/// <summary>A fake external-worker client: scripts the jobs to acquire and records completions.</summary>
|
||||
private sealed class FakeExternalWorkerClient(params OpenZaakJob[] jobs) : IExternalWorkerClient
|
||||
{
|
||||
public int AcquireCount { get; private set; }
|
||||
public List<(string JobId, Uri ZaakUrl)> Completed { get; } = [];
|
||||
|
||||
public Task<IReadOnlyList<OpenZaakJob>> AcquireOpenZaakJobsAsync(int maxJobs, CancellationToken ct = default)
|
||||
{
|
||||
AcquireCount++;
|
||||
return Task.FromResult<IReadOnlyList<OpenZaakJob>>(jobs.Take(maxJobs).ToList());
|
||||
}
|
||||
|
||||
public Task CompleteOpenZaakJobAsync(string jobId, Uri zaakUrl, CancellationToken ct = default)
|
||||
{
|
||||
Completed.Add((jobId, zaakUrl));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
private static OpenZaakJobProcessor Processor(IExternalWorkerClient client, IRegistrationStore store, FakeAclClient acl)
|
||||
=> new(client, new OpenZaakWorker(store, acl), NullLogger<OpenZaakJobProcessor>.Instance);
|
||||
|
||||
[Fact]
|
||||
public async Task Acquires_a_job_opens_the_zaak_and_completes_it()
|
||||
{
|
||||
var registration = Registration.Submit("123456782");
|
||||
var store = new FakeRegistrationStore();
|
||||
store.Seed(registration);
|
||||
var client = new FakeExternalWorkerClient(new OpenZaakJob("job-1", registration.Id));
|
||||
var acl = new FakeAclClient();
|
||||
|
||||
var acquired = await Processor(client, store, acl).PumpOnceAsync(5);
|
||||
|
||||
Assert.Equal(1, acquired);
|
||||
var completed = Assert.Single(client.Completed);
|
||||
Assert.Equal("job-1", completed.JobId);
|
||||
Assert.Equal(FakeAclClient.DefaultZaakUrl, completed.ZaakUrl);
|
||||
Assert.Equal(FakeAclClient.DefaultZaakUrl, (await store.GetAsync(registration.Id))!.ZaakUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_failing_job_is_left_uncompleted_for_flowable_to_redeliver()
|
||||
{
|
||||
var store = new FakeRegistrationStore();
|
||||
var acl = new FakeAclClient();
|
||||
// The job correlates to a registration that is not in the store, so the worker throws.
|
||||
var client = new FakeExternalWorkerClient(new OpenZaakJob("job-1", RegistrationId.New()));
|
||||
|
||||
var acquired = await Processor(client, store, acl).PumpOnceAsync(5);
|
||||
|
||||
Assert.Equal(1, acquired);
|
||||
Assert.Empty(client.Completed);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Does_nothing_but_poll_when_there_are_no_jobs()
|
||||
{
|
||||
var store = new FakeRegistrationStore();
|
||||
var acl = new FakeAclClient();
|
||||
var client = new FakeExternalWorkerClient();
|
||||
|
||||
var acquired = await Processor(client, store, acl).PumpOnceAsync(5);
|
||||
|
||||
Assert.Equal(0, acquired);
|
||||
Assert.Equal(1, client.AcquireCount);
|
||||
Assert.Empty(client.Completed);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user