feat: 完善 Rock 发货异常闭环与绑定判定
This commit is contained in:
@@ -215,7 +215,8 @@ func TestRockProvider_AntiGhostAndUIDMismatch(t *testing.T) {
|
||||
// 3. 买家扫错了号!拿了微信小号扫码,实际角色变成了“错误小号”(9999999999)
|
||||
currentBoundAccount = "错误小号"
|
||||
currentBoundRoleID = "9999999999"
|
||||
currentBindChangedAt = "2026-10-05 14:00:00"
|
||||
currentBindChangedAt = time.Now().In(timeutil.Location()).Add(time.Minute).Format("2006-01-02 15:04:05")
|
||||
rockSvc.refreshCache.Delete("151153")
|
||||
|
||||
check2, err := provider.CheckBind(context.Background(), order, bindRes.BindUUID)
|
||||
if err != nil {
|
||||
@@ -275,12 +276,14 @@ func TestRockProvider_AntiGhostAndUIDMismatch(t *testing.T) {
|
||||
// 5. 重新绑定正确账号“感性的洁少”(3688825401)
|
||||
currentBoundAccount = "感性的洁少"
|
||||
currentBoundRoleID = "3688825401"
|
||||
currentBindChangedAt = "2026-10-05 14:05:00"
|
||||
currentBindChangedAt = ""
|
||||
|
||||
bindRes2, err := provider.Bind(context.Background(), order, expectedUID)
|
||||
if err != nil {
|
||||
t.Fatalf("rebind error: %v", err)
|
||||
}
|
||||
currentBindChangedAt = time.Now().In(timeutil.Location()).Add(time.Minute).Format("2006-01-02 15:04:05")
|
||||
rockSvc.refreshCache.Delete("151153")
|
||||
check3, err := provider.CheckBind(context.Background(), order, bindRes2.BindUUID)
|
||||
if err != nil {
|
||||
t.Fatalf("check bind match: %v", err)
|
||||
@@ -638,6 +641,7 @@ func TestReleaseUnboundUsingToken(t *testing.T) {
|
||||
}
|
||||
|
||||
// 上游已经出现新扫码时拒绝释放。
|
||||
releaseBaseline := time.Now().Add(-time.Hour)
|
||||
using := model.RockToken{
|
||||
UpstreamTokenID: "88002",
|
||||
Token: "jwt2",
|
||||
@@ -646,12 +650,13 @@ func TestReleaseUnboundUsingToken(t *testing.T) {
|
||||
Status: model.RockStatusUsing,
|
||||
AssignedOrderNo: "FO-RELEASE-2",
|
||||
ExpectedUID: "3688825401",
|
||||
ClaimedAt: &releaseBaseline,
|
||||
}
|
||||
if err := db.Create(&using).Error; err != nil {
|
||||
t.Fatalf("create using token: %v", err)
|
||||
}
|
||||
boundRoleID = "3688825401"
|
||||
bindChangedAt = "2026-10-05 21:10:00"
|
||||
bindChangedAt = time.Now().In(timeutil.Location()).Add(-30 * time.Minute).Format("2006-01-02 15:04:05")
|
||||
if err := rockSvc.ReleaseUnboundUsingToken(context.Background(), using.ID, false, nil); err == nil || !strings.Contains(err.Error(), "已扫码绑定") {
|
||||
t.Fatalf("已绑定链接必须拒绝释放,实际: %v", err)
|
||||
}
|
||||
@@ -705,13 +710,15 @@ func TestReleaseUnboundUsingToken(t *testing.T) {
|
||||
boundRoleID = "4744920014"
|
||||
bindChangedAt = "2026-10-05 21:52:30"
|
||||
deliveryTime = "2026-10-05T21:52:40.61"
|
||||
if err := rockSvc.ReleaseUnboundUsingToken(context.Background(), fresh.ID, false, nil); err == nil || !strings.Contains(err.Error(), "已扫码绑定") {
|
||||
if err := rockSvc.ReleaseUnboundUsingToken(context.Background(), fresh.ID, false, nil); err == nil ||
|
||||
(!strings.Contains(err.Error(), "已扫码绑定") && !strings.Contains(err.Error(), "上游已发货")) {
|
||||
t.Fatalf("领取后的新发货必须拒绝释放,实际: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRockProvider_SchemeB_UIDSelfHealing(t *testing.T) {
|
||||
db := newRockTestDB(t)
|
||||
currentBindChangedAt := ""
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@@ -728,7 +735,7 @@ func TestRockProvider_SchemeB_UIDSelfHealing(t *testing.T) {
|
||||
"token": map[string]interface{}{
|
||||
"id": 152001,
|
||||
"status": "bound",
|
||||
"bind_changed_at": "2026-10-06 10:00:00",
|
||||
"bind_changed_at": currentBindChangedAt,
|
||||
"bound_account": "少年有点忧郁",
|
||||
"bound_account_id": "3454648872",
|
||||
"region": "安卓-微信",
|
||||
@@ -771,6 +778,7 @@ func TestRockProvider_SchemeB_UIDSelfHealing(t *testing.T) {
|
||||
if bindRes1.Bound {
|
||||
t.Fatalf("尚未扫码,bound 应为 false")
|
||||
}
|
||||
currentBindChangedAt = time.Now().In(timeutil.Location()).Add(time.Minute).Format("2006-01-02 15:04:05")
|
||||
|
||||
// 2. 扫码反查,真实角色是 3454648872,发生 mismatch
|
||||
check1, err := provider.CheckBind(ctx, order, bindRes1.BindUUID)
|
||||
|
||||
Reference in New Issue
Block a user