@@ -1062,4 +1062,82 @@ class GraphqlControllerTest < ActionDispatch::IntegrationTest
10621062 end
10631063 end
10641064 end
1065+
1066+ test 'graphql search with camelCase aggregation fields (accessToFiles, contentType)' do
1067+ VCR . use_cassette ( 'opensearch init' ) do
1068+ VCR . use_cassette ( 'graphql search data analytics' ) do
1069+ post '/graphql' , params : { query : '{
1070+ search(searchterm: "data analytics") {
1071+ aggregations {
1072+ accessToFiles {
1073+ key
1074+ docCount
1075+ }
1076+ contentType {
1077+ key
1078+ docCount
1079+ }
1080+ }
1081+ }
1082+ }' }
1083+ assert_equal ( 200 , response . status )
1084+ json = JSON . parse ( response . body )
1085+ aggs = json [ 'data' ] [ 'search' ] [ 'aggregations' ]
1086+
1087+ # Verify aggregations are present when requested
1088+ assert_not_nil aggs
1089+ assert_not_nil aggs [ 'accessToFiles' ]
1090+ assert_not_nil aggs [ 'contentType' ]
1091+
1092+ # Verify structure
1093+ assert aggs [ 'accessToFiles' ] . is_a? ( Array )
1094+ assert aggs [ 'contentType' ] . is_a? ( Array )
1095+ end
1096+ end
1097+ end
1098+
1099+ test 'graphql search with format aggregation (should map to content_format)' do
1100+ VCR . use_cassette ( 'opensearch init' ) do
1101+ VCR . use_cassette ( 'graphql search data analytics' ) do
1102+ post '/graphql' , params : { query : '{
1103+ search(searchterm: "data analytics") {
1104+ aggregations {
1105+ format {
1106+ key
1107+ docCount
1108+ }
1109+ }
1110+ }
1111+ }' }
1112+ assert_equal ( 200 , response . status )
1113+ json = JSON . parse ( response . body )
1114+ aggs = json [ 'data' ] [ 'search' ] [ 'aggregations' ]
1115+
1116+ # Verify format aggregation is present and populated
1117+ assert_not_nil aggs
1118+ assert_not_nil aggs [ 'format' ]
1119+ assert aggs [ 'format' ] . is_a? ( Array )
1120+ end
1121+ end
1122+ end
1123+
1124+ test 'graphql search without aggregations excludes them from OpenSearch query' do
1125+ VCR . use_cassette ( 'opensearch init' ) do
1126+ VCR . use_cassette ( 'graphql search data analytics' ) do
1127+ post '/graphql' , params : { query : '{
1128+ search(searchterm: "data analytics") {
1129+ hits
1130+ records {
1131+ title
1132+ }
1133+ }
1134+ }' }
1135+ assert_equal ( 200 , response . status )
1136+ json = JSON . parse ( response . body )
1137+
1138+ # Verify aggregations field is null when not requested
1139+ assert_nil json [ 'data' ] [ 'search' ] [ 'aggregations' ]
1140+ end
1141+ end
1142+ end
10651143end
0 commit comments