diff --git a/api/user/domain/valueObjects/userEmail.go b/api/user/domain/valueObjects/userEmail.go index f1c1530..b66ac6c 100644 --- a/api/user/domain/valueObjects/userEmail.go +++ b/api/user/domain/valueObjects/userEmail.go @@ -1,7 +1,6 @@ package userValueObjects import ( - "go-rest-template/internal/app/utils" "go-rest-template/internal/app/web" "net/http" "regexp" @@ -14,7 +13,6 @@ type Email struct { func ValidateEmail(value string) (*Email, *web.HttpError) { emailRegex := regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`) if result := emailRegex.MatchString(value); result == false { - utils.Print(result) return nil, &web.HttpError{ Code: http.StatusUnprocessableEntity, Body: map[string]interface{}{ diff --git a/api/user/domain/valueObjects/userEmail_test.go b/api/user/domain/valueObjects/userEmail_test.go new file mode 100644 index 0000000..d0ddf81 --- /dev/null +++ b/api/user/domain/valueObjects/userEmail_test.go @@ -0,0 +1,38 @@ +package userValueObjects + +import ( + "testing" +) + +func TestEmptyEmail(t *testing.T) { + t.Parallel() + email, err := ValidateEmail("") + if email != nil { + t.Errorf("Expected nil, got %v", email) + } + if err == nil { + t.Errorf("Expected error, got nil") + } +} + +func TestInvalidEmail(t *testing.T) { + t.Parallel() + email, err := ValidateEmail("invalidemail") + if email != nil { + t.Errorf("Expected nil, got %v", email) + } + if err == nil { + t.Errorf("Expected error, got nil") + } +} + +func TestValidEmail(t *testing.T) { + t.Parallel() + email, err := ValidateEmail("validemail@gmail.com") + if email == nil { + t.Errorf("Expected email, got nil") + } + if err != nil { + t.Errorf("Expected nil, got %v", err) + } +}