<commit_before>(ns celestial.integration.puny
  (:require [puny.core :as p])
  (:import clojure.lang.ExceptionInfo)
  (:use  
     midje.sweet
    [celestial.fixtures :only (is-type?)]
    [celestial.redis :only (clear-all)]))

(with-state-changes [(before :facts (clear-all))]
  (fact "id-less entity" :integration :redis
        (p/entity foo)        
        (defn validate-foo [foo] {})
        (let [id (add-foo {:bar 1})]
          (get-foo id) => {:bar 1}
          (foo-exists? id) => truthy
          (update-foo id {:bar 2}) 
          (get-foo id) => {:bar 2}
          (delete-foo id)
          (foo-exists? id) => falsey))

  (fact "entity with id" :integration :redis
        (p/entity user :id name)        
        (defn validate-user [user] {})
        (let [id (add-user {:name "me"})]
          (get-user "me") => {:name "me"}
          (user-exists? "me") => truthy
          (update-user {:name "me" :blue "bar"}) 
          (get-user "me") => {:name "me" :blue "bar"}
          (delete-user "me")
          (user-exists? "me") => falsey))

  (fact "basic index actions" :integration :redis
        (p/index-fns house {:indices [zip n]})
        (index-house 5 {:zip "1234" :n 5})
        (index-house 6 {:zip "1234" :n 6})
        (get-house-index :zip "1234") => ["5" "6"]
        (get-house-index :n 5) => ["5"]
        (clear-house-indices 5 {:zip "1234" :n 5})
        (get-house-index :zip "1234")  => ["6"]
        (reindex-house 6 {:zip "1234" :n 6} {:zip "1235" :n 6}) 
        (get-house-index :zip "1234")  => []
        (get-house-index :zip "1235")  => ["6"]
        )

  (fact "indexed entity" :integration :redis
        (p/entity position :indices [longi alti])        
        (defn validate-position [postion] {})
        (let [id (add-position {:longi 10 :alti 12})]
          (get-position id) => {:longi 10 :alti 12}
          (position-exists? id) => truthy
          (update-position id {:longi 11 :alti 12}) 
          (get-position-index :longi 11) => [(str id)]
          (delete-position id)
          (position-exists? id) => falsey
          (get-position-index :longi 11) => []
          ))

  (fact "indexed entity with id" :integration :redis
        (p/entity car :id license :indices [color])        
        (defn validate-car [car] {})
        (add-car {:license 123 :color "black"})
        (get-car 123) => {:license 123 :color "black"}
        (car-exists? 123) => truthy
        (get-car-index :color "black") => ["123"]
        (update-car {:license 123 :color "blue"}) 
        (get-car-index :color "black") => []
        (get-car-index :color "blue") => ["123"]
        (delete-car 123)
        (car-exists? 123) => falsey
        (get-car-index :color "blue") => [])

  (fact "fail fase actions"
        (p/entity planet :id name)
        (defn validate-planet [planet] {})
        (add-planet {:name "lunar"})
        (get-planet "lunar") => {:name "lunar"}
        (planet-exists! "lunar") => true
        (planet-exists! "foo") => (throws ExceptionInfo (is-type? :celestial.integration.puny/missing-planet))
        (delete-planet! "foo") => (throws ExceptionInfo (is-type? :celestial.integration.puny/missing-planet))
        (update-planet {:name "foo"}) => (throws ExceptionInfo (is-type? :celestial.integration.puny/missing-planet))
        (get-planet! "lunar") => {:name "lunar"}
        (delete-planet! "lunar") 
        (get-planet "lunar") => {} 
        (get-planet! "lunar") => (throws ExceptionInfo (is-type? :celestial.integration.puny/missing-planet)) 
        )
  )<commit_msg>marking fail fast test as redis tests<commit_after>(ns celestial.integration.puny
  (:require [puny.core :as p])
  (:import clojure.lang.ExceptionInfo)
  (:use  
     midje.sweet
    [celestial.fixtures :only (is-type?)]
    [celestial.redis :only (clear-all)]))

