feat(registratie): WP-35 — one Concept per case type (server-enforced)
Make "at most one unsubmitted Concept per type" a server invariant instead of a client-only convenience. ApplicationStore.Create → CreateConcept guards atomically under the write gate and POST /applications returns 409 when a duplicate would be created. The FE draft-sync recovers from the 409 by adopting the existing Concept (ensureId → findConcept) rather than erroring — one-per-type means the second attempt lands on the existing draft. Typed client regenerated (documents the 409). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,10 @@ public class ApplicationTests(TestWebApplicationFactory factory) : IClassFixture
|
||||
|
||||
private async Task<ApplicationDetailDto> Create(string type = "registratie")
|
||||
{
|
||||
// WP-35: one Concept per type is now server-enforced, and these tests share one DB
|
||||
// (IClassFixture). Clear any leftover Concept so each test starts from a clean slate.
|
||||
foreach (var s in (await List())!.Where(x => x.Status.Tag == "Concept"))
|
||||
await _client.DeleteAsync($"/api/v1/applications/{s.Id}");
|
||||
var res = await _client.PostAsJsonAsync("/api/v1/applications", new { type });
|
||||
Assert.Equal(HttpStatusCode.Created, res.StatusCode);
|
||||
return (await res.Content.ReadFromJsonAsync<ApplicationDetailDto>())!;
|
||||
@@ -90,6 +94,33 @@ public class ApplicationTests(TestWebApplicationFactory factory) : IClassFixture
|
||||
Assert.Equal(HttpStatusCode.Conflict, again.StatusCode);
|
||||
}
|
||||
|
||||
// --- WP-35: one Concept per case type (server-enforced) ---
|
||||
|
||||
[Fact]
|
||||
public async Task Creating_a_second_concept_of_the_same_type_conflicts()
|
||||
{
|
||||
await Create("herregistratie");
|
||||
var dup = await _client.PostAsJsonAsync("/api/v1/applications", new { type = "herregistratie" });
|
||||
Assert.Equal(HttpStatusCode.Conflict, dup.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_concept_of_a_different_type_is_allowed()
|
||||
{
|
||||
await Create("registratie");
|
||||
var other = await _client.PostAsJsonAsync("/api/v1/applications", new { type = "herregistratie" });
|
||||
Assert.Equal(HttpStatusCode.Created, other.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_new_concept_is_allowed_once_the_previous_one_is_submitted()
|
||||
{
|
||||
var a = await Create("registratie");
|
||||
(await _client.PostAsJsonAsync($"/api/v1/applications/{a.Id}/submit", new { diplomaHerkomst = "duo" })).EnsureSuccessStatusCode();
|
||||
var next = await _client.PostAsJsonAsync("/api/v1/applications", new { type = "registratie" });
|
||||
Assert.Equal(HttpStatusCode.Created, next.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Cancel_concept_removes_it()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user