 (ns samsara.client-test
   (:require [samsara.client2 :refer :all]
-            [midje.sweet :refer :all]))
+            [midje.sweet :refer :all]
+            [samsara.utils :refer [to-json]]))
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(fact "publish-events: should post the given events to the ingestion-api"

      (with-mock-send-events
        (publish-events "http://localhost:9000/v1"
                        [{:eventName "a" :timestamp 1 :sourceId "d1"}])

        headers => (contains {"Content-Type" "application/json"
                              "X-Samsara-publishedTimestamp" anything})

        body => (to-json [{:eventName "a" :timestamp 1 :sourceId "d1"}] )

        )
      )


(fact "publish-events: should post the given events to the ingestion-api"

      ;; successful post of a single event
      (with-mock-send-events
        (publish-events "http://localhost:9000/v1"
                        [{:invalid "event"}])
        ) => (throws Exception)
      )
