对接
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"kra/internal/data/ledger"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type acceptanceReport struct {
|
||||
StartedAt string `json:"startedAt"`
|
||||
Checks []string `json:"checks"`
|
||||
Findings []string `json:"findings"`
|
||||
Records map[string]any `json:"records"`
|
||||
Database string `json:"database"`
|
||||
}
|
||||
|
||||
func verify() (err error) {
|
||||
f, err := readFixtures()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
report := &acceptanceReport{StartedAt: time.Now().Format(time.RFC3339), Database: f.Database, Records: map[string]any{}}
|
||||
defer func() {
|
||||
if recovered := recover(); recovered != nil {
|
||||
report.Findings = append(report.Findings, fmt.Sprint(recovered))
|
||||
}
|
||||
if saveErr := saveJSON("report.json", report); saveErr != nil {
|
||||
err = saveErr
|
||||
return
|
||||
}
|
||||
if len(report.Findings) > 0 {
|
||||
err = fmt.Errorf("%d passed groups, %d findings; inspect %s/report.json", len(report.Checks), len(report.Findings), outputDir)
|
||||
}
|
||||
}()
|
||||
admin, err := login(f.Admin, true)
|
||||
must(err)
|
||||
viewer, err := login(f.Viewer, false)
|
||||
must(err)
|
||||
other, err := login(f.Other, false)
|
||||
must(err)
|
||||
anchor, err := login(f.Anchor, false)
|
||||
must(err)
|
||||
public := newClient()
|
||||
db, err := openFixtureDB()
|
||||
must(err)
|
||||
sqlDB, err := db.DB()
|
||||
must(err)
|
||||
defer sqlDB.Close()
|
||||
must(admin.call("PATCH", adminRoomPath(f.DisabledID)+"/status", dto.LiveStatusRequest{Enabled: false}, nil))
|
||||
var list struct {
|
||||
List []*dto.LiveRoomResponse `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
must(public.call("GET", fmt.Sprintf("/live/rooms?categoryId=%d&pageSize=100", f.CategoryID), nil, &list))
|
||||
foundLive, foundReplay := false, false
|
||||
for _, item := range list.List {
|
||||
check(item.Enabled && item.ID != f.DisabledID, "public list exposed a disabled room: %+v", item)
|
||||
foundLive = foundLive || item.ID == f.RoomID
|
||||
foundReplay = foundReplay || item.ID == f.ReplayID
|
||||
}
|
||||
check(foundLive && foundReplay, "public listing omitted enabled live/replay fixtures: %+v", list)
|
||||
var replay dto.LiveRoomResponse
|
||||
must(public.call("GET", roomPath(f.ReplayID), nil, &replay))
|
||||
check(replay.Status == "offline" && replay.ReplayURL != "", "offline replay inaccessible: %+v", replay)
|
||||
check(public.call("GET", roomPath(f.DisabledID), nil, nil) != nil, "disabled room was exposed publicly")
|
||||
passed(report, "public list includes offline and recorded rooms and excludes disabled rooms")
|
||||
verifyCatalog(admin, public, viewer, f, report)
|
||||
verifyRecharge(admin, viewer, other, f, db, report)
|
||||
verifyLive(admin, public, anchor, viewer, other, f, db, report)
|
||||
verifyDisabledAccount(admin, other, f, report)
|
||||
verifyAdminSurface(admin, viewer, f, db, report)
|
||||
verifyClientAccount(report)
|
||||
var final ledger.WalletPO
|
||||
must(db.Where("user_id = ?", f.Viewer.ID).First(&final).Error)
|
||||
var chatRows, sends, rechargeOrders int64
|
||||
must(db.Table("live_chat_messages").Count(&chatRows).Error)
|
||||
must(db.Model(&ledger.GiftSendPO{}).Where("user_id = ?", f.Viewer.ID).Count(&sends).Error)
|
||||
must(db.Model(&ledger.RechargeOrderPO{}).Where("user_id = ?", f.Viewer.ID).Count(&rechargeOrders).Error)
|
||||
check(chatRows == 0, "chat content was persisted: %d rows", chatRows)
|
||||
report.Records["finalWallet"] = final
|
||||
report.Records["giftSendRows"] = sends
|
||||
report.Records["rechargeOrderRows"] = rechargeOrders
|
||||
report.Records["chatRows"] = chatRows
|
||||
passed(report, "SQLite wallet, gift-send and recharge records reconciled; chat table remains empty")
|
||||
fmt.Printf("Completed %d acceptance check groups\n", len(report.Checks))
|
||||
return nil
|
||||
}
|
||||
|
||||
func passed(report *acceptanceReport, text string) {
|
||||
report.Checks = append(report.Checks, text)
|
||||
fmt.Printf("PASS %s\n", text)
|
||||
must(saveJSON("report.json", report))
|
||||
}
|
||||
|
||||
func wallet(db *gorm.DB, userID uint) ledger.WalletPO {
|
||||
var value ledger.WalletPO
|
||||
must(db.Where("user_id = ?", userID).First(&value).Error)
|
||||
return value
|
||||
}
|
||||
|
||||
func giftCount(db *gorm.DB, userID uint) int64 {
|
||||
var count int64
|
||||
must(db.Model(&ledger.GiftSendPO{}).Where("user_id = ?", userID).Count(&count).Error)
|
||||
return count
|
||||
}
|
||||
Reference in New Issue
Block a user