package learning import ( "context" "encoding/json" "testing" "github.com/gooseek/backend/internal/llm" ) func TestInferLevel(t *testing.T) { tests := []struct { years float64 want string }{ {0, "beginner"}, {1.5, "junior"}, {3.2, "middle"}, {6.5, "senior"}, {10, "lead"}, } for _, tc := range tests { got := inferLevel(tc.years) if got != tc.want { t.Fatalf("inferLevel(%v) = %q, want %q", tc.years, got, tc.want) } } } func TestExtractJSONBlockFromMarkdown(t *testing.T) { input := "text before\n```json\n{\"name\":\"Alex\",\"level\":\"junior\"}\n```\ntext after" got := extractJSONBlock(input) if got != "{\"name\":\"Alex\",\"level\":\"junior\"}" { t.Fatalf("unexpected json block: %q", got) } } func TestBuildProfileFromOnboarding(t *testing.T) { llmClient := &mockLLMClient{ generateFunc: func(ctx context.Context, req llm.StreamRequest) (string, error) { return `{"name":"Иван","experience_years":1.5,"current_role":"qa","skills":["testing"],"programming_languages":["Go"],"frameworks":[],"education":"BS","industries":["it"],"strengths":["аналитика"],"growth_areas":["backend"],"career_goals":"backend","recommended_tracks":["backend go"],"level":"junior","summary":"Начинающий специалист"}`, nil }, } profileJSON, err := BuildProfileFromOnboarding(context.Background(), llmClient, map[string]string{ "experience_level": "junior", "target_track": "backend go", "weekly_hours": "10", }) if err != nil { t.Fatalf("BuildProfileFromOnboarding error: %v", err) } var profile map[string]interface{} if err := json.Unmarshal(profileJSON, &profile); err != nil { t.Fatalf("profile json unmarshal: %v", err) } if profile["name"] != "Иван" { t.Fatalf("unexpected name: %v", profile["name"]) } if profile["level"] != "junior" { t.Fatalf("unexpected level: %v", profile["level"]) } }