Add tuition snapshot acceptance coverage

This commit is contained in:
biss committed 2026-11-21 12:47:17 +08:00
1 parent 5e44e2c044
commit 2a1ce72ba3
2 files changed
+90

No files matched your search

@@ -1,3 +1,7 @@
using System.Security.Claims;
using Jiaowu.Api.Controllers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Jiaowu.Api.Domain.Academic;
using Jiaowu.Api.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
@@ -71,6 +75,38 @@ public sealed class LiveMySqlAcceptanceTests
});
await db.SaveChangesAsync();
var college = await db.Colleges.SingleAsync(x => x.Code == "RC-ACCEPTANCE");
var major = new Major { Code = "RC-MAJOR", Name = "验收专业", DegreeType = "本科", CollegeId = college.Id };
var adminClass = new AdministrativeClass { Code = "RC-CLASS", Name = "验收班", Grade = 2026, MajorId = major.Id };
var student = new Student { StudentNumber = "RC-STUDENT", Name = "验收学生", AdministrativeClassId = adminClass.Id, EnrollmentDate = new DateOnly(2026, 9, 1) };
var term = new AcademicTerm { Code = "RC-TERM", Name = "验收学期", AcademicYear = "2026-2027", StartDate = new DateOnly(2026, 9, 1), EndDate = new DateOnly(2027, 1, 31) };
var course = new Course { Code = "RC-COURSE", Name = "原课程名称", CollegeId = college.Id, Credits = 3 };
var task = new TeachingTask { TaskNumber = "RC-TASK", Name = "验收任务", CourseId = course.Id, AcademicTermId = term.Id, Status = TeachingTaskStatus.Published,
Classes = [new TeachingTaskClass { AdministrativeClassId = adminClass.Id }] };
db.AddRange(major, adminClass, student, term, course, task, new TuitionTermSetting { AcademicTermId = term.Id, CreditUnitPrice = 100 });
await db.SaveChangesAsync();
var operatorId = Guid.NewGuid();
var controller = new TuitionController(db)
{
ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(
[new Claim(ClaimTypes.NameIdentifier, operatorId.ToString())], "test")) } }
};
Assert.IsType<OkObjectResult>(await controller.LockCredits(term.Id, default));
course.Name = "更新后的课程名称";
course.Credits = 4;
await db.SaveChangesAsync();
Assert.IsType<OkObjectResult>(await controller.LockCredits(term.Id, default));
var bill = await db.TuitionBills.AsNoTracking().SingleAsync(x => x.StudentId == student.Id);
Assert.Equal(4, bill.CreditCount);
Assert.Equal(400, bill.CreditFee);
var snapshots = await db.TuitionCreditSnapshots.AsNoTracking().Where(x => x.TuitionBillId == bill.Id).OrderBy(x => x.CalculatedAt).ToListAsync();
Assert.Equal(2, snapshots.Count);
Assert.Equal(3, snapshots[0].CreditCount);
Assert.Equal(operatorId, snapshots[0].CalculatedByUserId);
Assert.Equal("原课程名称", System.Text.Json.JsonDocument.Parse(snapshots[0].CoursesJson).RootElement[0].GetProperty("CourseName").GetString());
Assert.Equal("更新后的课程名称", System.Text.Json.JsonDocument.Parse(snapshots[1].CoursesJson).RootElement[0].GetProperty("CourseName").GetString());
Assert.Equal(snapshots[1].Id, bill.CurrentCreditSnapshotId);
Assert.Equal(
"RC 验收学院",
await db.Colleges
@@ -85,6 +121,7 @@ public sealed class LiveMySqlAcceptanceTests
Assert.Empty(await db.Database.GetPendingMigrationsAsync());
Assert.Equal(0, await db.GradeAppeals.CountAsync());
Assert.Equal(0, await db.NotificationDeliveries.CountAsync());
Assert.Equal(2, await db.TuitionCreditSnapshots.CountAsync());
}
}
finally
+53
View File
@@ -0,0 +1,53 @@
import { expect, test } from '@playwright/test'
test.use({ serviceWorkers: 'block' })
for (const role of ['Student', 'AcademicAdmin'] as const) {
for (const hasSnapshot of [true, false]) {
test(`${role} sees ${hasSnapshot ? 'saved' : 'unavailable'} credit details`, async ({ page }) => {
const user = { id: 'user-1', userName: 'user', displayName: '测试用户', roles: [role], permissions: [], effectiveDataScope: 'All' }
await page.addInitScript(savedUser => {
localStorage.setItem('jiaowu_token', 'test-token')
localStorage.setItem('jiaowu_user', JSON.stringify(savedUser))
localStorage.setItem('jiaowu_access_expires_at', '2099-01-01T00:00:00Z')
localStorage.setItem('jiaowu_session_expires_at', '2099-01-01T00:00:00Z')
}, user)
const bill = { id: 'bill-1', termName: '秋季', studentName: '测试学生', studentNumber: '20260101', baseTuition: 100, basePaid: 0, creditCount: 3, creditFee: 300, creditPaid: 0, accommodationFee: 50, accommodationPaid: 0, reconciliationAdjustment: 0, adjustmentPaid: 0, isPayable: true }
const course = { courseCode: 'C01', courseName: '计算时的课程', credits: 3, sources: ['Class'] }
let historyRequests = 0
await page.route(url => url.pathname.startsWith('/api/'), route => {
const path = new URL(route.request().url()).pathname
if (path === '/api/auth/me') return route.fulfill({ json: user })
if (path === '/api/plugins/runtime') return route.fulfill({ json: [{ id: 'mingxu.campus-services', isEnabled: true, navigationPaths: [], capabilities: [] }] })
if (path === '/api/tuition/mine') return route.fulfill({ json: [bill] })
if (path === '/api/tuition/mine/payments') return route.fulfill({ json: [] })
if (path === '/api/tuition/terms') return route.fulfill({ json: [{ id: 'term-1', name: '秋季', isCurrent: true, setting: { status: 'CreditsLocked', creditUnitPrice: 100 } }] })
if (path === '/api/tuition/bills') return route.fulfill({ json: { items: [bill], total: 1 } })
if (path === '/api/tuition/bills/bill-1/credit-details') return route.fulfill({ json: { creditCount: 3, creditFee: 300, hasSnapshot, creditUnitPrice: hasSnapshot ? 100 : null, courses: hasSnapshot ? [course] : [] } })
if (path === '/api/tuition/bills/bill-1/credit-history') {
historyRequests++
return route.fulfill({ json: hasSnapshot ? [{ id: 'snapshot-1', creditCount: 3, creditFee: 300, creditUnitPrice: 100, calculatedAt: '2026-11-21T00:00:00Z', calculatedByUserId: 'operator-1', courses: [course] }] : [] })
}
if (path === '/api/fee-catalog' || path.endsWith('/payments')) return route.fulfill({ json: [] })
return route.fulfill({ json: {} })
})
await page.goto('/tuition')
await page.getByRole('button', { name: '学分明细' }).first().click()
const dialog = page.getByRole('dialog', { name: '学分费课程明细' })
if (hasSnapshot) {
await expect(dialog.getByText('计算时的课程')).toBeVisible()
await expect(dialog.getByText(/计算时每学分单价/)).toBeVisible()
if (role === 'AcademicAdmin') {
await dialog.getByText('计算历史').click()
await dialog.locator('.el-table__expand-icon').click()
await expect(dialog.getByText('operator-1')).toBeVisible()
await expect(dialog.getByText('计算时的课程')).toHaveCount(2)
}
} else {
await expect(dialog.getByText(/该账单没有保存历史计费快照/)).toBeVisible()
await expect(dialog.getByText('计算时的课程')).toHaveCount(0)
}
expect(historyRequests).toBe(role === 'AcademicAdmin' ? 1 : 0)
})
}
}