<commit_before>(ns cmr.system-int-test.search.collection-consortium-search-test
  "Integration tests for collection consortium search"
  (:require
   [clojure.test :refer :all]
   [cmr.common.util :as util :refer [are3]]
   [cmr.system-int-test.data2.core :as d]
   [cmr.system-int-test.data2.umm-spec-collection :as umm-c]
   [cmr.system-int-test.utils.ingest-util :as ingest]
   [cmr.system-int-test.utils.index-util :as index]
   [cmr.system-int-test.utils.search-util :as search]))

(use-fixtures :each (ingest/reset-fixture
                      [{:provider-guid "provguid1"
                        :provider-id "PROV1"
                        :short-name "Provider 1"}
                       {:provider-guid "provguid2"
                        :provider-id "PROV2"
                        :short-name "PROVIDER 2"}]))

(deftest collection-consortium-search-test
  (ingest/delete-provider "PROV1")
  (ingest/delete-provider "PROV2")
  (ingest/create-provider {:provider-guid "provguid_consortium1" :provider-id "PROV1" :consortiums "consortium11 consortium12"})
  (ingest/create-provider {:provider-guid "provguid_consortium2" :provider-id "PROV2" :consortiums "consortium21 consortium22"})

  (let [coll1 (d/ingest-umm-spec-collection
               "PROV1"
               (umm-c/collection 1
                                 {:CollectionCitations [{:Creator "<NAME>"}
                                                        {:Creator "Nelkin"}]})
               {:format :umm-json})
        coll2 (d/ingest-umm-spec-collection
               "PROV2"
               (umm-c/collection 2
                                 {:CollectionCitations [{:Creator "<NAME>, <NAME>, and <NAME>"
                                                         :OtherCitationDetails "Sounder PEATE (Product Evaluation and Test Element) Team/<NAME>, JPL"}]})
               {:format :umm-json})
        id1 (:concept-id coll1)
        id2 (:concept-id coll2)]

    (index/wait-until-indexed)

    (testing "consortium returned in json and atom responses"
      (let [consortiums-in-json (-> (search/find-concepts-json :collection {:concept-id id1})
                                    (get-in [:results :entries])
                                    first
                                    :consortiums)
            consortiums-in-atom (-> (search/find-concepts-atom :collection {:concept-id id2})
                                    (get-in [:results :entries])
                                    first
                                    :consortiums)]
        (is (= ["cst11" "cst12"] consortiums-in-json))
        (is (= ["cst21" "cst22"] consortiums-in-atom))))
     
    (testing "consortium parameter search"
      (are3 [items consortium options]
        (let [params (merge {:consortium consortium}
                            options)]
          (d/refs-match? items (search/find-refs :collection params)))

        "consortium search1"
        [coll1] "consortium11" nil

        "consortium search2 ignore case"
        [coll2] "ConSortium21" nil

        "Pattern search"
        [coll1 coll2] "*consortium*" {"options[consortium][pattern]" "true"}
<commit_msg>CMR-7753 fixing broken test. (#1386)<commit_after>(ns cmr.system-int-test.search.collection-consortium-search-test
  "Integration tests for collection consortium search"
  (:require
   [clojure.test :refer :all]
   [cmr.common.util :as util :refer [are3]]
   [cmr.system-int-test.data2.core :as d]
   [cmr.system-int-test.data2.umm-spec-collection :as umm-c]
   [cmr.system-int-test.utils.ingest-util :as ingest]
   [cmr.system-int-test.utils.index-util :as index]
   [cmr.system-int-test.utils.search-util :as search]))

(use-fixtures :each (ingest/reset-fixture
                      [{:provider-guid "provguid1"
                        :provider-id "PROV1"
                        :short-name "Provider 1"}
                       {:provider-guid "provguid2"
                        :provider-id "PROV2"
                        :short-name "PROVIDER 2"}]))

(deftest collection-consortium-search-test
  (ingest/delete-provider "PROV1")
  (ingest/delete-provider "PROV2")
  (ingest/create-provider {:provider-guid "provguid_consortium1" :provider-id "PROV1" :consortiums "consortium11 consortium12"})
  (ingest/create-provider {:provider-guid "provguid_consortium2" :provider-id "PROV2" :consortiums "consortium21 consortium22"})

  (let [coll1 (d/ingest-umm-spec-collection
               "PROV1"
               (umm-c/collection 1
                                 {:CollectionCitations [{:Creator "<NAME>"}
                                                        {:Creator "Nelkin"}]})
               {:format :umm-json})
        coll2 (d/ingest-umm-spec-collection
               "PROV2"
               (umm-c/collection 2
                                 {:CollectionCitations [{:Creator "<NAME>, <NAME>, and <NAME>"
                                                         :OtherCitationDetails "Sounder PEATE (Product Evaluation and Test Element) Team/<NAME>, JPL"}]})
               {:format :umm-json})
        id1 (:concept-id coll1)
        id2 (:concept-id coll2)]

    (index/wait-until-indexed)

    (testing "consortium returned in json and atom responses"
      (let [consortiums-in-json (-> (search/find-concepts-json :collection {:concept-id id1})
                                    (get-in [:results :entries])
                                    first
                                    :consortiums)
            consortiums-in-atom (-> (search/find-concepts-atom :collection {:concept-id id2})
                                    (get-in [:results :entries])
                                    first
                                    :consortiums)]
        (is (= ["consortium11" "consortium12"] consortiums-in-json))
        (is (= ["consortium21" "consortium22"] consortiums-in-atom))))

    (testing "consortium parameter search"
      (are3 [items consortium options]
        (let [params (merge {:consortium consortium}
                            options)]
          (d/refs-match? items (search/find-refs :collection params)))

        "consortium search1"
        [coll1] "consortium11" nil

        "consortium search2 ignore case"
        [coll2] "ConSortium21" nil

        "Pattern search"
        [coll1 coll2] "*consortium*" {"options[consortium][pattern]" "true"}

{'fraction_non_alphanumeric': 0.12523570081709617, 'fraction_numerical': 0.018227529855436832, 'mean_word_length': 1.7697998259355963, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '144014', 'n_tokens_mistral': 1989, 'n_tokens_neox': 1799, 'n_words': 382}