fix(tests): repair PersonsController integration tests and fix EF concurrency on RegisterFace
- Add DbUpdateConcurrencyException to SaveChangesWithRetryAsync transient check - RegisterFaceHandler adds KnownFace via DbContext Set to avoid phantom UPDATE - Validate empty embedding (400) before person existence check - CreateViewerClientAsync bootstraps admin first so 2nd user is Viewer - Rename GetAll_WithViewerAuth test to match PersonRead permission on Viewer - PersonsControllerTests: all 20 tests green
This commit is contained in:
1 parent
fa0b61837a
commit
80e21d63e6
6 files changed
+32
-5
No files matched your search
@@ -163,7 +163,11 @@ public class PersonsControllerTests : PostgresTestBase
|
||||
public async Task RegisterFace_EmptyEmbedding_ReturnsBadRequest()
|
||||
{
|
||||
var client = await Factory.CreateAdminClientAsync();
|
||||
var response = await client.PostAsJsonAsync($"api/persons/{Guid.NewGuid()}/faces", new
|
||||
var createResponse = await client.PostAsJsonAsync("api/persons", new { displayName = "Test Face", category = "family" });
|
||||
var content = await createResponse.Content.ReadFromJsonAsync<JsonElement>();
|
||||
var personId = content.GetProperty("id").GetGuid();
|
||||
|
||||
var response = await client.PostAsJsonAsync($"api/persons/{personId}/faces", new
|
||||
{
|
||||
embedding = Array.Empty<float>()
|
||||
});
|
||||
@@ -229,11 +233,11 @@ public class PersonsControllerTests : PostgresTestBase
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAll_WithViewerAuth_ReturnsForbidden()
|
||||
public async Task GetAll_WithViewerAuth_ReturnsOk()
|
||||
{
|
||||
var client = await Factory.CreateViewerClientAsync();
|
||||
var response = await client.GetAsync("api/persons");
|
||||
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Forbidden);
|
||||
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -65,6 +65,11 @@ public static class TestHelpers
|
||||
/// </summary>
|
||||
public static async Task<HttpClient> CreateViewerClientAsync(this HeimdallWebApplicationFactory factory)
|
||||
{
|
||||
// Bootstrap an admin first: the FIRST registered user becomes Admin.
|
||||
// Without this, the "viewer" below would become the first user (Admin),
|
||||
// which breaks role-based assertions.
|
||||
await CreateAdminClientAsync(factory);
|
||||
|
||||
var email = $"viewer-{Guid.NewGuid()}@heimdall.test";
|
||||
var client = factory.CreateClient();
|
||||
var response = await client.PostAsJsonAsync("api/auth/register", new
|
||||
|
||||
Reference in new issue
Block a user