fix(tenant): 收紧双站后台边界并补齐货架管理
This commit is contained in:
@@ -3,6 +3,7 @@ package dispute
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"hfb_sys/backend/internal/model"
|
||||
ordermodule "hfb_sys/backend/internal/modules/order"
|
||||
"hfb_sys/backend/internal/modules/wallet"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
"gorm.io/gorm"
|
||||
@@ -56,11 +58,15 @@ func setupDisputeTestDB(t *testing.T) *gorm.DB {
|
||||
|
||||
func createDisputeOrderFixture(t *testing.T, db *gorm.DB, order model.RentalOrder) (model.User, model.User, model.RentalOrder) {
|
||||
t.Helper()
|
||||
owner := model.User{Phone: "13800000001"}
|
||||
var userCount int64
|
||||
if err := db.Model(&model.User{}).Count(&userCount).Error; err != nil {
|
||||
t.Fatalf("统计用户失败: %v", err)
|
||||
}
|
||||
owner := model.User{Phone: fmt.Sprintf("138%08d", userCount*2+1)}
|
||||
if err := db.Create(&owner).Error; err != nil {
|
||||
t.Fatalf("创建号主失败: %v", err)
|
||||
}
|
||||
renter := model.User{Phone: "13800000002"}
|
||||
renter := model.User{Phone: fmt.Sprintf("138%08d", userCount*2+2)}
|
||||
if err := db.Create(&renter).Error; err != nil {
|
||||
t.Fatalf("创建租客失败: %v", err)
|
||||
}
|
||||
@@ -74,6 +80,7 @@ func createDisputeOrderFixture(t *testing.T, db *gorm.DB, order model.RentalOrde
|
||||
t.Fatalf("创建账号失败: %v", err)
|
||||
}
|
||||
listing := model.RentalListing{
|
||||
ListingNo: fmt.Sprintf("L-DISPUTE-%d", userCount/2+1),
|
||||
AccountID: account.ID,
|
||||
OwnerID: owner.ID,
|
||||
PriceCent: 1000,
|
||||
@@ -84,7 +91,9 @@ func createDisputeOrderFixture(t *testing.T, db *gorm.DB, order model.RentalOrde
|
||||
if err := db.Create(&listing).Error; err != nil {
|
||||
t.Fatalf("创建商品失败: %v", err)
|
||||
}
|
||||
order.OrderNo = "RO202606130001"
|
||||
if order.OrderNo == "" {
|
||||
order.OrderNo = "RO202606130001"
|
||||
}
|
||||
order.ListingID = listing.ID
|
||||
order.AccountID = account.ID
|
||||
order.OwnerID = owner.ID
|
||||
@@ -812,6 +821,53 @@ func TestApplyAdminListFiltersSmartRouting(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminDisputeQueriesAndActionsAreScopedByBuyerTenant(t *testing.T) {
|
||||
db := setupDisputeTestDB(t)
|
||||
tenantA := model.Tenant{ID: 101, Code: "tenant_a", Name: "A站", Status: "active"}
|
||||
tenantB := model.Tenant{ID: 202, Code: "tenant_b", Name: "B站", Status: "active"}
|
||||
if err := db.Create(&tenantA).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&tenantB).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _, orderA := createDisputeOrderFixture(t, db, model.RentalOrder{
|
||||
OrderNo: "RO-DISPUTE-TENANT-A", BuyerTenantID: 101, SourceTenantID: 202, Status: "renting",
|
||||
})
|
||||
_, _, orderB := createDisputeOrderFixture(t, db, model.RentalOrder{
|
||||
OrderNo: "RO-DISPUTE-TENANT-B", BuyerTenantID: 202, SourceTenantID: 101, Status: "renting",
|
||||
})
|
||||
disputes := []model.Dispute{
|
||||
{OrderID: orderA.ID, InitiatorID: orderA.RenterID, InitiatorType: "user", TargetUserID: orderA.OwnerID, Type: "cannot_login", Status: "open"},
|
||||
{OrderID: orderB.ID, InitiatorID: orderB.RenterID, InitiatorType: "user", TargetUserID: orderB.OwnerID, Type: "cannot_login", Status: "open"},
|
||||
}
|
||||
if err := db.Create(&disputes).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 101})
|
||||
repo := NewRepository(db)
|
||||
result, err := repo.ListAdmin(ctx, AdminListQuery{Page: 1, PageSize: 20})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Total != 1 || result.Items[0].ID != disputes[0].ID {
|
||||
t.Fatalf("tenant dispute list = %+v", result)
|
||||
}
|
||||
if _, err := repo.FindAdminByID(ctx, disputes[1].ID); !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
t.Fatalf("cross-tenant dispute detail error = %v", err)
|
||||
}
|
||||
if _, err := repo.AdminCreateByOrder(ctx, 9, orderB.ID, AdminCreateRequest{
|
||||
Type: "cannot_login", Description: "越权测试", TargetRole: "owner",
|
||||
}, AuditMeta{}); !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
t.Fatalf("cross-tenant admin create error = %v", err)
|
||||
}
|
||||
if _, err := repo.Arbitrate(ctx, 9, disputes[1].ID, ArbitrateRequest{
|
||||
Result: "full_refund", Remark: "越权测试",
|
||||
}, AuditMeta{}); !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
t.Fatalf("cross-tenant arbitrate error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStampOwnerIncomeSiteUsesListingSite(t *testing.T) {
|
||||
siteID := uint64(3)
|
||||
orderID := uint64(9)
|
||||
|
||||
Reference in New Issue
Block a user