|
|
@@ -392,8 +392,7 @@ func TestCreateCourseIsUnpublished(t *testing.T) {
|
|
|
if err := db.First(&row, int64(id)).Error; err != nil {
|
|
|
t.Fatalf("回读课程失败: %v", err)
|
|
|
}
|
|
|
- // ⚠ status 断言拆到 TestCreateCourseStatusIsUnpublished_AC11Defect:
|
|
|
- // 本批实测发现 AC-11 的 `CreateCourse` 落库后 status = 1(而非 0),成因与处置见该用例注释。
|
|
|
+ // status 断言拆到 TestCreateCourseStatusIsUnpublished(D11 的回归门禁,含缺陷成因与修法)。
|
|
|
if row.InstitutionID != 1 {
|
|
|
t.Fatalf("institution_id = %d,期望 1(取作用域,不信 body 的 99)", row.InstitutionID)
|
|
|
}
|
|
|
@@ -412,22 +411,19 @@ func TestCreateCourseIsUnpublished(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// TestCreateCourseStatusIsUnpublished_AC11Defect **复现 AC-11 缺陷(本批只报不修,待裁决)**。
|
|
|
+// TestCreateCourseStatusIsUnpublished **新建课程必须落 status=0(未发布)**——D11 的回归门禁。
|
|
|
//
|
|
|
-// 现象(实测,非推测):`CourseService.CreateCourse` 里显式写了
|
|
|
-// `Status: model.CoursesStatusUnpublished`(0),但 `model.Courses.Status` 的 GORM tag 是
|
|
|
-// `not null;default:1` —— GORM 对"带 default tag 且值为零值"的字段**不把该列写进 INSERT**,
|
|
|
-// 改由数据库默认值填充 ⇒ 新建课程实际落 **status=1(发布未开始)**。
|
|
|
+// 缺陷原貌(2026-11-09 实测):`CourseService.CreateCourse` 显式写 `Status=0`,但
|
|
|
+// `model.Courses.Status` 的 gorm tag 带 `default:1` ⇒ GORM 对"有 default tag 且值为零"的列
|
|
|
+// **跳过该列**、由 DB 默认值填充 ⇒ 落库 `status=1`("新建即发布":课程直接出现在可报名列表)。
|
|
|
+// MySQL 与 SQLite 走同一段 GORM 回调,生产同样成立。
|
|
|
//
|
|
|
-// 为什么不是测试环境假象:MySQL 与 SQLite 走的是同一段 GORM 回调(`Create` 前对 default 列
|
|
|
-// 置 `DefaultValueInterface`),因此生产同样会落 1。后果是"新建即发布"——课程直接出现在
|
|
|
-// 前台可报名列表里,与 `CreateCourse` 注释"新建恒落未发布、发布走状态机"直接矛盾。
|
|
|
+// 修复(team-lead 裁决):**去掉 `model.Courses.Status` 的 `default:1`(DDL 不动)**,
|
|
|
+// 而不是 `tx.Select("*").Create(row)` —— 后者会把 `created_at`/`updated_at` 等零值一并写入,
|
|
|
+// 正是 `a1971b7`(审计时间零值落库)修过的反向坑。
|
|
|
//
|
|
|
-// 为什么不本批直接修:修复点落在 **AC-11 的 `repository.CreateCourse`**(`tx.Create(row)`
|
|
|
-// 需改为 `tx.Select("*").Create(row)` 或显式列出含 `status` 的列),属"改 AC-11 既有实现",
|
|
|
-// 按本批纪律**先报不改**。修复落地后,删掉下面这行 `t.Skip` 即可作为回归门禁。
|
|
|
-func TestCreateCourseStatusIsUnpublished_AC11Defect(t *testing.T) {
|
|
|
- t.Skip("AC-11 缺陷待裁决:新建课程 status 被 GORM default tag 吞掉,实际落 1(发布未开始)")
|
|
|
+// 本用例是**回归门禁**:把 `default:1` 加回 tag,本用例必红(实测见交付报告)。
|
|
|
+func TestCreateCourseStatusIsUnpublished(t *testing.T) {
|
|
|
db := newCourseTestDB(t)
|
|
|
app := newCourseTestApp(t, db)
|
|
|
code, msg, data := doJSON(t, app, fiber.MethodPost, PathCourses, map[string]any{
|