44 [yetibot.core.handler :as handler]
55 [yetibot.core.models.users :as users]
66 [yetibot.core.chat :as chat]
7+ [yetibot.core.webapp.routes.images :as images]
78 [midje.sweet :refer [fact facts anything => provided]]))
89
910(facts
6263 (provided (users/create-user " fake" {:id 999 :username " fake" }) => {:username " fake" }
6364 (chat/chat-source 456 ) => {:channel-id 456 :room " fake" }
6465 (handler/handle-raw anything anything anything anything anything) => " called handle-raw" )))
66+
67+ (facts
68+ " about generated-image-info"
69+ (fact
70+ " returns nil for messages without generated image URLs"
71+ (#'discord/generated-image-info " hello there!" ) => nil )
72+ (fact
73+ " extracts ID and extension when only URL is present"
74+ (#'discord/generated-image-info " http://localhost:3003/generated-images/fc62974c-0c61-4be6-8241-d1f79cd1eac0.png" )
75+ => {:url " http://localhost:3003/generated-images/fc62974c-0c61-4be6-8241-d1f79cd1eac0.png"
76+ :id " fc62974c-0c61-4be6-8241-d1f79cd1eac0"
77+ :ext " png" })
78+ (fact
79+ " extracts ID and extension when URL is embedded in text"
80+ (#'discord/generated-image-info " Check out the celebration: http://localhost:3003/generated-images/fc62974c-0c61-4be6-8241-d1f79cd1eac0.png ! Very cool!" )
81+ => {:url " http://localhost:3003/generated-images/fc62974c-0c61-4be6-8241-d1f79cd1eac0.png"
82+ :id " fc62974c-0c61-4be6-8241-d1f79cd1eac0"
83+ :ext " png" }))
84+
85+ (facts
86+ " about send-msg with generated images"
87+ (fact
88+ " sends message with attachment stream on discord and strips url"
89+ (with-redefs [images/image-store (atom {" fc62974c-0c61-4be6-8241-d1f79cd1eac0" {:data " SGVsbG8gd29ybGQ=" }})]
90+ (binding [chat/*target* 456 ]
91+ (#'discord/send-msg {:conn (atom {:rest :fake-rest })}
92+ " Check out the celebration: http://localhost:3003/generated-images/fc62974c-0c61-4be6-8241-d1f79cd1eac0.png ! Very cool!" )))
93+ => " created-message-result"
94+ (provided (messaging/create-message! :fake-rest 456
95+ :content " Check out the celebration: ! Very cool!"
96+ :stream anything) => (future " created-message-result" )))
97+ (fact
98+ " sends message with attachment stream without content if text is blank"
99+ (with-redefs [images/image-store (atom {" fc62974c-0c61-4be6-8241-d1f79cd1eac0" {:data " SGVsbG8gd29ybGQ=" }})]
100+ (binding [chat/*target* 456 ]
101+ (#'discord/send-msg {:conn (atom {:rest :fake-rest })}
102+ " http://localhost:3003/generated-images/fc62974c-0c61-4be6-8241-d1f79cd1eac0.png" )))
103+ => " created-message-result"
104+ (provided (messaging/create-message! :fake-rest 456
105+ :stream anything) => (future " created-message-result" ))))
65106
0 commit comments