File tree Expand file tree Collapse file tree
src/yetibot/core/webapp/routes
test/yetibot/core/test/webapp/routes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818 *target* (:room chat-source)]
1919 (info " chat-source" chat-source)
2020 (let [user {:username " api" }
21- res (or text (handle-unparsed-expr chat-source user command))]
21+ raw-res (or text (handle-unparsed-expr chat-source user command))
22+ res (if (map? raw-res)
23+ (cond
24+ (contains? raw-res :value ) (:value raw-res)
25+ (contains? raw-res :error ) (:error raw-res)
26+ :else raw-res)
27+ raw-res)]
2228 (chat-data-structure res)
2329 res))
2430 (str " invalid chat-source:" chat-source))))
Original file line number Diff line number Diff line change 11(ns yetibot.core.test.webapp.routes.api
22 (:require [yetibot.core.webapp.routes.api :refer [api]]
33 [yetibot.core.chat :refer [chat-data-structure]]
4+ [yetibot.core.handler :refer [handle-unparsed-expr]]
45 [midje.sweet :refer [=> fact facts contains provided anything]]))
56
67(facts
2122 " will return :text when :chat-source is legit, which is almost always
2223 as long as it is not empty/nil and not malformed"
2324 (api good-cs req) => (:text good-cs)
24- (provided (chat-data-structure anything) => nil ))))
25+ (provided (chat-data-structure anything) => nil )))
26+
27+ (let [command-cs {:chat-source " {:uuid \" C123\" :room \" #mychan\" }"
28+ :command " echo hello" }
29+ req " /api" ]
30+ (fact
31+ " will evaluate command and return its extracted :value"
32+ (api command-cs req) => " hello from command"
33+ (provided
34+ (handle-unparsed-expr anything anything " echo hello" ) => {:settings {} :skip-next-n 0 :value " hello from command" :data nil }
35+ (chat-data-structure " hello from command" ) => nil ))
36+
37+ (fact
38+ " will evaluate command and return its extracted :error on failure"
39+ (api command-cs req) => " error occurred"
40+ (provided
41+ (handle-unparsed-expr anything anything " echo hello" ) => {:error " error occurred" }
42+ (chat-data-structure " error occurred" ) => nil ))))
You can’t perform that action at this time.
0 commit comments