mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-14 03:52:26 +08:00
Merge pull request #6821 from 22zyfeng-collab/fix/antigravity-oauth-plan-type
fix(antigravity): preserve OAuth plan_type when saving accounts
This commit is contained in:
@@ -90,7 +90,7 @@ type AntigravityTokenInfo struct {
|
||||
Email string `json:"email,omitempty"`
|
||||
ProjectID string `json:"project_id,omitempty"`
|
||||
ProjectIDMissing bool `json:"-"`
|
||||
PlanType string `json:"-"`
|
||||
PlanType string `json:"plan_type,omitempty"`
|
||||
PrivacyMode string `json:"-"`
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -80,3 +81,26 @@ func TestResolveDefaultTierID(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// The OAuth handler serializes this DTO before the browser creates or reauthorizes an account.
|
||||
func TestAntigravityTokenInfoPreservesPlanTypeJSON(t *testing.T) {
|
||||
for _, plan := range []string{"pro", "ultra", "free", ""} {
|
||||
t.Run(plan, func(t *testing.T) {
|
||||
data, err := json.Marshal(AntigravityTokenInfo{PlanType: plan})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var response map[string]any
|
||||
if err := json.Unmarshal(data, &response); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if plan == "" {
|
||||
if _, exists := response["plan_type"]; exists {
|
||||
t.Fatal("unknown plan must remain omitted")
|
||||
}
|
||||
} else if response["plan_type"] != plan {
|
||||
t.Fatalf("OAuth response plan_type = %v, want %q", response["plan_type"], plan)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ export interface AntigravityTokenInfo {
|
||||
expires_at?: number | string
|
||||
expires_in?: number
|
||||
project_id?: string
|
||||
plan_type?: string
|
||||
email?: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
@@ -54,3 +54,17 @@ describe('useAntigravityOAuth.buildCredentials', () => {
|
||||
expect(credentials.refresh_token).toBe('rotated-refresh-token')
|
||||
})
|
||||
})
|
||||
|
||||
// This builder is shared by OAuth creation, refresh-token import and reauthorization.
|
||||
describe('Antigravity subscription metadata', () => {
|
||||
it.each(['pro', 'ultra', 'free'])('preserves the upstream %s plan when saving credentials', (plan) => {
|
||||
const oauth = useAntigravityOAuth()
|
||||
const credentials = oauth.buildCredentials({ plan_type: plan })
|
||||
expect(credentials.plan_type).toBe(plan)
|
||||
})
|
||||
|
||||
it('does not invent a plan when subscription discovery is unavailable', () => {
|
||||
const credentials = useAntigravityOAuth().buildCredentials({})
|
||||
expect(credentials).not.toHaveProperty('plan_type')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -132,7 +132,8 @@ export function useAntigravityOAuth() {
|
||||
token_type: tokenInfo.token_type,
|
||||
expires_at: expiresAt,
|
||||
project_id: tokenInfo.project_id,
|
||||
email: tokenInfo.email
|
||||
email: tokenInfo.email,
|
||||
...(tokenInfo.plan_type ? { plan_type: tokenInfo.plan_type } : {})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user