<commit_before>(ns spacon.trigger-test
  (:require [clojure.test :refer :all]
            [spacon.components.trigger.db :as trigger]
            [spacon.test-utils :as utils]
            [spacon.specs.trigger]
            [clojure.spec :as spec]
            [clojure.spec.gen :as gen]
            [camel-snake-kebab.core :refer :all]
            [camel-snake-kebab.extras :refer [transform-keys]]))

(deftest all-trigger-test
  (is (true? (utils/spec-passed? `trigger/all))))

(use-fixtures :once utils/setup-fixtures)

(deftest trigger-get-test []
  (let [res (utils/request-get "/api/triggers")]
    (is (some? (:result res)))))

(deftest trigger-crud-test []
  (let [trigger (gen/generate (spec/gen :spacon.specs.trigger/trigger-spec))
        d (transform-keys ->snake_case_keyword trigger)
        new-trigger (utils/request-post "/api/triggers" d)
        create-res (transform-keys ->kebab-case-keyword (:result new-trigger))
        read-trigger (utils/request-get (str "/api/triggers/" (:id create-res)))
        read-res (transform-keys ->kebab-case-keyword (:result read-trigger))
        delete-trigger (utils/request-delete (str "/api/triggers/" (:id create-res)))
        delete-res (transform-keys ->kebab-case-keyword (:result delete-trigger))]
    (is (spec/valid? :spacon.specs.trigger/trigger-spec create-res))
    (is (spec/valid? :spacon.specs.trigger/trigger-spec read-res))
    (is (= "success" delete-res))))<commit_msg>adding some http trigger tests (#242)<commit_after>(ns spacon.trigger-test
  (:require [clojure.test :refer :all]
            [spacon.components.trigger.db :as trigger]
            [spacon.test-utils :as utils]
            [spacon.specs.trigger]
            [clojure.spec :as spec]
            [clojure.spec.gen :as gen]
            [camel-snake-kebab.core :refer :all]
            [camel-snake-kebab.extras :refer [transform-keys]]))

(use-fixtures :once utils/setup-fixtures)

(deftest all-trigger-test
  (is (true? (utils/spec-passed? `trigger/all))))

(defn generate-test-trigger []
  (->> (gen/generate (spec/gen :spacon.specs.trigger/trigger-spec))
       (transform-keys ->snake_case_keyword)))

(deftest trigger-http-crud-test
  (let [test-trigger(generate-test-trigger)]

    (testing "Creating a trigger through REST api produces a valid HTML response"
      (let [res (utils/request-post "/api/triggers" test-trigger)
            new-trigger (transform-keys ->kebab-case-keyword (:result res))]
        (is (contains? res :result)
            "Response should have result keyword")
        (is (spec/valid? :spacon.specs.trigger/trigger-spec new-trigger)
            "The response should contain a trigger that conforms to the trigger spec")))

    (testing "Retrieving all triggers through REST api produces a valid HTML response"
      (let [res (-> (utils/request-get "/api/triggers"))
            trigger (->> res :result first (transform-keys ->kebab-case-keyword))]
        (is (contains? res :result)
            "Response should have result keyword")
        (is (spec/valid? :spacon.specs.trigger/trigger-spec trigger)
            "The response should contain a trigger that conforms to the trigger spec")))

    (testing "Retrieving trigger by its key through REST api produces a valid HTML response"
      (let [t (-> (utils/request-get "/api/triggers") :result first)
            res (-> (utils/request-get (str "/api/triggers/" (:id t))))
            trigger (transform-keys ->kebab-case-keyword (:result res))]
        (is (contains? res :result)
            "Response should have result keyword")
        (is (spec/valid? :spacon.specs.trigger/trigger-spec trigger)
            "The response should contain a trigger that conforms to the trigger spec")))

    (testing "Updating a trigger through REST api produces a valid HTML response"
      (let [trigger (-> (utils/request-get "/api/triggers") :result first)
            renamed-trigger (->> (assoc trigger :name "foo") (transform-keys ->snake_case_keyword))
            res (utils/request-put (str "/api/triggers/" (:id trigger)) renamed-trigger)
            updated-trigger (transform-keys ->kebab-case-keyword (:result res))]
        (is (contains? res :result)
            "Response should have result keyword")
        (is (spec/valid? :spacon.specs.trigger/trigger-spec updated-trigger)
            "The response should contain a trigger that conforms to the trigger spec")
        (is (= "foo" (:name updated-trigger))
            "The response should contain the updated trigger name")))

    (testing "Deleting triggers through REST api produces a valid HTML response"
      (let [trigger (-> (utils/request-get "/api/triggers") :result first)
            res (utils/request-delete (str "/api/triggers/" (:id trigger)))]
        (is (= "success" (:result res))
            "The response should contain a success message")))))
{'fraction_non_alphanumeric': 0.13956360642239604, 'fraction_numerical': 0.0006175380815150268, 'mean_word_length': 2.835043409629045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4114941', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1443, 'n_words': 404}