mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-19 10:54:23 +08:00
Merge pull request #4558 from fengshao1227/fix/antigravity-plan-type-preserve
fix(antigravity): 保留付费 tier 的 PlanType,IneligibleTiers 仅标记异常状态
This commit is contained in:
@@ -21,9 +21,14 @@ func NormalizeAntigravitySubscription(resp *antigravity.LoadCodeAssistResponse)
|
||||
if resp == nil {
|
||||
return AntigravitySubscriptionResult{PlanType: "Free"}
|
||||
}
|
||||
tierID := resp.GetTier()
|
||||
planType := antigravity.TierIDToPlanType(tierID)
|
||||
if len(resp.IneligibleTiers) > 0 {
|
||||
if planType == "" || planType == "Free" {
|
||||
planType = "Abnormal"
|
||||
}
|
||||
result := AntigravitySubscriptionResult{
|
||||
PlanType: "Abnormal",
|
||||
PlanType: planType,
|
||||
SubscriptionStatus: antigravitySubscriptionAbnormal,
|
||||
}
|
||||
if resp.IneligibleTiers[0] != nil {
|
||||
@@ -31,8 +36,7 @@ func NormalizeAntigravitySubscription(resp *antigravity.LoadCodeAssistResponse)
|
||||
}
|
||||
return result
|
||||
}
|
||||
tierID := resp.GetTier()
|
||||
return AntigravitySubscriptionResult{
|
||||
PlanType: antigravity.TierIDToPlanType(tierID),
|
||||
PlanType: planType,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Wei-Shaw/sub2api/internal/pkg/antigravity"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNormalizeAntigravitySubscription_PaidTierWithIneligible(t *testing.T) {
|
||||
resp := &antigravity.LoadCodeAssistResponse{
|
||||
PaidTier: &antigravity.PaidTierInfo{ID: "g1-pro-tier"},
|
||||
IneligibleTiers: []*antigravity.IneligibleTier{
|
||||
{ReasonMessage: "location validation required"},
|
||||
},
|
||||
}
|
||||
|
||||
result := NormalizeAntigravitySubscription(resp)
|
||||
|
||||
assert.Equal(t, "Pro", result.PlanType, "paid tier should preserve Pro even with ineligible tiers")
|
||||
assert.Equal(t, "abnormal", result.SubscriptionStatus)
|
||||
assert.Equal(t, "location validation required", result.SubscriptionError)
|
||||
}
|
||||
|
||||
func TestNormalizeAntigravitySubscription_FreeTierWithIneligible(t *testing.T) {
|
||||
resp := &antigravity.LoadCodeAssistResponse{
|
||||
PaidTier: &antigravity.PaidTierInfo{ID: "free-tier"},
|
||||
IneligibleTiers: []*antigravity.IneligibleTier{
|
||||
{ReasonMessage: "some warning"},
|
||||
},
|
||||
}
|
||||
|
||||
result := NormalizeAntigravitySubscription(resp)
|
||||
|
||||
assert.Equal(t, "Abnormal", result.PlanType, "free tier with ineligible should be Abnormal")
|
||||
assert.Equal(t, "abnormal", result.SubscriptionStatus)
|
||||
}
|
||||
|
||||
func TestNormalizeAntigravitySubscription_NoIneligible(t *testing.T) {
|
||||
resp := &antigravity.LoadCodeAssistResponse{
|
||||
PaidTier: &antigravity.PaidTierInfo{ID: "g1-ultra-tier"},
|
||||
}
|
||||
|
||||
result := NormalizeAntigravitySubscription(resp)
|
||||
|
||||
assert.Equal(t, "Ultra", result.PlanType)
|
||||
assert.Empty(t, result.SubscriptionStatus)
|
||||
}
|
||||
|
||||
func TestNormalizeAntigravitySubscription_NilResponse(t *testing.T) {
|
||||
result := NormalizeAntigravitySubscription(nil)
|
||||
assert.Equal(t, "Free", result.PlanType)
|
||||
}
|
||||
|
||||
func TestNormalizeAntigravitySubscription_NoTierWithIneligible(t *testing.T) {
|
||||
resp := &antigravity.LoadCodeAssistResponse{
|
||||
IneligibleTiers: []*antigravity.IneligibleTier{
|
||||
{ReasonMessage: "unknown issue"},
|
||||
},
|
||||
}
|
||||
|
||||
result := NormalizeAntigravitySubscription(resp)
|
||||
|
||||
assert.Equal(t, "Abnormal", result.PlanType, "no tier + ineligible should be Abnormal")
|
||||
assert.Equal(t, "abnormal", result.SubscriptionStatus)
|
||||
}
|
||||
Reference in New Issue
Block a user