routing tests added
This commit is contained in:
@@ -106,7 +106,7 @@
|
|||||||
|
|
||||||
(defn delete-note
|
(defn delete-note
|
||||||
[noteID]
|
[noteID]
|
||||||
(doseq [kw [password views note]]
|
(doseq [kw [password views note published edited]]
|
||||||
; TODO: delete short url by looking for the title
|
; TODO: delete short url by looking for the title
|
||||||
(redis/hdel db kw noteID)))
|
(redis/hdel db kw noteID)))
|
||||||
|
|
||||||
|
|||||||
+49
-53
@@ -11,6 +11,7 @@
|
|||||||
(def pid2 "somePlugin2")
|
(def pid2 "somePlugin2")
|
||||||
(def note-title (str (apply print-str (get-date)) " hello-world-this-is-a-test-note"))
|
(def note-title (str (apply print-str (get-date)) " hello-world-this-is-a-test-note"))
|
||||||
(def note-url (str domain (apply str (interpose "/" (get-date))) "/hello-world-this-is-a-test-note"))
|
(def note-url (str domain (apply str (interpose "/" (get-date))) "/hello-world-this-is-a-test-note"))
|
||||||
|
(defn substring? [a b] (not (= nil (re-matches (re-pattern (str "(?s).*" a ".*")) b))))
|
||||||
|
|
||||||
(defmacro isnt [arg] `(is (not ~arg)))
|
(defmacro isnt [arg] `(is (not ~arg)))
|
||||||
|
|
||||||
@@ -92,66 +93,61 @@
|
|||||||
:pid pid
|
:pid pid
|
||||||
:signature (get-signature pid psk note)
|
:signature (get-signature pid psk note)
|
||||||
:version "1.0"})
|
:version "1.0"})
|
||||||
body (parse-string (:body response))]
|
body (parse-string (:body response))
|
||||||
|
noteID (body "noteID")]
|
||||||
(is (has-status response 200))
|
(is (has-status response 200))
|
||||||
(is (get-in body ["status" "success"]))
|
(is (get-in body ["status" "success"]))
|
||||||
(is (= note ((parse-string
|
(is (= note ((parse-string
|
||||||
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID (body "noteID")}))) "note")))
|
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note")))
|
||||||
(is (do
|
(is (do
|
||||||
(storage/delete-note (body "noteID"))
|
(storage/delete-note noteID)
|
||||||
(not (storage/note-exists? (body "noteID"))))))))
|
(not (storage/note-exists? noteID)))))))
|
||||||
|
|
||||||
#_
|
|
||||||
(deftest note-update
|
(deftest note-update
|
||||||
(let [session-key (create-session)
|
(let [response (send-request [:post "/api/note"]
|
||||||
date (get-date)
|
{:note note
|
||||||
title "test-note"
|
:pid pid
|
||||||
[year month day] date]
|
:signature (get-signature pid psk note)
|
||||||
|
:version "1.0"
|
||||||
|
:password "qwerty"})
|
||||||
|
body (parse-string (:body response))
|
||||||
|
noteID (body "noteID")]
|
||||||
(testing "Note update"
|
(testing "Note update"
|
||||||
(is (has-status
|
(is (has-status response 200))
|
||||||
(send-request
|
(is (get-in body ["status" "success"]))
|
||||||
[:post "/post-note"]
|
(is (storage/note-exists? noteID))
|
||||||
{:session-key session-key
|
(is (substring? "_test_ note"
|
||||||
:draft "test note"
|
((parse-string
|
||||||
|
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note")))
|
||||||
|
(let [response (send-request [:put "/api/note"]
|
||||||
|
{:noteID noteID
|
||||||
|
:note "WRONG pass"
|
||||||
|
:pid pid
|
||||||
|
:signature (get-signature pid psk noteID "WRONG pass" "qwerty1")
|
||||||
|
:password "qwerty1"
|
||||||
|
:version "1.0"})
|
||||||
|
body (parse-string (:body response))]
|
||||||
|
(is (has-status response 200))
|
||||||
|
(isnt (get-in body ["status" "success"]))
|
||||||
|
(is (= "password invalid" (get-in body ["status" "message"])))
|
||||||
|
(isnt (get-in body ["statistics" "edited"]))
|
||||||
|
(is (substring? "_test_ note"
|
||||||
|
((parse-string
|
||||||
|
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note"))))
|
||||||
|
(is (get-in (parse-string
|
||||||
|
(:body (send-request [:put "/api/note"]
|
||||||
|
{:noteID noteID
|
||||||
|
:note "UPDATED CONTENT"
|
||||||
|
:pid pid
|
||||||
|
:signature (get-signature pid psk noteID "UPDATED CONTENT" "qwerty")
|
||||||
:password "qwerty"
|
:password "qwerty"
|
||||||
:session-value (str (get-hash (str "test note" session-key)))}) 302))
|
:version "1.0"}))) ["status" "success"]))
|
||||||
(is (note-exists? (build-key date title)))
|
(isnt (= nil (((parse-string
|
||||||
(is (substring? "test note"
|
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID})))
|
||||||
((send-request (url year month day title)) :body)))
|
"statistics") "edited")))
|
||||||
(is (has-status
|
|
||||||
(send-request
|
|
||||||
[:post "/update-note"]
|
|
||||||
{:key (build-key [year month day] title)
|
|
||||||
:draft "WRONG pass"
|
|
||||||
:password "qwerty1" }) 403))
|
|
||||||
(is (substring? "test note"
|
|
||||||
((send-request (url year month day title)) :body)))
|
|
||||||
(is (has-status
|
|
||||||
(send-request
|
|
||||||
[:post "/update-note"]
|
|
||||||
{:key (build-key [year month day] title)
|
|
||||||
:draft "UPDATED CONTENT"
|
|
||||||
:password "qwerty" }) 302))
|
|
||||||
(is (substring? "UPDATED CONTENT"
|
(is (substring? "UPDATED CONTENT"
|
||||||
((send-request (url year month day title)) :body)))
|
((parse-string
|
||||||
|
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note")))
|
||||||
(is (do
|
(is (do
|
||||||
(delete-note (build-key date title))
|
(storage/delete-note noteID)
|
||||||
(not (note-exists? (build-key date title))))))))
|
(not (storage/note-exists? noteID)))))))
|
||||||
#_
|
|
||||||
|
|
||||||
(deftest requests
|
|
||||||
(testing "HTTP Status"
|
|
||||||
(testing "of a wrong access"
|
|
||||||
(is (has-status (send-request "/wrong-page") 404))
|
|
||||||
(is (has-status (send-request (url 2012 6 3 "lol" "stat")) 404))
|
|
||||||
(is (has-status (send-request (url 2012 6 3 "lol" "export")) 404))
|
|
||||||
(is (has-status (send-request (url 2012 6 3 "lol")) 404))
|
|
||||||
(is (has-status (send-request (url 2012 6 4 "wrong-title")) 404)))
|
|
||||||
(testing "of corrupt note-post"
|
|
||||||
(is (has-status (send-request [:post "/post-note"]) 400)))
|
|
||||||
(testing "valid accesses"
|
|
||||||
;(is (has-status (send-request "/new") 200) "accessing /new")
|
|
||||||
(is (has-status (send-request (url 2012 6 3 "some-title")) 200) "accessing test note")
|
|
||||||
(is (has-status (send-request (url 2012 6 3 "some-title" "export")) 200) "accessing test note's export")
|
|
||||||
(is (has-status (send-request (url 2012 6 3 "some-title" "stats")) 200) "accessing test note's stats")
|
|
||||||
(is (has-status (send-request "/") 200) "accessing landing page"))))
|
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
[NoteHub.storage]
|
[NoteHub.storage]
|
||||||
[clojure.test]))
|
[clojure.test]))
|
||||||
|
|
||||||
(defn substring? [a b]
|
(defn substring? [a b] (not (= nil (re-matches (re-pattern (str "(?s).*" a ".*")) b))))
|
||||||
(not (= nil (re-matches (re-pattern (str "(?s).*" a ".*")) b))))
|
|
||||||
(def date [2012 6 3])
|
(def date [2012 6 3])
|
||||||
(def test-title "some-title")
|
(def test-title "some-title")
|
||||||
(def test-note "# This is a test note.\nHello _world_. Motörhead, тест.")
|
(def test-note "# This is a test note.\nHello _world_. Motörhead, тест.")
|
||||||
|
|||||||
Reference in New Issue
Block a user