<commit_before>(ns cmr.search.test.services.parameter-validation
  (:require [clojure.test :refer :all]
            [cmr.search.services.parameter-validation :as pv]
            [cmr.search.services.messages.attribute-messages :as attrib-msg]
            [cmr.search.services.messages.orbit-number-messages :as on-msg]))

(def valid-params
  "Example valid parameters"
  {:entry-title "foo"
   :page-size 10
   :options {:entry-title {:ignore-case "true"}}})

(deftest individual-parameter-validation-test
  (testing "unrecognized parameters"
    (is (= [] (pv/unrecognized-params-validation :collection valid-params)))
    (is (= ["Parameter [foo] was not recognized."
            "Parameter [bar] was not recognized."]
           (pv/unrecognized-params-validation :collection
                                              {:entry-title "fdad"
                                               :foo 1
                                               :bar 2}))))
  (testing "invalid options param names"
    (is (= [] (pv/unrecognized-params-in-options-validation :collection valid-params)))
    (is (= ["Parameter [foo] with option was not recognized."]
           (pv/unrecognized-params-in-options-validation :collection
                                                         {:entry-title "fdad"
                                                          :options {:foo {:ignore-case "true"}}}))))
  (testing "invalid options param args"
    (is (= ["Option [foo] for param [entry_title] was not recognized."]
           (pv/unrecognized-params-settings-in-options-validation :collection
                                                                  {:entry-title "fdad"
                                                                   :options {:entry-title {:foo "true"}}}))))
  (testing "Page size less than one"
    (is (= ["page_size must be a number between 1 and 2000"]
           (pv/page-size-validation :collection (assoc valid-params :page-size 0)))))

  (testing "Page size less than one"
    (is (= ["page_size must be a number between 1 and 2000"]
           (pv/page-size-validation :collection (assoc valid-params :page-size 0)))))
  (testing "Search with large page size"
    (is (= []
           (pv/page-size-validation :collection (assoc valid-params :page-size 100)))))
  (testing "Negative page size"
    (is (= ["page_size must be a number between 1 and 2000"]
           (pv/page-size-validation :collection (assoc valid-params :page-size -1)))))
  (testing "Page size too large."
    (is (= ["page_size must be a number between 1 and 2000"]
           (pv/page-size-validation :collection (assoc valid-params :page-size 2001)))))
  (testing "Non-numeric page size"
    (is (= ["page_size must be a number between 1 and 2000"]
           (pv/page-size-validation :collection (assoc valid-params :page-size "ABC")))))
  (testing "Valid page_num"
    (is (= []
           (pv/page-num-validation :collection (assoc valid-params :page-num 5)))))
  (testing "Page num less than one"
    (is (= ["page_num must be a number greater than or equal to 1"]
           (pv/page-num-validation :collection (assoc valid-params :page-num 0)))))
  (testing "Non-numeric page num"
    (is (= ["page_num must be a number greater than or equal to 1"]
           (pv/page-num-validation :collection (assoc valid-params :page-num "ABC")))))
  (testing "Valid exact orbit_number"
    (is (= []
           (pv/orbit-number-validation :granule (assoc valid-params :orbit-number "10")))))
  (testing "Valid orbit_number range"
    (is (= []
           (pv/orbit-number-validation :granule (assoc valid-params :orbit-number "1,2")))))
  (testing "Non-numeric single orbit-number"
    (is (= [(on-msg/invalid-orbit-number-msg)]
           (pv/orbit-number-validation :granlue (assoc valid-params :orbit-number "A")))))
  (testing "Non-numeric start-orbit-number"
    (is (= [(on-msg/invalid-orbit-number-msg)]
           (pv/orbit-number-validation :granule (assoc valid-params :orbit-number "A,10")))))
  (testing "Non-numeric stop-orbit-number"
    (is (= [(on-msg/invalid-orbit-number-msg)]
           (pv/orbit-number-validation :granule (assoc valid-params :orbit-number "10,A")))))
  (testing "Start orbit-number greater than stop orbit-number"
    (is (= [(on-msg/invalid-orbit-number-msg)]
           (pv/orbit-number-validation :granule (assoc valid-params :orbit-number "10,1"))))))

