       (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."}}

  {:name         "A Pulse"
   :public_perms common/perms-readwrite
   :creator_id   (user->id :rasta)
   :created_at   true
   :updated_at   true
   :cards        (into [] (map pulse-card-details [card1 card2]))}
  (pulse-response ((user->client :rasta) :post 200 "pulse" {:name     "A Pulse"
                                                            :cards    [{:id (:id card1)} {:id (:id card2)}]
                                                            :channels [{:channel_type  "email"
                                                                        :schedule_type "daily"}]})))

;; ## GET /api/pulse

(expect-let [pulse1 (new-pulse)
             ;pulse2 (new-pulse)
             ]
  [(pulse-details pulse1)]
  ((user->client :rasta) :get 200 "pulse"))

;(expect-eval-actual-first
;    (match-$ (sel :one EmailReport (order :id :DESC))

    :dataset_query          {}
    :visualization_settings {}))

(defn new-pulse [& {:keys [name cards channels]
                    :or   {name     (random-name)
                           cards    nil
                           channels nil}}]
  (let [cards    (or cards [(new-card), (new-card)])
        card-ids (filter identity (map :id cards))]
    (pulse/create-pulse name (user->id :crowberto) card-ids [])))

(defn delete-existing-pulses []
  (->> (db/sel :many :field [Pulse :id])
       (mapv #(db/cascade-delete Pulse :id %))))

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