package db import ( "encoding/json" "testing" ) func TestNewLearningRepository(t *testing.T) { pg := &PostgresDB{} repo := NewLearningRepository(pg) if repo == nil { t.Fatalf("expected repository instance") } if repo.db != pg { t.Fatalf("repository must keep provided db pointer") } } func TestLearningUserProfileJSONContract(t *testing.T) { profile := LearningUserProfile{ UserID: "u-1", DisplayName: "Alex", Profile: json.RawMessage(`{"target_track":"backend"}`), ResumeExtractedText: "resume text", OnboardingCompleted: true, } raw, err := json.Marshal(profile) if err != nil { t.Fatalf("marshal profile: %v", err) } var decoded map[string]interface{} if err := json.Unmarshal(raw, &decoded); err != nil { t.Fatalf("unmarshal profile json: %v", err) } if decoded["userId"] != "u-1" { t.Fatalf("unexpected userId: %v", decoded["userId"]) } if decoded["onboardingCompleted"] != true { t.Fatalf("unexpected onboardingCompleted: %v", decoded["onboardingCompleted"]) } }