migrated to API internally
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
(def pid "somePlugin")
|
||||
(def pid2 "somePlugin2")
|
||||
(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 "/" (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)))
|
||||
@@ -43,8 +43,8 @@
|
||||
(is (:success (:status post-response)))
|
||||
(is (:success (:status get-response)))
|
||||
(is (= note (:note get-response)))
|
||||
(is (= (:longURL post-response) (:longURL get-response) note-url))
|
||||
(is (= (:shortURL post-response) (:shortURL get-response)))
|
||||
(is (= (:longPath post-response) (:longPath get-response) note-url))
|
||||
(is (= (:shortPath post-response) (:shortPath get-response)))
|
||||
(is (= "1" (get-in get-response [:statistics :views])))
|
||||
(isnt (get-in get-response [:statistics :edited]))
|
||||
(is (= "2" (get-in (get-note (:noteID post-response)) [:statistics :views])))))
|
||||
|
||||
@@ -43,11 +43,7 @@
|
||||
test-note))
|
||||
(is (valid-password? (build-key date test-title) "12345qwert"))
|
||||
(is (= (do
|
||||
(update-note (build-key date test-title) "update" "12345qwert")
|
||||
(get-note (build-key date test-title)))
|
||||
"update"))
|
||||
(is (= (do
|
||||
(update-note (build-key date test-title) "not authorized" "44444")
|
||||
(edit-note (build-key date test-title) "update")
|
||||
(get-note (build-key date test-title)))
|
||||
"update")))
|
||||
(testing "of the note access"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns NoteHub.test.views.pages
|
||||
(:use [NoteHub.views.pages]
|
||||
[NoteHub.api :only [build-key get-date]]
|
||||
[NoteHub.api :only [build-key get-signature get-date]]
|
||||
[noir.util.test]
|
||||
[NoteHub.views.common :only [url]]
|
||||
[NoteHub.storage]
|
||||
@@ -38,9 +38,9 @@
|
||||
(is (has-status
|
||||
(send-request
|
||||
[:post "/post-note"]
|
||||
{:session-key session-key
|
||||
:draft test-note
|
||||
:session-value (str (get-hash (str test-note session-key)))}) 302))
|
||||
{:session session-key
|
||||
:note test-note
|
||||
:signature (get-signature session-key test-note)}) 302))
|
||||
(is (note-exists? (build-key date title)))
|
||||
(is (substring? "Hello _world_"
|
||||
((send-request (url year month day title)) :body)))
|
||||
@@ -51,35 +51,33 @@
|
||||
(deftest note-update
|
||||
(let [session-key (create-session)
|
||||
date (get-date)
|
||||
title "test-note"
|
||||
[year month day] date]
|
||||
title "this-is-a-test-note"
|
||||
[year month day] date
|
||||
hash (get-signature session-key test-note)]
|
||||
(testing "Note update"
|
||||
(is (has-status
|
||||
(send-request
|
||||
[:post "/post-note"]
|
||||
{:session-key session-key
|
||||
:draft "test note"
|
||||
{:session session-key
|
||||
:note test-note
|
||||
:password "qwerty"
|
||||
:session-value (str (get-hash (str "test note" session-key)))}) 302))
|
||||
:signature hash}) 302))
|
||||
(is (note-exists? (build-key date title)))
|
||||
(is (substring? "test note"
|
||||
((send-request (url year month day title)) :body)))
|
||||
(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 "WRONG pass"
|
||||
{:noteID (build-key [year month day] title)
|
||||
:note "WRONG pass"
|
||||
:password "qwerty1" }) 403))
|
||||
(is (substring? "test note"
|
||||
((send-request (url year month day title)) :body)))
|
||||
(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"
|
||||
{:noteID (build-key [year month day] title)
|
||||
:note "UPDATED CONTENT 123"
|
||||
:password "qwerty" }) 302))
|
||||
(is (substring? "UPDATED CONTENT"
|
||||
((send-request (url year month day title)) :body)))
|
||||
(is (substring? "UPDATED CONTENT" ((send-request (url year month day title)) :body)))
|
||||
(is (do
|
||||
(delete-note (build-key date title))
|
||||
(not (note-exists? (build-key date title))))))))
|
||||
@@ -100,13 +98,3 @@
|
||||
(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"))))
|
||||
|
||||
(deftest hash-function
|
||||
(testing "Self-made hash function"
|
||||
(testing "for correct hashes"
|
||||
(is (= 0 (get-hash "")))
|
||||
(is (= 6178 (get-hash "test тест")))
|
||||
(is (= 6178 (get-hash (str "test\n \rтест"))))
|
||||
(is (= 274 (get-hash "Hello world!"))))
|
||||
(testing "for a wrong hash"
|
||||
(is (not= 6178 (get-hash "wrong hash"))))))
|
||||
|
||||
Reference in New Issue
Block a user