Decouple email sync tests from local stubs

This commit is contained in:
IanShaw027
2026-04-21 00:16:06 +08:00
parent 16be82b959
commit b79052aaf2
2 changed files with 114 additions and 59 deletions

View File

@@ -5,48 +5,17 @@ package service
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
)
type emailSyncMockUserRepo struct {
*mockUserRepo
ensureCalls []ensureEmailCall
replaceCalls []replaceEmailCall
}
func (m *emailSyncMockUserRepo) EnsureEmailAuthIdentity(_ context.Context, userID int64, email string) error {
m.ensureCalls = append(m.ensureCalls, ensureEmailCall{userID: userID, email: email})
return nil
}
func (m *emailSyncMockUserRepo) ReplaceEmailAuthIdentity(_ context.Context, userID int64, oldEmail, newEmail string) error {
m.replaceCalls = append(m.replaceCalls, replaceEmailCall{
userID: userID,
oldEmail: oldEmail,
newEmail: newEmail,
})
return nil
}
func (m *emailSyncMockUserRepo) GetLatestUsedAtByUserIDs(context.Context, []int64) (map[int64]*time.Time, error) {
return map[int64]*time.Time{}, nil
}
func (m *emailSyncMockUserRepo) GetLatestUsedAtByUserID(context.Context, int64) (*time.Time, error) {
return nil, nil
}
func TestUpdateProfile_ReplacesEmailAuthIdentityWhenEmailChanges(t *testing.T) {
repo := &emailSyncMockUserRepo{
mockUserRepo: &mockUserRepo{
getByIDUser: &User{
ID: 19,
Email: "profile-before@example.com",
Username: "tester",
Concurrency: 2,
},
repo := &emailSyncRepoStub{
user: &User{
ID: 19,
Email: "profile-before@example.com",
Username: "tester",
Concurrency: 2,
},
}
svc := NewUserService(repo, nil, nil, nil)