Merge pull request #1 from raboof/restore-replacements-test

restore test for 'replacements'
This commit is contained in:
M.Jerger 2020-06-27 15:32:10 +02:00 committed by GitHub
commit 24353ea1a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 18 deletions

View file

@ -67,8 +67,12 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w
;; optional keyword filter regexes
;; any posts not matching the regexes will be filtered out
:keyword-filters [".*clojure.*"]
;; TODO: Description & example missing here
:replacements nil}
;; optional replacements
;; When the strings on the left side of this map are encountered in the source,
;; they are replaced with the string on the right side of the map:
:replacements {
"@openSUSE" "@opensuse@fosstodon.org",
"@conservancy" "@conservancy@mastodon.technology"}}
{:source {:source-type :rss
;; add RSS config to follow feeds

View file

@ -1,6 +1,4 @@
#!/usr/bin/env lumo
(ns mastodon-bot.core_test
(ns mastodon-bot.core-test
(:require
[cljs.test :refer-macros [deftest is testing run-tests]]
[cljs.reader :as edn]
@ -25,14 +23,3 @@
;; "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")))
;; )))
;; (deftest test-replacements
;; (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 "
;; (:text (core/perform-replacements (core/parse-tweet (readfile "testdata/twitter/tweet-mentions.edn"))))
;; )))
(cljs.test/run-tests)
; Don't run core's -main when testing
(set! *main-cli-fn* ())

View file

@ -2,6 +2,10 @@
(:require
[cljs.test :refer-macros [deftest is testing run-tests]]
[clojure.spec.alpha :as s]
[cljs.reader :as edn]
["fs" :as fs]
[mastodon-bot.core :as core]
[mastodon-bot.twitter-api :as twitter]
[mastodon-bot.transform :as sut]
))
@ -24,3 +28,14 @@
:resolve-urls? true
:content-filters [".*bannedsite.*"]
:keyword-filters [".*"]}])))
(defn readfile [filename]
(-> filename (fs/readFileSync #js {:encoding "UTF-8"}) edn/read-string))
(def testconfig (readfile "test.edn"))
(deftest test-replacements
(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 "
(:text (sut/perform-replacements (first (:transform testconfig)) (twitter/parse-tweet (readfile "testdata/twitter/tweet-mentions.edn"))))
)))

View file

@ -47,8 +47,23 @@
;; optional keyword filter regexes
;; any posts not matching the regexes will be filtered out
:keyword-filters [".*clojure.*"]
;; TODO: Description & example missing here
:replacements nil}
;; optional replacements
;; When the strings on the left side of this map are encountered in the source,
;; they are replaced with the string on the right side of the map:
:replacements {
"@openSUSE " "@opensuse@fosstodon.org ",
"@archlinux " "",
"@lolamby " "",
"@conservancy " "@conservancy@mastodon.technology ",
"@prototypefund " "@PrototypeFund@mastodon.social ",
"@coreboot_org " "",
"@OpenTechFund " "",
"@OpenWrtSummit " "",
"@OpenMirage " "",
"@debian " "@debian@fosstodon.org ",
"@nixos_org " "",
"@lwnnet " "",
"@guixhpc" ""}}
{:source {:source-type :rss
;; add RSS config to follow feeds