发现列表之前没有机器人帖。打开广场发现时,给已有机器人各写一条原创短帖。 Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"spark-server/internal/module/square/entity"
|
|
userentity "spark-server/internal/module/user/entity"
|
|
userlogic "spark-server/internal/module/user/logic"
|
|
)
|
|
|
|
func TestDiscoverFeedReturnsExistingBotPost(t *testing.T) {
|
|
svc, _, users := testSquare(t)
|
|
ctx := t.Context()
|
|
bot := &userentity.User{ID: 88001, Nickname: "小光", Status: userentity.StatusActive, SparkID: "sparkbot001"}
|
|
svc.users = &discoverUsers{inner: users, bot: bot}
|
|
viewer, err := users.AuthenticateEmail(ctx, "test01@spark.com", "1", &userentity.LoginDevice{DeviceID: 1, DeviceType: userentity.DeviceIOS})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
viewCtx := ctxUser(t, viewer.ID, "10.0.0.8")
|
|
out, err := svc.Feed(viewCtx, viewer.ID, entity.ChannelSquare, FeedQuery{Category: entity.CategoryRecommend, Limit: 20})
|
|
if err != nil || len(out.Items) != 1 {
|
|
t.Fatalf("items %d %v", len(out.Items), err)
|
|
}
|
|
item := out.Items[0]
|
|
if item.User.UID != bot.ID || item.Channel != entity.ChannelSquare || !strings.Contains(item.Text, "发现") {
|
|
t.Fatalf("post %+v", item)
|
|
}
|
|
again, err := svc.Feed(viewCtx, viewer.ID, entity.ChannelSquare, FeedQuery{Category: entity.CategoryRecommend, Limit: 20})
|
|
if err != nil || len(again.Items) != 1 || again.Items[0].ID != item.ID {
|
|
t.Fatalf("repeat %+v %v", again, err)
|
|
}
|
|
}
|
|
|
|
type discoverUsers struct {
|
|
inner *userlogic.Service
|
|
bot *userentity.User
|
|
}
|
|
|
|
func (d *discoverUsers) Get(ctx context.Context, id int64) (*userentity.User, error) {
|
|
if d.bot != nil && id == d.bot.ID {
|
|
return d.bot, nil
|
|
}
|
|
return d.inner.Get(ctx, id)
|
|
}
|
|
|
|
func (d *discoverUsers) GetByEmail(ctx context.Context, email string) (*userentity.User, error) {
|
|
if email == "bot001@spark.bot" {
|
|
return d.bot, nil
|
|
}
|
|
return d.inner.GetByEmail(ctx, email)
|
|
}
|