Permalink
Browse files

making templates work again #31

  • Loading branch information...
oliyh committed Mar 1, 2018
1 parent d4ed810 commit 131e2d632fba9fea36af1cb352755b279b0914e3
Showing with 36 additions and 31 deletions.
  1. +15 −0 migrators/jdbc/0009.clj
  2. +2 −3 src/slacky/meme.clj
  3. +4 −6 src/slacky/templates.clj
  4. +1 −4 test/slacky/integration_test.clj
  5. +14 −18 test/slacky/meme_test.clj
View
@@ -0,0 +1,15 @@
(ns jdbc.0009
(:require [clojure.java.jdbc :as sql]
[joplin.jdbc.database]))
(defn up [db]
(sql/with-db-connection [db db]
(sql/db-do-commands
db
["ALTER TABLE meme_templates DROP COLUMN template_id"])))
(defn down [db]
(sql/with-db-transaction [db db]
(sql/db-do-commands
db
["ALTER TABLE meme_templates ADD COLUMN template_id varchar(128) not null;"])))
View
@@ -134,9 +134,8 @@
(a/thread
(let [[_ template-name source-url] (resolve-template-addition text)]
(try
(let [template-id (memecaptain/create-template source-url)]
(templates/persist! db account-id template-name source-url template-id)
(a/>!! response-chan [:add-template template-name source-url]))
(templates/persist! db account-id template-name source-url)
(a/>!! response-chan [:add-template template-name source-url])
(catch Exception e
(a/>!! response-chan [:error (format "Could not create template from %s" source-url)]))))
(a/close! response-chan))
View
@@ -7,22 +7,20 @@
(defn lookup [db account-id name]
(->
(jdbc/query db (sql/format {:select [:template_id]
(jdbc/query db (sql/format {:select [:source_url]
:from [:meme_templates]
:where [:and
[:= :account_id account-id]
[:= :name (-> name string/trim string/lower-case)]]
:limit 1}))
first
:template_id
keyword))
:source_url))
(defn persist! [db account-id template-name source-url template-id]
(defn persist! [db account-id template-name source-url]
(jdbc/with-db-transaction [db db]
(jdbc/insert! db :meme_templates {:account_id account-id
:name (-> template-name string/trim string/lower-case)
:source_url source-url
:template_id template-id})))
:source_url source-url})))
(defn delete! [db account-id template-name]
(jdbc/with-db-transaction [db db]
@@ -113,7 +113,7 @@
(slack/->message :meme user-name "cats | cute cats | FTW" meme-url)]
(first (a/alts!! [slack-channel (a/timeout 500)]))))))
#_(testing "can register a template"
(testing "can register a template"
(with-fake-internet {:template-id "cute-cat-template-id"}
(is (= "Your template is being registered"
(slack-post! ":template cute cats http://cats.com/cute.jpg")))
@@ -123,8 +123,6 @@
"cute cats" "http://cats.com/cute.jpg")]
(first (a/alts!! [slack-channel (a/timeout 500)]))))
(cj/verify-first-call-args-for memecaptain/create-template "http://cats.com/cute.jpg")
(testing "and can use it in a meme"
(is (= "Your meme is on its way"
(slack-post! "cute cats | omg | so cute")))
@@ -133,7 +131,6 @@
(slack/->message :meme user-name "cute cats | omg | so cute" meme-url)]
(first (a/alts!! [slack-channel (a/timeout 500)]))))
(cj/verify-call-times-for memecaptain/create-template 1)
(cj/verify-first-call-args-for memecaptain/create-direct "http://cats.com/cute.jpg" "omg" "so cute"))
(testing "which shows up in help message"
View
@@ -40,25 +40,21 @@
(deftest register-template-test
(let [account-id (:id (register-basic-account! *db* "foo"))]
(cj/stubbing [memecaptain/create-template "some-template-id"]
(testing "can create a template"
(let [response (add-template *db*
account-id
":template angry martin http://foo.bar/baz.jpg")]
(is (= [:add-template "angry martin" "http://foo.bar/baz.jpg"]
(safe-read response))))
(testing "can create a template"
(let [response (add-template *db*
account-id
":template angry martin http://foo.bar/baz.jpg")]
(testing "use it"
(is (= ["http://foo.bar/baz.jpg" "" "bidi!!!111one"]
(resolve-meme-pattern *db* account-id "angry martin | | bidi!!!111one"))))
(is (= [:add-template "angry martin" "http://foo.bar/baz.jpg"]
(safe-read response))))
(cj/verify-called-once-with-args memecaptain/create-template "http://foo.bar/baz.jpg")
(testing "and delete it"
(is (= [:delete-template "angry martin"]
(safe-read (delete-template *db* account-id ":delete-template angry martin"))))
(testing "use it"
(is (= [:some-template-id "" "bidi!!!111one"]
(resolve-meme-pattern *db* account-id "angry martin | | bidi!!!111one"))))
(testing "and delete it"
(is (= [:delete-template "angry martin"]
(safe-read (delete-template *db* account-id ":delete-template angry martin"))))
(is (= ["angry martin" "" "bidi!!!111one"]
(resolve-meme-pattern *db* account-id "angry martin | | bidi!!!111one"))))))))
(is (= ["angry martin" "" "bidi!!!111one"]
(resolve-meme-pattern *db* account-id "angry martin | | bidi!!!111one")))))))

0 comments on commit 131e2d6

Please sign in to comment.