removed redirec t

This commit is contained in:
2026-01-06 09:07:24 +08:00
parent 744796a4b1
commit 679a7a9a42
4 changed files with 27 additions and 133 deletions
-14
View File
@@ -5,20 +5,6 @@ import (
"log"
)
func GetUser(email string) (string, *string, *string, string, error) {
log.Print(email)
query := `SELECT user_id, first_name, last_name, email_address FROM users WHERE email_address = ? AND is_deleted = 0 LIMIT 1;`
var id string
var firstName *string
var lastName *string
var emailAddress string
err := db.DB.QueryRow(query, email).Scan(&id, &firstName, &lastName, &emailAddress)
if err != nil {
return "", nil, nil, "", err
}
return id, firstName, lastName, emailAddress, nil
}
func GetUserID(email string) (string, error) {
log.Print(email)
query := `SELECT user_id, FROM users WHERE email_address = ? AND is_deleted = 0 LIMIT 1;`
+3 -65
View File
@@ -43,31 +43,6 @@ func TestGetUser(t *testing.T) {
WithArgs(email).
WillReturnRows(rows)
id, firstName, lastName, emailAddress, err := GetUser(email)
if err != nil {
t.Errorf("Expected no error, got: %v", err)
}
if id != expectedID {
t.Errorf("Expected ID %s, got %s", expectedID, id)
}
if firstName == nil || *firstName != expectedFirstName {
t.Errorf("Expected first name %s, got %v", expectedFirstName, firstName)
}
if lastName == nil || *lastName != expectedLastName {
t.Errorf("Expected last name %s, got %v", expectedLastName, lastName)
}
if emailAddress != expectedEmail {
t.Errorf("Expected email %s, got %s", expectedEmail, emailAddress)
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("Unfulfilled expectations: %v", err)
}
}
func TestGetUserNotFound(t *testing.T) {
@@ -80,7 +55,7 @@ func TestGetUserNotFound(t *testing.T) {
WithArgs(email).
WillReturnError(sql.ErrNoRows)
id, firstName, lastName, emailAddress, err := GetUser(email)
id, err := GetUserID(email)
if err != sql.ErrNoRows {
t.Errorf("Expected sql.ErrNoRows, got: %v", err)
@@ -89,18 +64,6 @@ func TestGetUserNotFound(t *testing.T) {
if id != "" {
t.Errorf("Expected empty ID, got %s", id)
}
if firstName != nil {
t.Errorf("Expected nil firstName, got %v", firstName)
}
if lastName != nil {
t.Errorf("Expected nil lastName, got %v", lastName)
}
if emailAddress != "" {
t.Errorf("Expected empty email, got %s", emailAddress)
}
}
func TestGetUserNullNames(t *testing.T) {
@@ -117,7 +80,7 @@ func TestGetUserNullNames(t *testing.T) {
WithArgs(email).
WillReturnRows(rows)
id, firstName, lastName, emailAddress, err := GetUser(email)
id, err := GetUserID(email)
if err != nil {
t.Errorf("Expected no error, got: %v", err)
@@ -127,17 +90,6 @@ func TestGetUserNullNames(t *testing.T) {
t.Errorf("Expected ID %s, got %s", expectedID, id)
}
if firstName != nil {
t.Errorf("Expected nil firstName for NULL value, got %v", firstName)
}
if lastName != nil {
t.Errorf("Expected nil lastName for NULL value, got %v", lastName)
}
if emailAddress != email {
t.Errorf("Expected email %s, got %s", email, emailAddress)
}
}
func TestGetUserID(t *testing.T) {
@@ -346,7 +298,7 @@ func TestGetUserMultipleEmails(t *testing.T) {
WithArgs(tc.email).
WillReturnRows(rows)
id, fn, ln, email, err := GetUser(tc.email)
id, err := GetUserID(tc.email)
if err != nil {
t.Errorf("Expected no error, got: %v", err)
@@ -355,20 +307,6 @@ func TestGetUserMultipleEmails(t *testing.T) {
if id != tc.userID {
t.Errorf("Expected ID %s, got %s", tc.userID, id)
}
if tc.hasNames {
if fn == nil || ln == nil {
t.Error("Expected names to be present")
}
} else {
if fn != nil || ln != nil {
t.Error("Expected names to be nil")
}
}
if email != tc.email {
t.Errorf("Expected email %s, got %s", tc.email, email)
}
})
}
}