Skip to content

Commit

Permalink
Add tests for swark.authom
Browse files Browse the repository at this point in the history
  • Loading branch information
verberktstan committed Jan 23, 2024
1 parent 354168e commit 753268a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/swark/authom.cljc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(ns swark.authom
(:require [swark.core :refer [try?]]))

;; swark.authom - Atomic authorisation made easy

(defn- ->hash
"Returns the hash code of `item`. Tries to find it for collections if standard hashing fails."
([item]
Expand Down
17 changes: 16 additions & 1 deletion test/swark/authom_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@
(:require [clojure.test :as t]
[swark.authom :as sut]))

;; TODO: Add tests!
(def ITEM #:user{:id 123 :fullname "User Name"})
(def WITH-TOKEN (-> ITEM (select-keys [:user/id]) (sut/with-meta-token "password" "SECRET")))
(def TOKEN -301775488)

(t/deftest meta-token
(t/testing "Returns the token if stored in metadata"
(t/is (= TOKEN (sut/meta-token WITH-TOKEN))))
(t/testing "Returns nil if the token is NOT stored in metadata"
(t/is (nil? (sut/meta-token ITEM)))))

(t/deftest check-meta-token
(t/testing "Returns a truethy value when password and secret match"
(t/is (sut/check-meta-token WITH-TOKEN "password" "SECRET")))
(t/testing "Returns a falsey value when password and/or secret do not match"
(t/is (not (sut/check-meta-token WITH-TOKEN "wrong-password" "SECRET")))
(t/is (not (sut/check-meta-token WITH-TOKEN "password" "WRONG_SECRET")))))

0 comments on commit 753268a

Please sign in to comment.