 
 (use-fixtures :each log-fixture)
 
-(defn intersect-keys= [expected actual]
-  (let [keys-to-compare (keys expected)]
-    (= expected (select-keys actual keys-to-compare))))
+(defn diff-with-first-nil? [expected actual]
+  (let [diff (first (data/diff expected actual))]
+    (when diff (pprint {:diff diff}))
+    (= nil (first (data/diff expected actual)))))
 
 (defn make-uuid []
   (java.util.UUID/randomUUID))

  (:require [foosball.models.db :refer :all]
            [com.stuartsierra.component :as c]
            [foosball.models.domains :as d]
            [clojure.test :refer :all]
            [taoensso.timbre :as t]))

(defn memory-db []
  (c/start

  (testing "Creating matches"
    (let [db            (memory-db)
          create-player (fn [seed]
                          (let [id (make-uuid)
                                name (str "name-" seed)
                                openid (str "openid-" seed)]
                            (d/create-player! db id name openid )
                            (util/symbols-as-map id name openid)))
          [p1 p2 p3 p4] (map create-player ["p1" "p2" "p3" "p3"])
          match-date (java.util.Date.)
          team1score 10
          team2score 5
          reporter (create-player "reporter")]
      (testing "We can create a match with our four players,"
        (is (not= nil (d/create-match! db {:matchdate match-date
                                           :team1 {:player1 (:id p1) :player2 (:id p2) :score team1score}
                                           :team2 {:player1 (:id p3) :player2 (:id p4) :score team2score}
                                           :reported-by (:id reporter)})))
        (testing "then we can get it out again"
          (let [result (d/get-matches db)]
            (is (diff-with-first-nil? {:matchdate match-date
                                       :team1 {:player1 (:name p1) :player2 (:name p2) :score team1score}
                                       :team2 {:player1 (:name p3) :player2 (:name p4) :score team2score}
                                       :reported-by (:name reporter)}
                                      (first result)))
            (is (= 1 (count result)))))))))
