- backend: AdminOrderListItemDTO 不再脱敏 owner_phone/renter_phone,移除 order 包内已无用的 maskPhone - frontend: 同步 AdminOrderListItem 类型注释 - tests: 更新后台列表用例为断言完整手机号,并继续校验不泄露账号快照
96 lines
2.8 KiB
Go
96 lines
2.8 KiB
Go
package order
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"hfb_sys/backend/internal/model"
|
|
)
|
|
|
|
func TestOrderDTOForUserHidesDepositHoldFields(t *testing.T) {
|
|
now := time.Now()
|
|
row := orderRow{
|
|
RentalOrder: model.RentalOrder{
|
|
ID: 1,
|
|
OwnerID: 10,
|
|
RenterID: 20,
|
|
DepositHoldStatus: model.DepositHoldStatusHeld,
|
|
DepositHoldAmountCent: 1000,
|
|
DepositHoldReason: "风控复核",
|
|
DepositHeldAt: &now,
|
|
DepositHoldReleasedAt: &now,
|
|
},
|
|
}
|
|
|
|
dto := row.toDTOForUser(20)
|
|
if dto.DepositHoldStatus != "" {
|
|
t.Fatalf("deposit hold status = %q, want empty", dto.DepositHoldStatus)
|
|
}
|
|
if dto.DepositHoldAmountCent != 0 {
|
|
t.Fatalf("deposit hold amount = %d, want 0", dto.DepositHoldAmountCent)
|
|
}
|
|
if dto.DepositHoldReason != "" {
|
|
t.Fatalf("deposit hold reason = %q, want empty", dto.DepositHoldReason)
|
|
}
|
|
if dto.DepositHeldAt != nil {
|
|
t.Fatalf("deposit held at = %v, want nil", dto.DepositHeldAt)
|
|
}
|
|
if dto.DepositHoldReleasedAt != nil {
|
|
t.Fatalf("deposit hold released at = %v, want nil", dto.DepositHoldReleasedAt)
|
|
}
|
|
}
|
|
|
|
func TestUserOrderListItemDoesNotSerializeDetailFields(t *testing.T) {
|
|
row := orderRow{
|
|
RentalOrder: model.RentalOrder{
|
|
ID: 1,
|
|
OrderNo: "ORD-001",
|
|
ListingID: 2,
|
|
OwnerID: 10,
|
|
RenterID: 20,
|
|
RentAmountCent: 1000,
|
|
DepositAmountCent: 2000,
|
|
DepositHoldReason: "风控复核",
|
|
DepositFreeManualQuotaCent: 5000,
|
|
Status: orderStatusPendingPayment,
|
|
},
|
|
ListingNo: "SP000002",
|
|
Title: "测试账号",
|
|
}
|
|
|
|
raw, err := json.Marshal(row.toUserListItem(20, nil))
|
|
if err != nil {
|
|
t.Fatalf("Marshal() error = %v", err)
|
|
}
|
|
text := string(raw)
|
|
for _, field := range []string{"account_snapshot", "deposit_hold_reason", "deposit_free_manual_quota_cent", "owner_id", "renter_id"} {
|
|
if strings.Contains(text, field) {
|
|
t.Fatalf("list response contains sensitive field %q: %s", field, text)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAdminOrderListItemShowsPhonesAndOmitsSnapshot(t *testing.T) {
|
|
row := orderRow{
|
|
RentalOrder: model.RentalOrder{ID: 1, OrderNo: "ORD-001", Status: orderStatusPendingPayment},
|
|
OwnerPhone: "13800001234",
|
|
RenterPhone: "13900005678",
|
|
}
|
|
raw, err := json.Marshal(row.toAdminListItem())
|
|
if err != nil {
|
|
t.Fatalf("Marshal() error = %v", err)
|
|
}
|
|
text := string(raw)
|
|
// 后台订单列表需要展示完整手机号,方便客服定位用户。
|
|
for _, phone := range []string{"13800001234", "13900005678"} {
|
|
if !strings.Contains(text, phone) {
|
|
t.Fatalf("list response should contain full phone %q: %s", phone, text)
|
|
}
|
|
}
|
|
if strings.Contains(text, "account_snapshot") {
|
|
t.Fatalf("list response contains account snapshot: %s", text)
|
|
}
|
|
}
|