fix: 更新邮箱 OAuth 单测契约

This commit is contained in:
lyen1688
2026-05-06 17:19:20 +08:00
parent 93f884b719
commit 480fe27b31
3 changed files with 104 additions and 3 deletions
@@ -229,6 +229,67 @@ func TestRegisterOAuthEmailAccountSetsNormalizedSignupSourceOnCreatedUser(t *tes
require.Equal(t, "oidc", userRepo.created[0].SignupSource)
}
func TestRegisterOAuthEmailAccountKeepsGitHubAndGoogleSignupSource(t *testing.T) {
tests := []struct {
name string
email string
signupSource string
want string
}{
{
name: "github",
email: "github@example.com",
signupSource: " GitHub ",
want: "github",
},
{
name: "google",
email: "google@example.com",
signupSource: " Google ",
want: "google",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
userRepo := &userRepoStub{nextID: 43}
emailCache := &emailCacheStub{
data: &VerificationCodeData{
Code: "246810",
Attempts: 0,
CreatedAt: time.Now().UTC(),
ExpiresAt: time.Now().UTC().Add(15 * time.Minute),
},
}
authService := newOAuthEmailFlowAuthService(
userRepo,
&redeemCodeRepoStub{},
&refreshTokenCacheStub{},
map[string]string{
SettingKeyRegistrationEnabled: "true",
SettingKeyEmailVerifyEnabled: "true",
},
emailCache,
)
tokenPair, user, err := authService.RegisterOAuthEmailAccount(
context.Background(),
tt.email,
"secret-123",
"246810",
"",
tt.signupSource,
)
require.NoError(t, err)
require.NotNil(t, tokenPair)
require.NotNil(t, user)
require.Len(t, userRepo.created, 1)
require.Equal(t, tt.want, userRepo.created[0].SignupSource)
})
}
}
func TestRegisterOAuthEmailAccountFallsBackUnknownSignupSourceToEmail(t *testing.T) {
userRepo := &userRepoStub{nextID: 43}
emailCache := &emailCacheStub{
@@ -256,7 +317,7 @@ func TestRegisterOAuthEmailAccountFallsBackUnknownSignupSourceToEmail(t *testing
"secret-123",
"246810",
"",
"github",
"unknown-provider",
)
require.NoError(t, err)