Backend: - Password reset flow (forgot/reset endpoints, tokens table) - Profile management (PUT /users/me, skills, experience, education) - Tickets system (CRUD, messages, stats) - Activity logs (list, stats) - Document validator (CNPJ, CPF, EIN support) - Input sanitizer (XSS prevention) - Full-text search em vagas (plainto_tsquery) - Filtros avançados (location, salary, workMode) - Ordenação (date, salary, relevance) Frontend: - Forgot/Reset password pages - Candidate profile edit page - Sanitize utilities (sanitize.ts) Backoffice: - TicketsModule proxy - ActivityLogsModule proxy - Dockerfile otimizado (multi-stage, non-root, healthcheck) Migrations: - 013: Profile fields to users - 014: Password reset tokens - 015: Tickets table - 016: Activity logs table
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
package services_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/DATA-DOG/go-sqlmock"
|
|
"github.com/rede5/gohorsejobs/backend/internal/dto"
|
|
"github.com/rede5/gohorsejobs/backend/internal/services"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type MockEmailService struct {
|
|
SentEmails []struct {
|
|
To string
|
|
Subject string
|
|
Body string
|
|
}
|
|
}
|
|
|
|
func (m *MockEmailService) SendEmail(to, subject, body string) error {
|
|
m.SentEmails = append(m.SentEmails, struct {
|
|
To string
|
|
Subject string
|
|
Body string
|
|
}{To: to, Subject: subject, Body: body})
|
|
return nil
|
|
}
|
|
|
|
func StringPtr(s string) *string {
|
|
return &s
|
|
}
|
|
|
|
func IntPtr(i int) *int {
|
|
return &i
|
|
}
|
|
|
|
func TestCreateApplication_Success(t *testing.T) {
|
|
db, mock, err := sqlmock.New()
|
|
assert.NoError(t, err)
|
|
defer db.Close()
|
|
|
|
emailService := &MockEmailService{}
|
|
service := services.NewApplicationService(db, emailService)
|
|
|
|
req := dto.CreateApplicationRequest{
|
|
JobID: 1,
|
|
UserID: IntPtr(123),
|
|
Name: StringPtr("John Doe"),
|
|
Email: StringPtr("john@example.com"),
|
|
Phone: StringPtr("1234567890"),
|
|
}
|
|
|
|
rows := sqlmock.NewRows([]string{"id", "created_at", "updated_at"}).
|
|
AddRow(1, time.Now(), time.Now())
|
|
|
|
mock.ExpectQuery("INSERT INTO applications").
|
|
WillReturnRows(rows)
|
|
|
|
app, err := service.CreateApplication(req)
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, app)
|
|
assert.Equal(t, 1, app.ID)
|
|
|
|
// Wait for goroutine to finish (simple sleep for test, ideal would be waitgroup but svc doesn't expose it)
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
if len(emailService.SentEmails) == 0 {
|
|
t.Error("Expected email to be sent")
|
|
} else {
|
|
assert.Equal(t, "company@example.com", emailService.SentEmails[0].To)
|
|
assert.Contains(t, emailService.SentEmails[0].Subject, "Nova candidatura")
|
|
}
|
|
}
|