fix: stabilize backend tests
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user