tests adjusted
This commit is contained in:
@@ -1,16 +0,0 @@
|
|||||||
(ns NoteHub.test.crossover.lib
|
|
||||||
(:require [NoteHub.crossover.lib :as lib])
|
|
||||||
(:use [clojure.test]))
|
|
||||||
|
|
||||||
(with-test
|
|
||||||
(defn lib-hash [s]
|
|
||||||
(lib/hash #(.codePointAt % 0) s))
|
|
||||||
(testing "Crossover Lib:"
|
|
||||||
(testing "Self-made hash function"
|
|
||||||
(testing "for correct hashes"
|
|
||||||
(is (= 0 (lib-hash "")))
|
|
||||||
(is (= 6178 (lib-hash "test тест")))
|
|
||||||
(is (= 6178 (lib-hash (str "test\n \rтест"))))
|
|
||||||
(is (= 274 (lib-hash "Hello world!"))))
|
|
||||||
(testing "for a wrong hash"
|
|
||||||
(is (not= 6178 (lib-hash "wrong hash")))))))
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
(ns NoteHub.test.views.pages
|
(ns NoteHub.test.views.pages
|
||||||
(:require [NoteHub.crossover.lib :as lib])
|
|
||||||
(:use [NoteHub.views.pages]
|
(:use [NoteHub.views.pages]
|
||||||
[noir.util.test]
|
[noir.util.test]
|
||||||
[NoteHub.views.common :only [url]]
|
[NoteHub.views.common :only [url]]
|
||||||
@@ -23,88 +22,92 @@
|
|||||||
(is (= (url 2010 05 06 "test-title" "export") "/2010/5/6/test-title/export"))
|
(is (= (url 2010 05 06 "test-title" "export") "/2010/5/6/test-title/export"))
|
||||||
|
|
||||||
(deftest testing-fixture
|
(deftest testing-fixture
|
||||||
(testing "Was a not created?"
|
(testing "Was a not created?"
|
||||||
(is (= (get-note date test-title) test-note))
|
(is (= (get-note date test-title) test-note))
|
||||||
(is (note-exists? date test-title))))
|
(is (note-exists? date test-title))))
|
||||||
|
|
||||||
(deftest helper-functions
|
|
||||||
(testing "Markdown generation"
|
|
||||||
(is (= "<h1><em>hellö</em> <strong>world</strong></h1><p>test <code>code</code></p>"
|
|
||||||
(md-to-html "#_hellö_ __world__\ntest `code`")))))
|
|
||||||
(deftest export-test
|
(deftest export-test
|
||||||
(testing "Markdown export"
|
(testing "Markdown export"
|
||||||
(is (has-body (send-request (url 2012 6 3 "some-title" "export")) test-note))))
|
(is (has-body (send-request (url 2012 6 3 "some-title" "export")) test-note))))
|
||||||
|
|
||||||
(deftest note-creation
|
(deftest note-creation
|
||||||
(let [session-key (create-session)
|
(let [session-key (create-session)
|
||||||
date (get-date)
|
date (get-date)
|
||||||
title "this-is-a-test-note"
|
title "this-is-a-test-note"
|
||||||
[year month day] date]
|
[year month day] date]
|
||||||
(testing "Note creation"
|
(testing "Note creation"
|
||||||
(is (has-status
|
(is (has-status
|
||||||
(send-request
|
(send-request
|
||||||
[:post "/post-note"]
|
[:post "/post-note"]
|
||||||
{:session-key session-key
|
{:session-key session-key
|
||||||
:draft test-note
|
:draft test-note
|
||||||
:session-value (str (lib/hash #(.codePointAt % 0)
|
:session-value (str (get-hash (str test-note session-key)))}) 302))
|
||||||
(str test-note session-key)))}) 302))
|
(is (note-exists? date title))
|
||||||
(is (note-exists? date title))
|
(is (substring? "Hello _world_"
|
||||||
(is (substring? "Hello <em>world</em>"
|
((send-request (url year month day title)) :body)))
|
||||||
((send-request (url year month day title)) :body)))
|
(is (do
|
||||||
(is (do
|
(delete-note date title)
|
||||||
(delete-note date title)
|
(not (note-exists? date title)))))))
|
||||||
(not (note-exists? date title)))))))
|
|
||||||
|
|
||||||
(deftest note-update
|
(deftest note-update
|
||||||
(let [session-key (create-session)
|
(let [session-key (create-session)
|
||||||
date (get-date)
|
date (get-date)
|
||||||
title "test-note"
|
title "test-note"
|
||||||
[year month day] date]
|
[year month day] date]
|
||||||
(testing "Note update"
|
(testing "Note update"
|
||||||
(is (has-status
|
(is (has-status
|
||||||
(send-request
|
(send-request
|
||||||
[:post "/post-note"]
|
[:post "/post-note"]
|
||||||
{:session-key session-key
|
{:session-key session-key
|
||||||
:draft "test note"
|
:draft "test note"
|
||||||
:password "qwerty"
|
:password "qwerty"
|
||||||
:session-value (str (lib/hash #(.codePointAt % 0)
|
:session-value (str (get-hash (str "test note" session-key)))}) 302))
|
||||||
(str "test note" session-key)))}) 302))
|
(is (note-exists? date title))
|
||||||
(is (note-exists? date title))
|
(is (substring? "test note"
|
||||||
(is (substring? "test note"
|
((send-request (url year month day title)) :body)))
|
||||||
((send-request (url year month day title)) :body)))
|
(is (has-status
|
||||||
(is (has-status
|
(send-request
|
||||||
(send-request
|
[:post "/update-note"]
|
||||||
[:post "/update-note"]
|
{:key (build-key [year month day] title)
|
||||||
{:key (build-key [year month day] title)
|
:draft "WRONG pass"
|
||||||
:draft "WRONG pass"
|
:password "qwerty1" }) 403))
|
||||||
:password "qwerty1" }) 403))
|
(is (substring? "test note"
|
||||||
(is (substring? "test note"
|
((send-request (url year month day title)) :body)))
|
||||||
((send-request (url year month day title)) :body)))
|
(is (has-status
|
||||||
(is (has-status
|
(send-request
|
||||||
(send-request
|
[:post "/update-note"]
|
||||||
[:post "/update-note"]
|
{:key (build-key [year month day] title)
|
||||||
{:key (build-key [year month day] title)
|
:draft "UPDATED CONTENT"
|
||||||
:draft "UPDATED CONTENT"
|
:password "qwerty" }) 302))
|
||||||
:password "qwerty" }) 302))
|
(is (substring? "UPDATED CONTENT"
|
||||||
(is (substring? "UPDATED CONTENT"
|
((send-request (url year month day title)) :body)))
|
||||||
((send-request (url year month day title)) :body)))
|
(is (do
|
||||||
(is (do
|
(delete-note date title)
|
||||||
(delete-note date title)
|
(not (note-exists? date title)))))))
|
||||||
(not (note-exists? date title)))))))
|
|
||||||
|
|
||||||
(deftest requests
|
(deftest requests
|
||||||
(testing "HTTP Status"
|
(testing "HTTP Status"
|
||||||
(testing "of a wrong access"
|
(testing "of a wrong access"
|
||||||
(is (has-status (send-request "/wrong-page") 404))
|
(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" "stat")) 404))
|
||||||
(is (has-status (send-request (url 2012 6 3 "lol" "export")) 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 3 "lol")) 404))
|
||||||
(is (has-status (send-request (url 2012 6 4 "wrong-title")) 404)))
|
(is (has-status (send-request (url 2012 6 4 "wrong-title")) 404)))
|
||||||
(testing "of corrupt note-post"
|
(testing "of corrupt note-post"
|
||||||
(is (has-status (send-request [:post "/post-note"]) 400)))
|
(is (has-status (send-request [:post "/post-note"]) 400)))
|
||||||
(testing "valid accesses"
|
(testing "valid accesses"
|
||||||
;(is (has-status (send-request "/new") 200) "accessing /new")
|
;(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")) 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" "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 (url 2012 6 3 "some-title" "stats")) 200) "accessing test note's stats")
|
||||||
(is (has-status (send-request "/") 200) "accessing landing page"))))
|
(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