(with-state-changes [(before :facts (clear-all))]
  (fact "id-less entity" :integration :redis
        (p/entity foo)        
        (defn validate-foo [foo] {})
        (let [id (add-foo {:bar 1})]
          (get-foo id) => {:bar 1}
          (foo-exists? id) => truthy
          (update-foo id {:bar 2}) 
          (get-foo id) => {:bar 2}
          (delete-foo id)
          (foo-exists? id) => falsey))

  (fact "entity with id" :integration :redis
        (p/entity user :id name)        
        (defn validate-user [user] {})
        (let [id (add-user {:name "me"})]
          (get-user "me") => {:name "me"}
          (user-exists? "me") => truthy
          (update-user {:name "me" :blue "bar"}) 
          (get-user "me") => {:name "me" :blue "bar"}
          (delete-user "me")
          (user-exists? "me") => falsey))

  (fact "basic index actions" :integration :redis
        (p/index-fns house {:indices [zip n]})
        (index-house 5 {:zip "1234" :n 5})
        (index-house 6 {:zip "1234" :n 6})
        (get-house-index :zip "1234") => ["5" "6"]
        (get-house-index :n 5) => ["5"]
        (clear-house-indices 5 {:zip "1234" :n 5})
        (get-house-index :zip "1234")  => ["6"]
        (reindex-house 6 {:zip "1234" :n 6} {:zip "1235" :n 6}) 
        (get-house-index :zip "1234")  => []
        (get-house-index :zip "1235")  => ["6"]
        )

  (fact "indexed entity" :integration :redis
        (p/entity position :indices [longi alti])        
        (defn validate-position [postion] {})
        (let [id (add-position {:longi 10 :alti 12})]
          (get-position id) => {:longi 10 :alti 12}
          (position-exists? id) => truthy
          (update-position id {:longi 11 :alti 12}) 
          (get-position-index :longi 11) => [(str id)]
          (delete-position id)
          (position-exists? id) => falsey
          (get-position-index :longi 11) => []
          ))

  (fact "indexed entity with id" :integration :redis
        (p/entity car :id license :indices [color])        
        (defn validate-car [car] {})
        (add-car {:license 123 :color "black"})
        (get-car 123) => {:license 123 :color "black"}
        (car-exists? 123) => truthy
        (get-car-index :color "black") => ["123"]
        (update-car {:license 123 :color "blue"}) 
        (get-car-index :color "black") => []
        (get-car-index :color "blue") => ["123"]
        (delete-car 123)
        (car-exists? 123) => falsey
        (get-car-index :color "blue") => [])

  (fact "fail fase actions" :integration :redis
        (p/entity planet :id name)
        (defn validate-planet [planet] {})
        (add-planet {:name "lunar"})
        (get-planet "lunar") => {:name "lunar"}
        (planet-exists! "lunar") => true
        (planet-exists! "foo") => (throws ExceptionInfo (is-type? :celestial.integration.puny/missing-planet))
        (delete-planet! "foo") => (throws ExceptionInfo (is-type? :celestial.integration.puny/missing-planet))
        (update-planet {:name "foo"}) => (throws ExceptionInfo (is-type? :celestial.integration.puny/missing-planet))
        (get-planet! "lunar") => {:name "lunar"}
        (delete-planet! "lunar") 
        (get-planet "lunar") => {} 
        (get-planet! "lunar") => (throws ExceptionInfo (is-type? :celestial.integration.puny/missing-planet)) 
        )
  )
{'fraction_non_alphanumeric': 0.18587775607033213, 'fraction_numerical': 0.027351381523862683, 'mean_word_length': 2.215343203230148, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 69, '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': '2253237', 'n_tokens_mistral': 2715, 'n_tokens_neox': 2424, 'n_words': 630}