<commit_before>(ns rook.async-spec
  (:use
    [clojure.core.async :only [go chan >!! <! <!! thread]]
    speclj.core)
  (:require
    [ring.mock.request :as mock]
    [io.aviso.rook
     [async :as async]
     [client :as c]
     [utils :as utils]]))

(describe "io.aviso.rook.async"

  (describe "routing"

    (it "return the first result that is not false"

        (let [req {:uri "whatever"}]
          (should= req
                   (->
                     (async/routing req
                                    (fn [_] (thread false))
                                    (fn [request] (thread
                                                    (utils/response 200 request))))
                     <!!
                     :body))))

    (it "returns false when all handlers return false"

        (should= false
                 (->
                   (async/routing {} (fn [_] (thread false)))
                   <!!)))

    (it "returns false when there are no handlers"
        (should= false
                 (->
                   (async/routing {})
                   <!!))))

  (describe "loopback-handler"

    (it "should expose the loopback in the request"
        (let [fred (fn [request]
                     (go
                       (if (= (:uri request) "/fred")
                         (->
                           (c/new-request (:loopback-handler request))
                           (c/to :get :barney)
                           c/send
                           (c/then (reply (utils/response reply))))
                         false)))
              barney (fn [request]
                       (go
                         (if (= (:uri request) "/barney")
                           (utils/response 200 "rubble")
                           false)))
              wrapped (async/wrap-with-loopback (async/routes fred barney))]
          (should= "rubble"<commit_msg>Add a test for a nil path to async/namespace-handler<commit_after>(ns rook.async-spec
  (:use
    [clojure.core.async :only [go chan >!! <! <!! thread]]
    speclj.core)
  (:require
    [ring.mock.request :as mock]
    [io.aviso.rook
     [async :as async]
     [client :as c]
     [utils :as utils]]))

(describe "io.aviso.rook.async"

  (describe "routing"

    (it "return the first result that is not false"

        (let [req {:uri "whatever"}]
          (should= req
                   (->
                     (async/routing req
                                    (fn [_] (thread false))
                                    (fn [request] (thread
                                                    (utils/response 200 request))))
                     <!!
                     :body))))

    (it "returns false when all handlers return false"

        (should= false
                 (->
                   (async/routing {} (fn [_] (thread false)))
                   <!!)))

    (it "returns false when there are no handlers"
        (should= false
                 (->
                   (async/routing {})
                   <!!))))

  (describe "namespace-handler"

    (it "allows the path to be nil"
        (let [handler (async/namespace-handler 'barney)]
          (should= {:message "ribs!"}
                   (->
                     (mock/request :get "/")
                     handler
                     <!!
                     :body)))))


  (describe "loopback-handler"

    (it "should expose the loopback in the request"
        (let [fred (fn [request]
                     (go
                       (if (= (:uri request) "/fred")
                         (->
                           (c/new-request (:loopback-handler request))
                           (c/to :get :barney)
                           c/send
                           (c/then (reply (utils/response reply))))
                         false)))
              barney (fn [request]
                       (go
                         (if (= (:uri request) "/barney")
                           (utils/response 200 "rubble")
                           false)))
              wrapped (async/wrap-with-loopback (async/routes fred barney))]
          (should= "rubble"
{'fraction_non_alphanumeric': 0.12106653855392746, 'fraction_numerical': 0.002882536632236368, 'mean_word_length': 1.0252918287937742, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5596826', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1030, 'n_words': 285}