90 lines
2.4 KiB
Go
90 lines
2.4 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func fullAnalysisResult() AnalysisResult {
|
|
return AnalysisResult{
|
|
OverallScore: 82,
|
|
Summary: "Well-aligned candidate with clear strengths and a few gaps.",
|
|
CriteriaScores: []CriterionScore{
|
|
{Criterion: "Go", Score: 9, Evidence: "5 years experience", Comments: "Strong practical depth"},
|
|
{Criterion: "Cloud", Score: 7, Evidence: "AWS usage", Comments: "Good baseline with room to grow"},
|
|
},
|
|
Strengths: []string{"Strong backend experience", "Solid testing habits", "Clear technical communication"},
|
|
Weaknesses: []string{"Limited Kubernetes depth", "Few quantified outcomes", "Limited leadership evidence"},
|
|
MissingInformation: []string{"Architecture decision ownership"},
|
|
GrammarSpelling: GrammarSpelling{
|
|
Score: 9,
|
|
IssuesFound: []string{},
|
|
Corrections: []string{},
|
|
},
|
|
Recommendation: Recommendation{
|
|
Label: "Strong fit",
|
|
Rationale: "High technical relevance with manageable gaps.",
|
|
},
|
|
InjectionDetected: false,
|
|
InjectionDetails: "",
|
|
}
|
|
}
|
|
|
|
func TestAnalysisResult_3_6_1_CompleteStructureSerializesToJSON(t *testing.T) {
|
|
result := fullAnalysisResult()
|
|
|
|
b, err := json.Marshal(result)
|
|
if err != nil {
|
|
t.Fatalf("expected marshal success, got error: %v", err)
|
|
}
|
|
|
|
var parsed map[string]any
|
|
if err := json.Unmarshal(b, &parsed); err != nil {
|
|
t.Fatalf("expected valid JSON output, got parse error: %v", err)
|
|
}
|
|
|
|
required := []string{
|
|
"overall_score",
|
|
"summary",
|
|
"criteria_scores",
|
|
"strengths",
|
|
"weaknesses",
|
|
"missing_information",
|
|
"grammar_spelling",
|
|
"recommendation",
|
|
"injection_detected",
|
|
"injection_details",
|
|
}
|
|
for _, key := range required {
|
|
if _, ok := parsed[key]; !ok {
|
|
t.Fatalf("expected field %q in JSON output", key)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAnalysisResult_3_6_2_JSONFieldNamesMatchTypeScriptSchema(t *testing.T) {
|
|
result := fullAnalysisResult()
|
|
|
|
b, err := json.Marshal(result)
|
|
if err != nil {
|
|
t.Fatalf("marshal failed: %v", err)
|
|
}
|
|
jsonStr := string(b)
|
|
|
|
expectedSnakeCase := []string{
|
|
"\"overall_score\"",
|
|
"\"criteria_scores\"",
|
|
"\"missing_information\"",
|
|
"\"grammar_spelling\"",
|
|
"\"issues_found\"",
|
|
"\"injection_detected\"",
|
|
"\"injection_details\"",
|
|
}
|
|
for _, field := range expectedSnakeCase {
|
|
if !strings.Contains(jsonStr, field) {
|
|
t.Fatalf("expected snake_case field %s in JSON: %s", field, jsonStr)
|
|
}
|
|
}
|
|
}
|