add first transformation source spec

master
jem 4 years ago
parent b409346416
commit 7fa26afde8

@ -18,8 +18,14 @@
:opt-un [::media-links ::untrimmed-text])) :opt-un [::media-links ::untrimmed-text]))
(def mastodon-output? (s/keys :req-un [::created-at ::text] (def mastodon-output? (s/keys :req-un [::created-at ::text]
:opt-un [::media-links])) :opt-un [::media-links]))
(s/def ::type keyword?)
(def transformations? any?) (defmulti source-type :type)
(defmethod source-type :twitter-source [_]
(s/merge (s/keys :req-un[::type]) twitter/twitter-source?))
(s/def ::source (s/multi-spec source-type ::type))
(s/def ::target any?)
(s/def ::transformation (s/keys :req-un [::source ::target]))
(def transformations? (s/* ::transformation))
(defn trim-text [text max-post-length] (defn trim-text [text max-post-length]
(cond (cond

@ -14,13 +14,13 @@
(s/def ::access_token_secret string?) (s/def ::access_token_secret string?)
(s/def ::access-keys (s/keys :req-un [::consumer_key ::consumer_secret ::access_token_key (s/def ::access-keys (s/keys :req-un [::consumer_key ::consumer_secret ::access_token_key
::access_token_secret])) ::access_token_secret]))
(def twitter-auth? (s/keys :req-un [::access-keys]))
(s/def ::include-rts? boolean?) (s/def ::include-rts? boolean?)
(s/def ::include-replies? boolean?) (s/def ::include-replies? boolean?)
(s/def ::account string?) (s/def ::account string?)
(s/def ::accounts (s/* ::account)) (s/def ::accounts (s/* ::account))
(def twitter-auth? (s/keys :req-un [::access-keys])) (def twitter-source? (s/keys :req-un [::include-rts? ::include-replies?]))
(def twitter-transform? (s/keys :req-un [::include-rts? ::include-replies?]))
(defn-spec twitter-client any? (defn-spec twitter-client any?
[twitter-config twitter-auth?] [twitter-config twitter-auth?]

@ -8,29 +8,29 @@
[mastodon-bot.core :as core] [mastodon-bot.core :as core]
)) ))
(deftest test-read-config ;; (deftest test-read-config
(is (= 300 core/max-post-length))) ;; (is (= 300 core/max-post-length)))
(defn readfile [filename] ;; (defn readfile [filename]
(-> filename (fs/readFileSync #js {:encoding "UTF-8"}) edn/read-string)) ;; (-> filename (fs/readFileSync #js {:encoding "UTF-8"}) edn/read-string))
(deftest test-remove-link-to-image ;; (deftest test-remove-link-to-image
(is (= ;; (is (=
"Mensen vragen om meer foto's in SPAMSPAMSPAM, dus bij deze achteraf de nieuwe kasten voor de projectenkast en de bookcrossingzone. Te vinden direct bij binnenkomst op de eerste en tweede verdieping." ;; "Mensen vragen om meer foto's in SPAMSPAMSPAM, dus bij deze achteraf de nieuwe kasten voor de projectenkast en de bookcrossingzone. Te vinden direct bij binnenkomst op de eerste en tweede verdieping."
(:text (core/parse-tweet (readfile "testdata/twitter/tweet-with-link-to-image.edn"))) ;; (:text (core/parse-tweet (readfile "testdata/twitter/tweet-with-link-to-image.edn")))
))) ;; )))
(deftest test-parse-normal-tweet-text ;; (deftest test-parse-normal-tweet-text
(is (= ;; (is (=
"Daar is 'ie dan! SPAMSPAMSPAM editie 2! Met een samenvatting van wat er in deze eerste twee maanden van 2020 gebeurd en gedaan is binnen @hack42. Lees het via: \nhttps://t.co/O1YzlWTFU3 #hackerspace #nieuws #arnhem #nuarnhem" ;; "Daar is 'ie dan! SPAMSPAMSPAM editie 2! Met een samenvatting van wat er in deze eerste twee maanden van 2020 gebeurd en gedaan is binnen @hack42. Lees het via: \nhttps://t.co/O1YzlWTFU3 #hackerspace #nieuws #arnhem #nuarnhem"
(:text (core/parse-tweet (readfile "testdata/twitter/normal-tweet.edn"))) ;; (:text (core/parse-tweet (readfile "testdata/twitter/normal-tweet.edn")))
))) ;; )))
(deftest test-replacements ;; (deftest test-replacements
(is (= ;; (is (=
"💠 Check out what has been going on during March in the world of @ReproBuilds! 💠 https://t.co/k6NsSO115z @opensuse@fosstodon.org @conservancy@mastodon.technology @PrototypeFund@mastodon.social @debian@fosstodon.org " ;; "💠 Check out what has been going on during March in the world of @ReproBuilds! 💠 https://t.co/k6NsSO115z @opensuse@fosstodon.org @conservancy@mastodon.technology @PrototypeFund@mastodon.social @debian@fosstodon.org "
(:text (core/perform-replacements (core/parse-tweet (readfile "testdata/twitter/tweet-mentions.edn")))) ;; (:text (core/perform-replacements (core/parse-tweet (readfile "testdata/twitter/tweet-mentions.edn"))))
))) ;; )))
(cljs.test/run-tests) (cljs.test/run-tests)

@ -0,0 +1,16 @@
(ns mastodon-bot.transform_test
(:require
[cljs.test :refer-macros [deftest is testing run-tests]]
[clojure.spec.alpha :as s]
[mastodon-bot.transform :as sut]
))
(deftest test-spec
(is (s/valid? sut/transformations?
[]))
(is (s/valid? sut/transformations?
[{:source {:type :twitter-source
:include-replies? false
:include-rts? true
:accounts ["an-twitter-account"]}
:target {}}])))