 (ns yetibot.core.test.adapters.slack
-  (:require [yetibot.core.adapters :as adapters]
-            [yetibot.core.adapters.adapter :as a]
+  (:require [yetibot.core.adapters.adapter :as a]
             [yetibot.core.adapters.slack :as slack]
             [yetibot.core.chat :as chat]
+            [yetibot.core.handler :refer [handle-raw]]
             [clj-slack
              [channels :as channels]
              [users :as slack-users]
-             [groups :as groups]]
+             [groups :as groups]
+             [im :as im]
+             [chat :as slack-chat]]
+            [slack-rtm.core :as slack-rtm]
+            [yetibot.core.models.users :as users]
             [midje.sweet :refer [=> fact facts contains provided
                                  anything every-checker throws]]))
 

                                            not-empty
                                            (contains '({:members ["U123"]})))))

;; functions to test some comment code
(defn slack-configs []
  (filter
   (fn [c] (= "slack" (:type c)))
   (vals (adapters/adapters-config))))

(def config (slack/slack-config (last (slack-configs))))

(comment
  ;; replace these with real IDs to try it out
  (slack/entity-with-name-by-id
   config {:channel "C11111114"})
  (slack/entity-with-name-by-id
   config {:channel "G11111111"})
  (slack/entity-with-name-by-id
   config
   {:type "message"
    :channel "D11111111"
    :user "U11111111"
    :text "!echo hi"})

  ;; test sending a message and getting the history of
  (let [adapter (first (a/active-adapters))]
    (slack/history adapter "G1QD1DNG2")

    (binding [chat/*target* "D0HFDJHA4"]
      (a/send-msg adapter "hi"))

    (slack/react adapter "balloon" "D0HFDJHA4"))
  
  ;; test bindings when calling an adapter function
  (let [*config* nil]
    (binding [*config* (last (slack-configs))]
      (slack/list-channels))

    (binding [*config* (last (slack-configs))]
      (slack/channels-cached))

    (binding [*config* (last (slack-configs))]
      (slack/channels))

    (binding [*config* (last (slack-configs))]
      (:groups (slack/list-groups)))))

  "returns only channels YB is in"
  (slack/channels-in anything) => '({:is_member true :name "yes"})
  (provided (slack/list-channels anything) => {:channels [{:is_member true
                                                           :name "yes"}
                                                          {:is_member false
                                                           :name "no"}]})))

(facts
 "about chan-or-group-name"
