storage layer made more BL independent
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
(ns NoteHub.test.storage
|
||||
(:use [NoteHub.storage] [clojure.test]))
|
||||
(:use [NoteHub.storage]
|
||||
[NoteHub.views.pages]
|
||||
[clojure.test]))
|
||||
|
||||
(def date [2012 06 03])
|
||||
(def test-title "Some title.")
|
||||
@@ -25,29 +27,29 @@
|
||||
(short-url-exists? url))))))
|
||||
(testing "of correct note creation"
|
||||
(is (= (do
|
||||
(set-note date test-title test-note)
|
||||
(get-note date test-title))
|
||||
(add-note (build-key date test-title) test-note)
|
||||
(get-note (build-key date test-title)))
|
||||
test-note))
|
||||
(is (= "1" (get-note-views date test-title)))
|
||||
(is (= "1" (get-note-views (build-key date test-title))))
|
||||
(is (= (do
|
||||
(get-note date test-title)
|
||||
(get-note-views date test-title))
|
||||
(get-note (build-key date test-title))
|
||||
(get-note-views (build-key date test-title)))
|
||||
"2")))
|
||||
(testing "of note update"
|
||||
(is (= (do
|
||||
(set-note date test-title test-note "12345qwert")
|
||||
(get-note date test-title))
|
||||
(add-note (build-key date test-title) test-note "12345qwert")
|
||||
(get-note (build-key date test-title)))
|
||||
test-note))
|
||||
(is (= (do
|
||||
(update-note (build-key date test-title) "update" "12345qwert")
|
||||
(get-note date test-title))
|
||||
(get-note (build-key date test-title)))
|
||||
"update"))
|
||||
(is (= (do
|
||||
(update-note (build-key date test-title) "not authorized" "44444")
|
||||
(get-note date test-title))
|
||||
(get-note (build-key date test-title)))
|
||||
"update")))
|
||||
(testing "of the note access"
|
||||
(is (not= (get-note date test-title) "any text")))
|
||||
(is (not= (get-note (build-key date test-title)) "any text")))
|
||||
(testing "session management"
|
||||
(let [s1 (create-session)
|
||||
s2 (create-session)
|
||||
@@ -58,9 +60,9 @@
|
||||
(is (not (invalidate-session "wrongtoken")))
|
||||
(is (invalidate-session s3))))
|
||||
(testing "of note existence"
|
||||
(is (note-exists? date test-title))
|
||||
(is (note-exists? (build-key date test-title)))
|
||||
(is (not (do
|
||||
(delete-note date test-title)
|
||||
(note-exists? date test-title))))
|
||||
(is (not (note-exists? [2013 06 03] test-title)))
|
||||
(is (not (note-exists? date "some title"))))))
|
||||
(delete-note (build-key date test-title))
|
||||
(note-exists? (build-key date test-title)))))
|
||||
(is (not (note-exists? (build-key [2013 06 03] test-title))))
|
||||
(is (not (note-exists? (build-key date "some title")))))))
|
||||
|
||||
@@ -6,16 +6,15 @@
|
||||
[clojure.test]))
|
||||
|
||||
(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 test-title "some-title")
|
||||
(def test-note "# This is a test note.\nHello _world_. Motörhead, тест.")
|
||||
|
||||
(defn create-testnote-fixture [f]
|
||||
(set-note date test-title test-note)
|
||||
(add-note (build-key date test-title) test-note)
|
||||
(f)
|
||||
(delete-note date test-title))
|
||||
(delete-note (build-key date test-title)))
|
||||
|
||||
(use-fixtures :each create-testnote-fixture)
|
||||
|
||||
@@ -23,8 +22,8 @@
|
||||
|
||||
(deftest testing-fixture
|
||||
(testing "Was a not created?"
|
||||
(is (= (get-note date test-title) test-note))
|
||||
(is (note-exists? date test-title))))
|
||||
(is (= (get-note (build-key date test-title)) test-note))
|
||||
(is (note-exists? (build-key date test-title)))))
|
||||
|
||||
(deftest export-test
|
||||
(testing "Markdown export"
|
||||
@@ -42,12 +41,12 @@
|
||||
{:session-key session-key
|
||||
:draft test-note
|
||||
:session-value (str (get-hash (str test-note session-key)))}) 302))
|
||||
(is (note-exists? date title))
|
||||
(is (note-exists? (build-key date title)))
|
||||
(is (substring? "Hello _world_"
|
||||
((send-request (url year month day title)) :body)))
|
||||
(is (do
|
||||
(delete-note date title)
|
||||
(not (note-exists? date title)))))))
|
||||
(delete-note (build-key date title))
|
||||
(not (note-exists? (build-key date title))))))))
|
||||
|
||||
(deftest note-update
|
||||
(let [session-key (create-session)
|
||||
@@ -62,7 +61,7 @@
|
||||
:draft "test note"
|
||||
:password "qwerty"
|
||||
:session-value (str (get-hash (str "test note" session-key)))}) 302))
|
||||
(is (note-exists? date title))
|
||||
(is (note-exists? (build-key date title)))
|
||||
(is (substring? "test note"
|
||||
((send-request (url year month day title)) :body)))
|
||||
(is (has-status
|
||||
@@ -82,8 +81,8 @@
|
||||
(is (substring? "UPDATED CONTENT"
|
||||
((send-request (url year month day title)) :body)))
|
||||
(is (do
|
||||
(delete-note date title)
|
||||
(not (note-exists? date title)))))))
|
||||
(delete-note (build-key date title))
|
||||
(not (note-exists? (build-key date title))))))))
|
||||
|
||||
(deftest requests
|
||||
(testing "HTTP Status"
|
||||
|
||||
Reference in New Issue
Block a user