Skip to content

Commit 7b2b754

Browse files
committed
CMR-10886: addresses some PR comments
1 parent bf10f4f commit 7b2b754

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

search-app/src/cmr/search/services/query_execution/granule_counts_results_feature.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
(fn [condition-path condition]
9393
(when (and (instance? SpatialCondition condition)
9494
(not (is-spatial-or-group? (last condition-path))))
95+
(validate-path-to-condition query condition-path)
9596
true)))]
9697

9798
(concat spatial-or-groups ungrouped-spatial-conds)))

search-app/test/cmr/search/test/unit/services/query_execution/granule_counts_results_feature_test.clj

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,44 @@
137137
:condition combined})
138138
result (gcrf/extract-spatial-conditions query)]
139139
(is (= [or-group cond3] result)))))
140+
141+
(deftest extract-spatial-conditions-validates-parent-path-test
142+
(testing "Rejects SpatialCondition under NegatedCondition"
143+
(let [spatial-cond (make-spatial-condition 10 0)
144+
negated (q/negated-condition spatial-cond)
145+
query (q/query {:concept-type :collection
146+
:condition negated})]
147+
(is (thrown? Exception
148+
(gcrf/extract-spatial-conditions query)))))
149+
150+
(testing "Rejects SpatialCondition nested under NegatedCondition in AND group"
151+
(let [spatial-cond (make-spatial-condition 10 0)
152+
title-cond (q/string-condition :entry-title "test")
153+
negated (q/negated-condition spatial-cond)
154+
combined (gc/and-conds [title-cond negated])
155+
query (q/query {:concept-type :collection
156+
:condition combined})]
157+
(is (thrown? Exception
158+
(gcrf/extract-spatial-conditions query)))))
159+
160+
(testing "Accepts valid SpatialCondition in AND group"
161+
(let [spatial-cond (make-spatial-condition 10 0)
162+
title-cond (q/string-condition :entry-title "test")
163+
combined (gc/and-conds [title-cond spatial-cond])
164+
query (q/query {:concept-type :collection
165+
:condition combined})]
166+
(is (seq (gcrf/extract-spatial-conditions query)))))
167+
168+
(testing "Accepts valid SpatialCondition at top level"
169+
(let [spatial-cond (make-spatial-condition 10 0)
170+
query (q/query {:concept-type :collection
171+
:condition spatial-cond})]
172+
(is (seq (gcrf/extract-spatial-conditions query)))))
173+
174+
(testing "Preserves MultiPolygon OR groups with validation"
175+
(let [spatial-cond-1 (make-spatial-condition 10 0)
176+
spatial-cond-2 (make-spatial-condition 20 10)
177+
or-group (gc/or-conds [spatial-cond-1 spatial-cond-2])
178+
query (q/query {:concept-type :collection
179+
:condition or-group})]
180+
(is (= [or-group] (gcrf/extract-spatial-conditions query))))))

0 commit comments

Comments
 (0)