40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"testing"
|
|
|
|
friendlogic "spark-server/internal/module/friend/logic"
|
|
modentity "spark-server/internal/module/moderation/entity"
|
|
modlogic "spark-server/internal/module/moderation/logic"
|
|
"spark-server/internal/pkg/errs"
|
|
"spark-server/internal/pkg/sensitive"
|
|
)
|
|
|
|
func TestSendMessageContentBlocked(t *testing.T) {
|
|
svc, users, friends, _ := testMessageSvc(t)
|
|
word := sensitive.FoldWord("赌博")
|
|
repo := modlogic.NewMemoryRepo(&modentity.Word{
|
|
ID: 1, WordRaw: "赌博", Word: word, Category: modentity.CategoryGambling,
|
|
Action: modentity.ActionReject, Enabled: true,
|
|
})
|
|
mod := modlogic.NewService(repo, users, svc.ids)
|
|
svc.BindModeration(users, mod, mod)
|
|
ctx := context.Background()
|
|
a, b := twoUsers(t, users)
|
|
applied, err := friends.Apply(ctx, a.ID, &friendlogic.ApplyInput{UID: b.ID, Reason: "hi"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := friends.Accept(ctx, b.ID, friendlogic.AcceptInput{RequestID: applied.RequestID}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
text := json.RawMessage(`{"t":1,"text":{"body":"今晚赌博"}}`)
|
|
_, err = svc.SendMessage(ctx, a.ID, 1, &SendInput{PeerID: b.ID, ClientMsgID: "bad", Content: text})
|
|
if !errors.Is(err, errs.ErrContentBlocked) {
|
|
t.Fatalf("expected blocked got %v", err)
|
|
}
|
|
}
|