diff --git a/src/core/tests/Deal.Tests.Unit/Support/OperatorAuditEndpointsHttpTests.cs b/src/core/tests/Deal.Tests.Unit/Support/OperatorAuditEndpointsHttpTests.cs index 3fdef10..557d9d9 100644 --- a/src/core/tests/Deal.Tests.Unit/Support/OperatorAuditEndpointsHttpTests.cs +++ b/src/core/tests/Deal.Tests.Unit/Support/OperatorAuditEndpointsHttpTests.cs @@ -282,6 +282,7 @@ public sealed class OperatorAuditEndpointsHttpTests { var tenantId = Guid.NewGuid(); var auditStore = new TestAuditLogStore(); + var userStore = NewUserStore(tenantId, "owner@acme"); await auditStore.Store.AppendAsync( new AuditRecordDto( AuditEvents.TenantStatusChanged, @@ -295,7 +296,7 @@ public sealed class OperatorAuditEndpointsHttpTests await OperatorAuthHttpHost.RunAsync( NewOperatorStore(), - NewUserStore(), + userStore, async (baseAddress, _, _, _, _, _) => { HttpClient operatorClient = CreateClient(baseAddress); @@ -306,6 +307,7 @@ public sealed class OperatorAuditEndpointsHttpTests JsonElement item = (await ReadJsonAsync(response)).GetProperty("items")[0]; Assert.Equal(tenantId, item.GetProperty("tenantId").GetGuid()); + Assert.Equal("owner@acme", item.GetProperty("userName").GetString()); Assert.Equal("acme", item.GetProperty("tenantName").GetString()); JsonElement change = item.GetProperty("changes")[0]; Assert.Equal("status", change.GetProperty("field").GetString()); @@ -346,6 +348,20 @@ public sealed class OperatorAuditEndpointsHttpTests return store; } + // Фейк-хранилище с одним пользователем заданного тенанта (владелец для разрешения логина). + private static TestAuthStore NewUserStore(Guid tenantId, string login) + { + var passwordHasher = TestHashers.New(); + var store = new TestAuthStore(); + store.AddUser(new StoredUserDto( + Guid.NewGuid(), + login, + tenantId, + "active", + passwordHasher.Hash(UserPassword))); + return store; + } + // HTTP-клиент с собственным CookieContainer (изоляция сценариев кук). private static HttpClient CreateClient(string baseAddress) => new(new HttpClientHandler { UseCookies = true, CookieContainer = new CookieContainer() }) diff --git a/src/core/tests/Deal.Tests.Unit/Support/TestAuthStore.cs b/src/core/tests/Deal.Tests.Unit/Support/TestAuthStore.cs index 50925f6..2677abc 100644 --- a/src/core/tests/Deal.Tests.Unit/Support/TestAuthStore.cs +++ b/src/core/tests/Deal.Tests.Unit/Support/TestAuthStore.cs @@ -50,6 +50,8 @@ public sealed class TestAuthStore .Returns(ci => FindById(ci.ArgAt(0))); Store.ListUsersByTenantIdAsync(Arg.Any(), Arg.Any()) .Returns(ci => ListByTenantId(ci.ArgAt(0))); + Store.FindOwnerLoginsByTenantIdsAsync(Arg.Any>(), Arg.Any()) + .Returns(ci => OwnerLogins(ci.ArgAt>(0))); Store.When(s => s.CreateUserAsync(Arg.Any(), Arg.Any())) .Do(ci => { @@ -113,6 +115,17 @@ public sealed class TestAuthStore .ToList(); } + private IReadOnlyDictionary OwnerLogins(IReadOnlyCollection tenantIds) + { + var owners = new Dictionary(); + foreach (StoredUserDto user in _users.Where(u => tenantIds.Contains(u.TenantId))) + { + owners.TryAdd(user.TenantId, user.Login); + } + + return owners; + } + private void UpdatePasswordHash(Guid userId, string passwordHash) { int index = _users.FindIndex(u => u.Id == userId);