Files
cv-site/internal/models/cv/loader_test.go
T
juanatsap 7b60fdcf9c refactor: Separate CV domain and UI presentation models into distinct packages
**Main Changes:**

1. **Package Restructuring** - Separated mixed concerns into focused packages:
   - Created `internal/models/cv/` for CV domain logic (CV, Personal, Experience, etc.)
   - Created `internal/models/ui/` for UI presentation logic (InfoModal, ShortcutsModal, etc.)
   - Removed monolithic `internal/models/cv.go` (300+ lines → organized packages)

2. **Testing** - Added comprehensive unit tests:
   - `internal/models/cv/loader_test.go` - CV data loading and validation
   - `internal/models/ui/loader_test.go` - UI translations loading
   - All tests passing 

3. **Documentation** - Added Go learning knowledge base:
   - `_go-learning/architecture/server-design.md` - Goroutines, graceful shutdown explained
   - `_go-learning/refactorings/001-cv-model-separation.md` - This refactoring documented
   - Public documentation showcasing Go expertise (README.md kept private)

4. **Handler Updates** - Updated imports to use new package structure:
   - `internal/handlers/cv.go` - Uses `cvmodel` and `uimodel` aliases

**Benefits:**
-  Clear separation of concerns (domain vs presentation)
-  Better testability (isolated package testing)
-  Improved maintainability (smaller, focused files)
-  Scalability (each domain can evolve independently)
-  Follows Go best practices (small, cohesive packages)

**Other Updates:**
- Updated middleware security checks
- Template improvements
- Organized completed prompts

**Testing:**
- All Go unit tests pass (cv, ui, handlers)
- Server verified with curl tests (English, Spanish, Health endpoints)
- Frontend functionality unchanged (refactoring is transparent to UI)
2025-11-20 16:17:56 +00:00

101 lines
2.0 KiB
Go

package cv_test
import (
"testing"
"github.com/juanatsap/cv-site/internal/models/cv"
)
func TestLoadCV(t *testing.T) {
tests := []struct {
name string
lang string
wantErr bool
}{
{
name: "English CV",
lang: "en",
wantErr: false,
},
{
name: "Spanish CV",
lang: "es",
wantErr: false,
},
{
name: "Invalid language",
lang: "fr",
wantErr: true,
},
{
name: "Empty language",
lang: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cvData, err := cv.LoadCV(tt.lang)
if (err != nil) != tt.wantErr {
t.Errorf("LoadCV() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr {
if cvData == nil {
t.Error("LoadCV() returned nil CV data")
return
}
// Validate CV has essential data
if cvData.Personal.Name == "" {
t.Error("LoadCV() returned CV with empty name")
}
if len(cvData.Experience) == 0 {
t.Error("LoadCV() returned CV with no experience")
}
if len(cvData.Skills.Technical) == 0 {
t.Error("LoadCV() returned CV with no technical skills")
}
// Validate that year placeholder was replaced
for i, ref := range cvData.References {
if ref.URL == "" {
continue
}
if len(ref.URL) >= 2 && ref.URL[0:2] == "{{" {
t.Errorf("LoadCV() reference %d still has placeholder in URL: %s", i, ref.URL)
}
}
}
})
}
}
func TestLoadCV_DataIntegrity(t *testing.T) {
cvData, err := cv.LoadCV("en")
if err != nil {
t.Fatalf("LoadCV() failed: %v", err)
}
// Test that computed fields are properly initialized (empty, not populated yet)
for i, exp := range cvData.Experience {
if exp.Duration != "" {
t.Errorf("Experience[%d].Duration should be empty before calculation, got: %s", i, exp.Duration)
}
}
// Test that JSON tags are properly used
if cvData.Meta.Version == "" {
t.Error("Meta.Version should not be empty")
}
if cvData.Meta.Language == "" {
t.Error("Meta.Language should not be empty")
}
}