(deftest temporal-format-validation :collection-start-date-test
  (testing "valid-start-date"
    (is (empty? (pv/temporal-format-validation :collection {:temporal ["2014-04-05T00:00:00Z"]}))))
  (testing "invalid-start-date"
    (are [start-date]
         (let [error (pv/temporal-format-validation :collection {:temporal [start-date]})]<commit_msg>CMR-348: Removed unnecessary parameter validation test.<commit_after>(ns cmr.search.test.services.parameter-validation
  (:require [clojure.test :refer :all]
            [cmr.search.services.parameter-validation :as pv]
            [cmr.search.services.messages.attribute-messages :as attrib-msg]
            [cmr.search.services.messages.orbit-number-messages :as on-msg]))

(def valid-params
  "Example valid parameters"
  {:entry-title "foo"
   :page-size 10
   :options {:entry-title {:ignore-case "true"}}})

(deftest individual-parameter-validation-test
  (testing "unrecognized parameters"
    (is (= [] (pv/unrecognized-params-validation :collection valid-params)))
    (is (= ["Parameter [foo] was not recognized."
            "Parameter [bar] was not recognized."]
           (pv/unrecognized-params-validation :collection
                                              {:entry-title "fdad"
                                               :foo 1
                                               :bar 2}))))
  (testing "invalid options param names"
    (is (= [] (pv/unrecognized-params-in-options-validation :collection valid-params)))
    (is (= ["Parameter [foo] with option was not recognized."]
           (pv/unrecognized-params-in-options-validation :collection
                                                         {:entry-title "fdad"
                                                          :options {:foo {:ignore-case "true"}}}))))
  (testing "invalid options param args"
    (is (= ["Option [foo] for param [entry_title] was not recognized."]
           (pv/unrecognized-params-settings-in-options-validation :collection
                                                                  {:entry-title "fdad"
                                                                   :options {:entry-title {:foo "true"}}}))))
  (testing "Page size less than one"
    (is (= ["page_size must be a number between 1 and 2000"]
           (pv/page-size-validation :collection (assoc valid-params :page-size 0)))))

  (testing "Page size less than one"
    (is (= ["page_size must be a number between 1 and 2000"]
           (pv/page-size-validation :collection (assoc valid-params :page-size 0)))))
  (testing "Search with large page size"
    (is (= []
           (pv/page-size-validation :collection (assoc valid-params :page-size 100)))))
  (testing "Negative page size"
    (is (= ["page_size must be a number between 1 and 2000"]
           (pv/page-size-validation :collection (assoc valid-params :page-size -1)))))
  (testing "Page size too large."
    (is (= ["page_size must be a number between 1 and 2000"]
           (pv/page-size-validation :collection (assoc valid-params :page-size 2001)))))
  (testing "Non-numeric page size"
    (is (= ["page_size must be a number between 1 and 2000"]
           (pv/page-size-validation :collection (assoc valid-params :page-size "ABC")))))
  (testing "Valid page_num"
    (is (= []
           (pv/page-num-validation :collection (assoc valid-params :page-num 5)))))
  (testing "Page num less than one"
    (is (= ["page_num must be a number greater than or equal to 1"]
           (pv/page-num-validation :collection (assoc valid-params :page-num 0)))))
  (testing "Non-numeric page num"
    (is (= ["page_num must be a number greater than or equal to 1"]
           (pv/page-num-validation :collection (assoc valid-params :page-num "ABC")))))
  (testing "Valid exact orbit_number"
    (is (= []
           (pv/orbit-number-validation :granule (assoc valid-params :orbit-number "10")))))
  (testing "Valid orbit_number range"
    (is (= []
           (pv/orbit-number-validation :granule (assoc valid-params :orbit-number "1,2")))))
  (testing "Non-numeric single orbit-number"
    (is (= [(on-msg/invalid-orbit-number-msg)]
           (pv/orbit-number-validation :granlue (assoc valid-params :orbit-number "A")))))
  (testing "Non-numeric start-orbit-number"
    (is (= [(on-msg/invalid-orbit-number-msg)]
           (pv/orbit-number-validation :granule (assoc valid-params :orbit-number "A,10")))))
  (testing "Non-numeric stop-orbit-number"
    (is (= [(on-msg/invalid-orbit-number-msg)]
           (pv/orbit-number-validation :granule (assoc valid-params :orbit-number "10,A"))))))

(deftest temporal-format-validation :collection-start-date-test
  (testing "valid-start-date"
    (is (empty? (pv/temporal-format-validation :collection {:temporal ["2014-04-05T00:00:00Z"]}))))
  (testing "invalid-start-date"
    (are [start-date]
         (let [error (pv/temporal-format-validation :collection {:temporal [start-date]})]
{'fraction_non_alphanumeric': 0.14363753213367608, 'fraction_numerical': 0.01456726649528706, 'mean_word_length': 2.4466592838685863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3397904', 'n_tokens_mistral': 2848, 'n_tokens_neox': 2592, 'n_words': 727}