<commit_before>;; Copyright © 2015, JUXT LTD.

(ns yada.collection-resource-test
  (:require
   [clojure.set :as set]
   [clojure.test :refer :all]
   [clojure.tools.logging :refer :all]
   [clojure.pprint :refer [pprint]]
   [ring.mock.request :as mock]
   [clojure.java.io :as io]
   [clj-time.core :as time]
   [clj-time.coerce :refer [to-date]]
   [ring.util.time :refer (parse-date format-date)]
   [yada.representation :as rep]
   [yada.test.util :refer (to-string)]
   [yada.yada :refer [yada]]))

(defn yesterday []
  (time/minus (time/now) (time/days 1)))

(deftest map-resource-test
  (testing "map"
    (let [handler (time/do-at (yesterday) (yada {:name "Frank"}))
          request (mock/request :get "/")
          response @(handler request)
          last-modified (some-> response :headers (get "last-modified") parse-date)]

      (is last-modified)
      (is (instance? java.util.Date last-modified))

      (is (= 200 (:status response)))
      (is (= {"content-type" "application/edn"
              "content-length" 16} (select-keys (:headers response) ["content-type" "content-length"])))
      (is (instance? java.nio.HeapByteBuffer (:body response)))

      (let [request (merge (mock/request :get "/")
                           {:headers {"if-modified-since" (format-date (to-date (time/now)))}})
            response @(handler request)]
        (is (= 304 (:status response)))))))

<commit_msg>updating collection-resource-test to make it platform-independent<commit_after>;; Copyright © 2015, JUXT LTD.

(ns yada.collection-resource-test
  (:require
    [clojure.set :as set]
    [clojure.test :refer :all]
    [clojure.tools.logging :refer :all]
    [clojure.pprint :refer [pprint]]
    [ring.mock.request :as mock]
    [clojure.java.io :as io]
    [clj-time.core :as time]
    [clj-time.coerce :refer [to-date]]
    [ring.util.time :refer (parse-date format-date)]
    [yada.representation :as rep]
    [yada.test.util :refer (to-string)]
    [yada.yada :refer [yada]]
    [clojure.edn :as edn]))

(defn yesterday []
  (time/minus (time/now) (time/days 1)))

(deftest map-resource-test
  (testing "map"
    (let [test-map {:name "Frank"}
          handler (time/do-at (yesterday) (yada test-map))
          request (mock/request :get "/")
          response @(handler request)
          last-modified (some-> response :headers (get "last-modified") parse-date)]

      (is last-modified)
      (is (instance? java.util.Date last-modified))

      (is (= 200 (:status response)))
      (is (= {"content-type" "application/edn"
              "content-length" (count (prn-str test-map))}
             (select-keys (:headers response) ["content-type" "content-length"])))
      (is (instance? java.nio.HeapByteBuffer (:body response)))
      (is (= test-map
             (-> response :body to-string edn/read-string)))

      (let [request (merge (mock/request :get "/")
                           {:headers {"if-modified-since" (format-date (to-date (time/now)))}})
            response @(handler request)]
        (is (= 304 (:status response)))))))
{'fraction_non_alphanumeric': 0.17067620286085824, 'fraction_numerical': 0.007802340702210663, 'mean_word_length': 2.7708333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5885792', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1038, 'n_words': 254}