提交管理员操作一切

This commit is contained in:
chfei committed 2026-10-23 18:16:05 +08:00
1 parent a87ebeaffb
commit d6471f97d3
23 files changed
+600 -73

No files matched your search

+46 -1
View File
@@ -202,7 +202,7 @@ public sealed class UserManagementTests
Assert.Equal("child-two", Assert.Single(page.Items).UserName);
var second = await context.Users.Search(new() { Page = 2, PageSize = 1 }, true, default);
Assert.Equal("child", Assert.Single(second.Items).UserName);
Assert.Equal(403, (await Assert.ThrowsAsync<AppException>(() => context.Users.Search(new(), false, default))).Code);
Assert.Equal(3, (await context.Users.Search(new(), false, default)).Total);
}
[Theory]
@@ -215,6 +215,51 @@ public sealed class UserManagementTests
await Assert.ThrowsAsync<ValidationException>(() => context.Users.Search(new() { Page = page, PageSize = pageSize }, false, default));
}
[Fact]
public async Task Admin_CanQueryAllChildrenWithoutIncludingMainAccounts()
{
using var context = new UserTestContext();
context.Seed("foreign-child", parent: "other");
context.Seed("admin-child", parent: "admin");
context.Seed("blank-parent", parent: " ");
var page = await context.Users.Search(new(), true, default);
Assert.Equal(3, page.Total);
Assert.Equal(new[] { "admin-child", "child", "foreign-child" }, page.Items.Select(u => u.UserName).Order().ToArray());
Assert.All(page.Items, u => Assert.False(u.IsMainUser));
}
[Theory]
[InlineData("main", "child")]
[InlineData(" other ", "foreign-child")]
public async Task Admin_CanFilterChildrenByAnyParent(string parent, string expectedChild)
{
using var context = new UserTestContext();
context.Seed("foreign-child", parent: "other");
var page = await context.Users.Search(new() { ParentUserName = parent }, true, default);
Assert.Equal(1, page.Total);
Assert.Equal(expectedChild, Assert.Single(page.Items).UserName);
}
[Fact]
public async Task MainAccount_CannotSelectAnotherParentsChildren()
{
using var context = new UserTestContext();
context.CurrentUser.UserName = "main";
var error = await Assert.ThrowsAsync<AppException>(() => context.Users.Search(new() { ParentUserName = "other" }, true, default));
Assert.Equal(403, error.Code);
var page = await context.Users.Search(new() { ParentUserName = "main" }, true, default);
Assert.Equal("child", Assert.Single(page.Items).UserName);
}
[Fact]
public async Task ChildAccount_CannotQueryChildLists()
{
using var context = new UserTestContext();
context.CurrentUser.UserName = "child";
var error = await Assert.ThrowsAsync<AppException>(() => context.Users.Search(new(), true, default));
Assert.Equal(403, error.Code);
}
[Fact]
public async Task EmptyAccount_CanBeDeleted_AndSessionIsInvalidated()
{