refactor: consolidate lang into constants, rename services to email

- Merge lang package into constants (add IsValidLang, ValidateLang, AllLangs)
- Rename internal/services to internal/email for consistency with pdf package
- Rename types to avoid redundancy: EmailService→Service, EmailConfig→Config
- Update all imports and references across codebase
- Delete internal/lang directory (functions moved to constants)
This commit is contained in:
juanatsap
2025-12-06 17:05:17 +00:00
parent 30ed21ff7a
commit c89b67a06d
28 changed files with 241 additions and 290 deletions
+13 -13
View File
@@ -8,7 +8,7 @@ import (
"testing"
"time"
"github.com/juanatsap/cv-site/internal/services"
"github.com/juanatsap/cv-site/internal/email"
)
// TestSMTPConnection tests that SMTP credentials are valid and connection works
@@ -123,7 +123,7 @@ func TestEmailServiceSend(t *testing.T) {
t.Skip("Skipping email send test: CONTACT_EMAIL not configured")
}
config := &services.EmailConfig{
config := &email.Config{
SMTPHost: host,
SMTPPort: port,
SMTPUser: user,
@@ -132,9 +132,9 @@ func TestEmailServiceSend(t *testing.T) {
ToEmail: to,
}
emailService := services.NewEmailService(config)
emailService := email.NewService(config)
testData := &services.ContactFormData{
testData := &email.ContactFormData{
Email: "test-sender@example.com",
Name: "Integration Test",
Company: "Test Suite",
@@ -155,7 +155,7 @@ func TestEmailServiceSend(t *testing.T) {
// TestEmailServiceValidation tests that the email service properly validates input
func TestEmailServiceValidation(t *testing.T) {
config := &services.EmailConfig{
config := &email.Config{
SMTPHost: "smtp.test.com",
SMTPPort: "465",
SMTPUser: "test@test.com",
@@ -164,17 +164,17 @@ func TestEmailServiceValidation(t *testing.T) {
ToEmail: "to@test.com",
}
emailService := services.NewEmailService(config)
emailService := email.NewService(config)
tests := []struct {
name string
data *services.ContactFormData
data *email.ContactFormData
wantErr bool
errMsg string
}{
{
name: "valid data",
data: &services.ContactFormData{
data: &email.ContactFormData{
Email: "valid@example.com",
Name: "Valid User",
Message: "This is a valid message with more than 10 characters.",
@@ -184,7 +184,7 @@ func TestEmailServiceValidation(t *testing.T) {
},
{
name: "missing email",
data: &services.ContactFormData{
data: &email.ContactFormData{
Name: "No Email",
Message: "This is a valid message.",
Time: time.Now(),
@@ -194,7 +194,7 @@ func TestEmailServiceValidation(t *testing.T) {
},
{
name: "invalid email format",
data: &services.ContactFormData{
data: &email.ContactFormData{
Email: "notanemail",
Name: "Bad Email",
Message: "This is a valid message.",
@@ -205,7 +205,7 @@ func TestEmailServiceValidation(t *testing.T) {
},
{
name: "missing message",
data: &services.ContactFormData{
data: &email.ContactFormData{
Email: "valid@example.com",
Name: "No Message",
Time: time.Now(),
@@ -215,7 +215,7 @@ func TestEmailServiceValidation(t *testing.T) {
},
{
name: "message too short",
data: &services.ContactFormData{
data: &email.ContactFormData{
Email: "valid@example.com",
Name: "Short Msg",
Message: "Hi",
@@ -226,7 +226,7 @@ func TestEmailServiceValidation(t *testing.T) {
},
{
name: "email with newlines (header injection)",
data: &services.ContactFormData{
data: &email.ContactFormData{
Email: "test@example.com\nBcc: attacker@evil.com",
Name: "Attacker",
Message: "Trying to inject headers.",
+2 -2
View File
@@ -11,14 +11,14 @@ import (
"github.com/juanatsap/cv-site/internal/handlers"
"github.com/juanatsap/cv-site/internal/middleware"
"github.com/juanatsap/cv-site/internal/services"
"github.com/juanatsap/cv-site/internal/email"
"github.com/juanatsap/cv-site/internal/templates"
)
// mockEmailSender is a mock implementation of handlers.EmailSender for testing
type mockEmailSender struct{}
func (m *mockEmailSender) SendContactForm(data *services.ContactFormData) error {
func (m *mockEmailSender) SendContactForm(data *email.ContactFormData) error {
// Validate like the real service would
if err := data.Validate(); err != nil {
return fmt.Errorf("validation failed: %w", err)