fix: stabilize backend tests

This commit is contained in:
2026-01-08 14:07:58 +08:00
parent 7f1d2e7cb3
commit edbb62449b
18 changed files with 281 additions and 147 deletions

View File

@@ -2,6 +2,7 @@ package services
import (
"context"
"os"
"time"
"quyun/v2/app/errorx"
@@ -57,7 +58,7 @@ func (s *notification) List(ctx context.Context, userID int64, page int, typeArg
}, nil
}
func (s *notification) MarkRead(ctx context.Context, userID int64, id int64) error {
func (s *notification) MarkRead(ctx context.Context, userID, id int64) error {
_, err := models.NotificationQuery.WithContext(ctx).
Where(models.NotificationQuery.ID.Eq(id), models.NotificationQuery.UserID.Eq(userID)).
UpdateSimple(models.NotificationQuery.IsRead.Value(true))
@@ -84,5 +85,19 @@ func (s *notification) Send(ctx context.Context, userID int64, typ, title, conte
Title: title,
Content: content,
}
// 测试环境下同步写入,避免异步任务未启动导致结果不确定。
if os.Getenv("JOB_INLINE") == "1" {
n := &models.Notification{
UserID: userID,
Type: typ,
Title: title,
Content: content,
IsRead: false,
}
if err := models.NotificationQuery.WithContext(ctx).Create(n); err != nil {
return errorx.ErrDatabaseError.WithCause(err)
}
return nil
}
return s.job.Add(arg)
}