服务器端分页优化
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Jiaowu.Api.Controllers;
|
||||
using Jiaowu.Api.Contracts;
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Infrastructure.Auth;
|
||||
@@ -11,6 +12,40 @@ namespace Jiaowu.Api.Tests;
|
||||
|
||||
public sealed class ApprovalsControllerTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Pending_returns_a_single_server_page_with_total()
|
||||
{
|
||||
await using var fixture = await ApprovalFixture.CreateAsync();
|
||||
fixture.Db.AddRange(
|
||||
new DeferredExam
|
||||
{
|
||||
StudentId = fixture.Student.Id,
|
||||
TeachingTaskId = fixture.CurrentTask.Id,
|
||||
Reason = "较早提交",
|
||||
SubmittedAt = DateTime.UtcNow.AddMinutes(-2)
|
||||
},
|
||||
new CourseExemption
|
||||
{
|
||||
StudentId = fixture.Student.Id,
|
||||
TeachingTaskId = fixture.CurrentTask.Id,
|
||||
Reason = "较晚提交",
|
||||
SubmittedAt = DateTime.UtcNow.AddMinutes(-1)
|
||||
});
|
||||
await fixture.Db.SaveChangesAsync();
|
||||
|
||||
var controller = new ApprovalsController(
|
||||
fixture.Db,
|
||||
new ManagerDataScope());
|
||||
var result = await controller.GetPending(2, 1, CancellationToken.None);
|
||||
|
||||
var ok = Assert.IsType<OkObjectResult>(result.Result);
|
||||
var page = Assert.IsType<PagedResult<ApprovalItem>>(ok.Value);
|
||||
Assert.Equal(2, page.Total);
|
||||
Assert.Equal(2, page.Page);
|
||||
var item = Assert.Single(page.Items);
|
||||
Assert.Equal("较早提交", item.Desc);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MyCourses_IncludesPublishedScheduledTaskAfterCurrentTermChanges()
|
||||
{
|
||||
@@ -298,4 +333,14 @@ public sealed class ApprovalsControllerTests
|
||||
DataScope.Self,
|
||||
new HashSet<string>([SystemRoles.Student]));
|
||||
}
|
||||
|
||||
private sealed class ManagerDataScope : ICurrentUserDataScope
|
||||
{
|
||||
public CurrentUserScope Current { get; } = new(
|
||||
Guid.NewGuid(),
|
||||
"测试管理员",
|
||||
null,
|
||||
DataScope.All,
|
||||
new HashSet<string>([SystemRoles.SuperAdmin]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user