      :created_at   $
      :updated_at   $
      :creator_id   $
-     :creator      (user-details @(:creator pulse))
-     :cards        (mapv pulse-card-details @(:cards pulse))
-     :channels     (mapv pulse-channel-details @(:channels pulse))}))
+     :creator      (user-details (:creator pulse))
+     :cards        (mapv pulse-card-details (:cards pulse))
+     :channels     (mapv pulse-channel-details (:channels pulse))}))
 
 (defn pulse-response [{:keys [created_at updated_at] :as pulse}]
   (-> pulse

    :dataset_query          {}
    :visualization_settings {}))

(defn new-pulse []
  (let [cards    [(new-card), (new-card)]
        card-ids (filter identity (map :id cards))]
    (pulse/create-pulse (random-name) (user->id :crowberto) card-ids [])))

;; ## GET /api/emailreport/form_input
;; Test that we can get the form input options for the Test Org
;(expect-let [_ @test-db ; force lazy loading of Test Data / Metabase DB
;             _ (cascade-delete Database :name [not= "Test Database"])] ; Delete all Databases that aren't the Test DB
;  {:users #{{:id (user->id :rasta),     :name "Rasta Toucan"}
;            {:id (user->id :crowberto), :name "Crowberto Corv"}
;            {:id (user->id :lucky),     :name "Lucky Pigeon"}
;            {:id (user->id :trashbird), :name "Trash Bird"}}
;   :databases [{:id (:id @test-db)
;                :name "Test Database"}],
;   :timezones ["GMT"
;               "UTC"
;               "US/Alaska"
;               "US/Arizona"
;               "US/Central"
;               "US/Eastern"
;               "US/Hawaii"
;               "US/Mountain"
;               "US/Pacific"
;               "America/Costa_Rica"]
;   :times_of_day [{:id "morning",   :realhour 8,  :name "Morning"}
;                  {:id "midday",    :realhour 12, :name "Midday"}
;                  {:id "afternoon", :realhour 16, :name "Afternoon"}
;                  {:id "evening",   :realhour 20, :name "Evening"}
;                  {:id "midnight",  :realhour 0,  :name "Midnight"}]
;   :days_of_week [{:id "sun", :name "Sun"}
;                  {:id "mon", :name "Mon"}
;                  {:id "tue", :name "Tue"}
;                  {:id "wed", :name "Wed"}
;                  {:id "thu", :name "Thu"}
;                  {:id "fri", :name "Fri"}
;                  {:id "sat", :name "Sat"}]
;   :modes [{:name "Active", :id 1}
;           {:name "Disabled", :id 2}]
;   :permissions [{:name "None",         :id 0}
;                 {:name "Read Only",    :id 1}
;                 {:name "Read & Write", :id 2}]}
;  (-> ((user->client :rasta) :get 200 "emailreport/form_input" :org @org-id) ; convert to a set so test doesn't fail if order differs
;        (update-in [:users] set)))

;; ## /api/pulse/* AUTHENTICATION Tests
;; We assume that all endpoints for a given context are enforced by the same middleware, so we don't run the same
;; authentication test on every single individual endpoint

(expect (get middleware/response-unauthentic :body) (http/client :get 401 "pulse"))
(expect (get middleware/response-unauthentic :body) (http/client :put 401 "pulse/13"))

(defn user-details [user]
  (match-$ user

      (assoc :updated_at (not (nil? updated_at)))))


;; ## /api/pulse/* AUTHENTICATION Tests
;; We assume that all endpoints for a given context are enforced by the same middleware, so we don't run the same
;; authentication test on every single individual endpoint

(expect (get middleware/response-unauthentic :body) (http/client :get 401 "pulse"))
(expect (get middleware/response-unauthentic :body) (http/client :put 401 "pulse/13"))


;; ## POST /api/pulse

(expect {:errors {:name "field is a required param."}}
