Skip to content

Commit

Permalink
[TECH] Make event-type-property safe if something other than a string…
Browse files Browse the repository at this point in the history
… is passed as argument

Authors: @Eustaquio122 @zimio
Co-authored-by: Jefry Lagrange <[email protected]>
  • Loading branch information
Eustaquio122 and zimio committed Oct 10, 2022
1 parent f0283dd commit bbff16c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/vent/hal.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

(defn- single-word [property]
"Removes spaces from property and creates a single word joined by '-'"
(string/join "-" (string/split property #"(\s+)")))
(if (string? property)
(string/join "-" (string/split property #"(\s+)"))
property))

(defn event-type-property [property]
(fn [event] (keyword (single-word (hal/get-property (:payload event) property)))))

5 changes: 4 additions & 1 deletion test/vent/hal_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
(is (= :some-event-type ((event-type-property :type) (new-event "some event type ")))))

(testing "keeps the string as it is if it's only one word"
(is (= :some-event-type ((event-type-property :type) (new-event "some-event-type"))))))
(is (= :some-event-type ((event-type-property :type) (new-event "some-event-type")))))

(testing "returns a keyword as it is if a keyword is passed"
(is (= :some-event-type ((event-type-property :type) (new-event :some-event-type))))))

0 comments on commit bbff16c

Please sign in to comment.