|
|
|
@ -1,11 +1,9 @@ |
|
|
|
(ns NoteHub.test.api |
|
|
|
(ns NoteHub.test.api |
|
|
|
(:require |
|
|
|
(:require |
|
|
|
[NoteHub.storage :as storage]) |
|
|
|
[NoteHub.storage :as storage]) |
|
|
|
(:use [NoteHub.api] |
|
|
|
(:use [NoteHub.api] |
|
|
|
[clojure.test])) |
|
|
|
[clojure.test])) |
|
|
|
|
|
|
|
|
|
|
|
(def note "Hello world, this is a test note!") |
|
|
|
|
|
|
|
(def note2 "Another test note") |
|
|
|
|
|
|
|
(def pid "somePlugin") |
|
|
|
(def pid "somePlugin") |
|
|
|
(def pid2 "somePlugin2") |
|
|
|
(def pid2 "somePlugin2") |
|
|
|
|
|
|
|
|
|
|
|
@ -14,16 +12,20 @@ |
|
|
|
(defn register-publisher-fixture [f] |
|
|
|
(defn register-publisher-fixture [f] |
|
|
|
(def psk (storage/register-publisher pid)) |
|
|
|
(def psk (storage/register-publisher pid)) |
|
|
|
(f) |
|
|
|
(f) |
|
|
|
(storage/revoke-publisher pid)) |
|
|
|
(storage/revoke-publisher pid) |
|
|
|
|
|
|
|
(storage/revoke-publisher pid2)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(use-fixtures :each register-publisher-fixture) |
|
|
|
|
|
|
|
|
|
|
|
(deftest api |
|
|
|
(deftest api |
|
|
|
(testing "API" |
|
|
|
(testing "API" |
|
|
|
(testing "publisher registration" |
|
|
|
(testing "publisher registration" |
|
|
|
|
|
|
|
(is (storage/valid-publisher? pid)) |
|
|
|
|
|
|
|
(isnt (storage/valid-publisher? pid2)) |
|
|
|
(let [psk2 (storage/register-publisher pid2)] |
|
|
|
(let [psk2 (storage/register-publisher pid2)] |
|
|
|
(is (storage/valid-publisher? pid)) |
|
|
|
(is (= psk2 (storage/get-psk pid2))) |
|
|
|
(is (storage/valid-publisher? pid2)) |
|
|
|
(is (storage/valid-publisher? pid2)) |
|
|
|
(is (storage/revoke-publisher pid2)) |
|
|
|
(is (storage/revoke-publisher pid2)) |
|
|
|
(isnt (storage/revoke-publisher "anyPID")) |
|
|
|
|
|
|
|
(isnt (storage/valid-publisher? "any_PID")) |
|
|
|
(isnt (storage/valid-publisher? "any_PID")) |
|
|
|
(isnt (storage/valid-publisher? pid2)))) |
|
|
|
(isnt (storage/valid-publisher? pid2)))) |
|
|
|
#_ (testing "note publishing & retrieval" |
|
|
|
#_ (testing "note publishing & retrieval" |
|
|
|
@ -43,19 +45,19 @@ |
|
|
|
(is (storage/revoke-publisher pid2)) |
|
|
|
(is (storage/revoke-publisher pid2)) |
|
|
|
(isnt (:success (:status (post-note note "randomPID" (get-signature pid psk2 note))))))) |
|
|
|
(isnt (:success (:status (post-note note "randomPID" (get-signature pid psk2 note))))))) |
|
|
|
#_ (testing "note update" |
|
|
|
#_ (testing "note update" |
|
|
|
(let [post-response (post-note note pid (get-signature pid psk note) "passwd") |
|
|
|
(let [post-response (post-note note pid (get-signature pid psk note) "passwd") |
|
|
|
note-id (:noteID post-response) |
|
|
|
note-id (:noteID post-response) |
|
|
|
get-response (get-note note-id) |
|
|
|
get-response (get-note note-id) |
|
|
|
new-note "a new note!" |
|
|
|
new-note "a new note!" |
|
|
|
update-response (update-note note-id new-note pid (get-signature pid psk new-note) "passwd") |
|
|
|
update-response (update-note note-id new-note pid (get-signature pid psk new-note) "passwd") |
|
|
|
get-response-new (get-note note-id) |
|
|
|
get-response-new (get-note note-id) |
|
|
|
update-response-false (update-note note-id new-note pid (get-signature pid psk new-note) "pass") |
|
|
|
update-response-false (update-note note-id new-note pid (get-signature pid psk new-note) "pass") |
|
|
|
] |
|
|
|
] |
|
|
|
(is (:success (:status post-response))) |
|
|
|
(is (:success (:status post-response))) |
|
|
|
(is (:success (:status get-response))) |
|
|
|
(is (:success (:status get-response))) |
|
|
|
(is (:success (:status get-response-new))) |
|
|
|
(is (:success (:status get-response-new))) |
|
|
|
(is (:success (:status update-response))) |
|
|
|
(is (:success (:status update-response))) |
|
|
|
(isnt (:success (:status update-response-false))) |
|
|
|
(isnt (:success (:status update-response-false))) |
|
|
|
(is (= note (:note get-response))) |
|
|
|
(is (= note (:note get-response))) |
|
|
|
(is (= new-note (:note get-response-new))) |
|
|
|
(is (= new-note (:note get-response-new))) |
|
|
|
(is (= new-note (:note (get-note note-id)))))))) |
|
|
|
(is (= new-note (:note (get-note note-id)))))))) |
|
|
|
|