<commit_before>(ns kuona-api.core.collector.service-status-test
  (:require [midje.sweet :refer :all]
            [clj-http.client :as http]
            [cheshire.core :refer :all]
            [kuona-api.core.collector.service-status :refer :all]))

(facts "Content filtering"
       (fact "Non json content type is empty string"
             (json-filter {:headers {:Content-Type "foobar"}}) => {})
       (fact "Json content type yields body"
             (json-filter {:headers {:Content-Type "json"} :body "{\"foo\":{}}"}) => {:foo {}})
       (fact "application/json content type yields body"
             (json-filter {:headers {:Content-Type "application/json"} :body "{\"foo\":{}}"}) => {:foo {}}))

(facts "Collecting from end points"
       (fact "Service is down if no connection"
             (collect-endpoint "http://localhost:12000") => {:error  "Connection Refused",
                                                             :status "DOWN",
                                                             :type   "error",
                                                             :url    "http://localhost:12000"}
             (provided (http/get anything) =throws=> (java.net.ConnectException.)))<commit_msg>Added import<commit_after>(ns kuona-api.core.collector.service-status-test
  (:require [midje.sweet :refer :all]
            [clj-http.client :as http]
            [cheshire.core :refer :all]
            [kuona-api.core.collector.service-status :refer :all])
  (:import (java.net ConnectException)))

(facts "Content filtering"
       (fact "Non json content type is empty string"
             (json-filter {:headers {:Content-Type "foobar"}}) => {})
       (fact "Json content type yields body"
             (json-filter {:headers {:Content-Type "json"} :body "{\"foo\":{}}"}) => {:foo {}})
       (fact "application/json content type yields body"
             (json-filter {:headers {:Content-Type "application/json"} :body "{\"foo\":{}}"}) => {:foo {}}))

(facts "Collecting from end points"
       (fact "Service is down if no connection"
             (collect-endpoint "http://localhost:12000") => {:error  "Connection Refused",
                                                             :status "DOWN",
                                                             :type   "error",
                                                             :url    "http://localhost:12000"}
             (provided (http/get anything) =throws=> (ConnectException.)))
{'fraction_non_alphanumeric': 0.1512469831053902, 'fraction_numerical': 0.008045052292839904, 'mean_word_length': 1.7572062084257207, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1462319', 'n_tokens_mistral': 668, 'n_tokens_neox': 624, 'n_words': 171}