48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"hyapp/pkg/appcode"
|
|
userdomain "hyapp/services/user-service/internal/domain/user"
|
|
)
|
|
|
|
func TestSubmitReportAcceptsExactlyOneTarget(t *testing.T) {
|
|
repository := &fakeModerationRepository{}
|
|
svc := New(repository, WithClock(func() time.Time { return time.UnixMilli(1_778_000_000_000).UTC() }))
|
|
ctx := appcode.WithContext(context.Background(), "lalu")
|
|
|
|
report, err := svc.SubmitReport(ctx, 10001, 10002, "", " Pornography ", " reason ", []string{" https://cdn.example.com/report.png "}, "req-report")
|
|
if err != nil {
|
|
t.Fatalf("SubmitReport failed: %v", err)
|
|
}
|
|
if report.ReportID == "" || report.TargetType != userdomain.ReportTargetUser || report.ReportType != "pornography" || report.Reason != "reason" || len(report.ImageURLs) != 1 {
|
|
t.Fatalf("report normalization mismatch: %+v", report)
|
|
}
|
|
if repository.lastReport.ReporterUserID != 10001 || repository.lastReport.UserID != 10002 || repository.lastReport.RequestID != "req-report" || repository.lastReport.CreatedAtMs != 1_778_000_000_000 {
|
|
t.Fatalf("repository report mismatch: %+v", repository.lastReport)
|
|
}
|
|
}
|
|
|
|
func TestSubmitReportRejectsMissingOrMixedTarget(t *testing.T) {
|
|
svc := New(&fakeModerationRepository{})
|
|
ctx := appcode.WithContext(context.Background(), "lalu")
|
|
tests := []struct {
|
|
name string
|
|
userID int64
|
|
roomID string
|
|
}{
|
|
{name: "missing target"},
|
|
{name: "mixed target", userID: 10002, roomID: "room_1"},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
if _, err := svc.SubmitReport(ctx, 10001, test.userID, test.roomID, "fraud", "", nil, "req-report"); err == nil {
|
|
t.Fatalf("SubmitReport must reject target combination user=%d room=%q", test.userID, test.roomID)
|
|
}
|
|
})
|
|
}
|
|
}
|