package httpserver import ( "encoding/json" "reflect" "strings" "testing" "Rezina-Backend/docs" ) func TestLearningSwaggerPublicHierarchy(t *testing.T) { var spec struct { Definitions map[string]struct { Properties map[string]json.RawMessage `json:"properties"` } `json:"definitions"` Paths map[string]map[string]struct { Tags []string `json:"tags"` Responses map[string]json.RawMessage `json:"responses"` } `json:"paths"` } if err := json.Unmarshal([]byte(docs.SwaggerInfo.ReadDoc()), &spec); err != nil { t.Fatal(err) } for schema, field := range map[string]string{ "handlers.courseListData": "courses", "handlers.chapterListData": "chapters", "handlers.lessonListData": "lessons", "handlers.quizListData": "quizzes", } { for _, key := range []string{field, "total_count", "limit", "offset"} { if _, ok := spec.Definitions[schema].Properties[key]; !ok { t.Errorf("%s missing %s", schema, key) } } } for schema, hidden := range map[string][]string{ "domain.ExamPrepCatalogCourse": {"category", "modules_count"}, "domain.ExamPrepUnit": {"catalog_course_id", "modules_count"}, "domain.ExamPrepLesson": {"unit_module_id"}, "handlers.createChapterQuizRequest": {"parents", "parent_kind", "parent_id"}, } { for _, key := range hidden { if _, ok := spec.Definitions[schema].Properties[key]; ok { t.Errorf("%s exposes legacy field %s", schema, key) } } } var parentKind struct { Enum []string `json:"enum"` } if err := json.Unmarshal(spec.Definitions["domain.ExamPrepPracticeParent"].Properties["parent_kind"], &parentKind); err != nil { t.Fatal(err) } if !reflect.DeepEqual(parentKind.Enum, []string{"COURSE", "CHAPTER", "LESSON"}) { t.Fatalf("public parent kinds=%v", parentKind.Enum) } for path, operations := range spec.Paths { if !strings.Contains(path, "/quizzes") { continue } for method, operation := range operations { if !reflect.DeepEqual(operation.Tags, []string{"quizzes"}) { t.Errorf("%s %s is not documented as a quiz", method, path) } } } }