From 560148efda1fbeeb21750af4fc7201fcd9d64558 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Sat, 27 Jun 2020 11:16:47 +0200 Subject: [PATCH] restore test for 'replacements' and add description in the README --- README.md | 8 ++++++-- src/test/mastodon_bot/core_test.cljs | 15 +-------------- src/test/mastodon_bot/transform_test.cljs | 15 +++++++++++++++ test.edn | 19 +++++++++++++++++-- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 3e28d46..d143554 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/test/mastodon_bot/core_test.cljs b/src/test/mastodon_bot/core_test.cljs index ab799fd..9856836 100755 --- a/src/test/mastodon_bot/core_test.cljs +++ b/src/test/mastodon_bot/core_test.cljs @@ -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* ()) diff --git a/src/test/mastodon_bot/transform_test.cljs b/src/test/mastodon_bot/transform_test.cljs index a90576e..dcb4df8 100755 --- a/src/test/mastodon_bot/transform_test.cljs +++ b/src/test/mastodon_bot/transform_test.cljs @@ -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")))) + ))) \ No newline at end of file diff --git a/test.edn b/test.edn index 75241e9..314a314 100644 --- a/test.edn +++ b/test.edn @@ -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