2fbd88f28e
- Title: "Senior Technical Consultant & Full-Stack Developer" - Add Swift & macOS Development skill category (SoundInbox, Commando) - Rename "AI-Assisted Development" → "AI Engineering & Integration" with MCP, ADK, Gemini, CLIP - Remove "Design Tools" (Corel Draw, GIMP) and "Legacy Enterprise" (Struts, Yii, Zend) - Remove jQuery, Assembler, Groovy; add Swift to programming languages - Rewrite Team Management with professional language - Proficiency scale: 1-5 → 1-10 (validation, tests, chat agent prompt) - Add SoundInbox (Swift) and Commando (Go+SwiftUI) to projects - Remove personal details: dateOfBirth, placeOfBirth, domestika, driverLicense - Trim weak LinkedIn Learning courses (speed reading, persuasive UX) - Fix Spanish soft_skills duplicates - Chat agent: 11 new assertions (proficiency scale, new projects, removed skills) - Fix hardcoded year 2025 in TestDefaultCVShortcut → time.Now().Year()
187 lines
4.4 KiB
Go
187 lines
4.4 KiB
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestHome tests the Home handler
|
|
func TestHome(t *testing.T) {
|
|
handler := newTestCVHandler(t, "localhost:8080", nil)
|
|
|
|
tests := []struct {
|
|
name string
|
|
lang string
|
|
expectStatus int
|
|
expectContains string
|
|
}{
|
|
{
|
|
name: "Default language (English)",
|
|
lang: "",
|
|
expectStatus: http.StatusOK,
|
|
expectContains: "Juan Andrés Moreno Rubio",
|
|
},
|
|
{
|
|
name: "English language",
|
|
lang: "en",
|
|
expectStatus: http.StatusOK,
|
|
expectContains: "Juan Andrés Moreno Rubio",
|
|
},
|
|
{
|
|
name: "Spanish language",
|
|
lang: "es",
|
|
expectStatus: http.StatusOK,
|
|
expectContains: "Juan Andrés Moreno Rubio",
|
|
},
|
|
{
|
|
name: "Invalid language",
|
|
lang: "fr",
|
|
expectStatus: http.StatusBadRequest,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
// Create request
|
|
req := httptest.NewRequest(http.MethodGet, "/?lang="+tt.lang, nil)
|
|
w := httptest.NewRecorder()
|
|
|
|
// Call handler
|
|
handler.Home(w, req)
|
|
|
|
// Check status code
|
|
if w.Code != tt.expectStatus {
|
|
t.Errorf("Expected status %d, got %d", tt.expectStatus, w.Code)
|
|
}
|
|
|
|
// Check response body contains expected content (if success)
|
|
if tt.expectStatus == http.StatusOK && tt.expectContains != "" {
|
|
body := w.Body.String()
|
|
if len(body) == 0 {
|
|
t.Error("Expected non-empty response body")
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestCVContent tests the CVContent handler
|
|
func TestCVContent(t *testing.T) {
|
|
handler := newTestCVHandler(t, "localhost:8080", nil)
|
|
|
|
tests := []struct {
|
|
name string
|
|
lang string
|
|
expectStatus int
|
|
}{
|
|
{
|
|
name: "Default language",
|
|
lang: "",
|
|
expectStatus: http.StatusOK,
|
|
},
|
|
{
|
|
name: "English language",
|
|
lang: "en",
|
|
expectStatus: http.StatusOK,
|
|
},
|
|
{
|
|
name: "Spanish language",
|
|
lang: "es",
|
|
expectStatus: http.StatusOK,
|
|
},
|
|
{
|
|
name: "Invalid language",
|
|
lang: "de",
|
|
expectStatus: http.StatusBadRequest,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
// Create request
|
|
req := httptest.NewRequest(http.MethodGet, "/cv-content?lang="+tt.lang, nil)
|
|
w := httptest.NewRecorder()
|
|
|
|
// Call handler
|
|
handler.CVContent(w, req)
|
|
|
|
// Check status code
|
|
if w.Code != tt.expectStatus {
|
|
t.Errorf("Expected status %d, got %d", tt.expectStatus, w.Code)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestDefaultCVShortcut tests the DefaultCVShortcut handler
|
|
// NOTE: This test requires a running server for PDF generation via chromedp
|
|
func TestDefaultCVShortcut(t *testing.T) {
|
|
// Skip if running in CI or if server is not available
|
|
// PDF generation requires a running HTTP server that chromedp can connect to
|
|
if testing.Short() {
|
|
t.Skip("Skipping PDF generation test - requires running server")
|
|
}
|
|
|
|
// Check if server is actually running on port 1999
|
|
resp, err := http.Get("http://localhost:1999/health")
|
|
if err != nil || resp.StatusCode != http.StatusOK {
|
|
t.Skip("Skipping PDF generation test - server not running on localhost:1999")
|
|
}
|
|
_ = resp.Body.Close()
|
|
|
|
handler := newTestCVHandler(t, "localhost:1999", nil)
|
|
|
|
currentYear := fmt.Sprintf("%d", time.Now().Year())
|
|
|
|
tests := []struct {
|
|
name string
|
|
path string
|
|
expectStatus int
|
|
}{
|
|
{
|
|
name: "Valid shortcut URL (current year EN)",
|
|
path: "/cv-jamr-" + currentYear + "-en.pdf",
|
|
expectStatus: http.StatusOK,
|
|
},
|
|
{
|
|
name: "Valid shortcut URL (current year ES)",
|
|
path: "/cv-jamr-" + currentYear + "-es.pdf",
|
|
expectStatus: http.StatusOK,
|
|
},
|
|
{
|
|
name: "Invalid year",
|
|
path: "/cv-jamr-2020-en.pdf",
|
|
expectStatus: http.StatusNotFound,
|
|
},
|
|
{
|
|
name: "Invalid language",
|
|
path: "/cv-jamr-" + currentYear + "-fr.pdf",
|
|
expectStatus: http.StatusNotFound,
|
|
},
|
|
{
|
|
name: "Invalid format",
|
|
path: "/cv-wrong-format.pdf",
|
|
expectStatus: http.StatusNotFound,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
// Create request
|
|
req := httptest.NewRequest(http.MethodGet, tt.path, nil)
|
|
w := httptest.NewRecorder()
|
|
|
|
// Call handler
|
|
handler.DefaultCVShortcut(w, req)
|
|
|
|
// Check status code
|
|
if w.Code != tt.expectStatus {
|
|
t.Errorf("Expected status %d, got %d", tt.expectStatus, w.Code)
|
|
}
|
|
})
|
|
}
|
|
}
|