增加客服上传账号统计
This commit is contained in:
@@ -65,3 +65,44 @@ func assertChannelStats(t *testing.T, item ListingChannelDayStatsDTO, published,
|
||||
t.Fatalf("channel %q stats = %#v, want published=%d offline=%d tradeLeave=%d", item.SourceChannel, item, published, offline, tradeLeave)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListingDailyOverviewGroupsExternalUploadsByUploader(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
if err := db.AutoMigrate(&model.ListingStatusEvent{}, &model.ListingUpload{}); err != nil {
|
||||
t.Fatalf("AutoMigrate() error = %v", err)
|
||||
}
|
||||
loc := timeutil.ShanghaiLocation()
|
||||
now := time.Date(2026, 7, 25, 12, 0, 0, 0, loc)
|
||||
uploaderX := uint64(11)
|
||||
uploaderY := uint64(12)
|
||||
listingOne := uint64(101)
|
||||
listingTwo := uint64(102)
|
||||
listingThree := uint64(103)
|
||||
uploads := []model.ListingUpload{
|
||||
{UploaderName: "小晴", MatchedAdminID: &uploaderX, ListingID: &listingOne, CreatedAt: now},
|
||||
{UploaderName: "小晴", MatchedAdminID: &uploaderX, ListingID: &listingTwo, CreatedAt: now.Add(time.Hour)},
|
||||
{UploaderName: "小美", MatchedAdminID: &uploaderY, ListingID: &listingThree, CreatedAt: now.Add(2 * time.Hour)},
|
||||
{UploaderName: "小晴", MatchedAdminID: &uploaderX, ListingID: &listingOne, CreatedAt: now.AddDate(0, 0, -1)},
|
||||
}
|
||||
if err := db.Create(&uploads).Error; err != nil {
|
||||
t.Fatalf("create uploads error = %v", err)
|
||||
}
|
||||
|
||||
overview, err := NewRepository(db).listingDailyOverview(t.Context(), now, 2)
|
||||
if err != nil {
|
||||
t.Fatalf("listingDailyOverview() error = %v", err)
|
||||
}
|
||||
if len(overview.TodayUploaders) != 2 {
|
||||
t.Fatalf("today uploaders = %#v, want 2 rows", overview.TodayUploaders)
|
||||
}
|
||||
counts := make(map[string]int64)
|
||||
for _, item := range overview.TodayUploaders {
|
||||
counts[item.UploaderName] = item.UploadCount
|
||||
}
|
||||
if counts["小晴"] != 2 || counts["小美"] != 1 {
|
||||
t.Fatalf("today uploader counts = %#v, want 小晴=2, 小美=1", counts)
|
||||
}
|
||||
if len(overview.UploaderTrend) != 3 {
|
||||
t.Fatalf("uploader trend = %#v, want 3 rows", overview.UploaderTrend)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user