|
|
|
@ -1,24 +1,15 @@ |
|
|
|
(ns notehub.test.handler |
|
|
|
(ns notehub.test.handler |
|
|
|
(:use clojure.test |
|
|
|
(:use clojure.test |
|
|
|
|
|
|
|
[notehub.api :only [build-key get-date url]] |
|
|
|
|
|
|
|
notehub.storage |
|
|
|
ring.mock.request |
|
|
|
ring.mock.request |
|
|
|
|
|
|
|
notehub.test.api |
|
|
|
notehub.handler)) |
|
|
|
notehub.handler)) |
|
|
|
|
|
|
|
|
|
|
|
(defn substring? [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, тест.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#_( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(ns NoteHub.test.views.pages |
|
|
|
|
|
|
|
(:use [NoteHub.views.pages] |
|
|
|
|
|
|
|
[NoteHub.api :only [build-key get-signature get-date url]] |
|
|
|
|
|
|
|
[noir.util.test] |
|
|
|
|
|
|
|
[NoteHub.storage] |
|
|
|
|
|
|
|
[clojure.test])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn create-testnote-fixture [f] |
|
|
|
(defn create-testnote-fixture [f] |
|
|
|
(add-note (build-key date test-title) test-note "testPID") |
|
|
|
(add-note (build-key date test-title) test-note "testPID") |
|
|
|
(f) |
|
|
|
(f) |
|
|
|
@ -35,10 +26,10 @@ |
|
|
|
|
|
|
|
|
|
|
|
(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 (= (: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 "somemd5hash" |
|
|
|
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] |
|
|
|
@ -47,7 +38,7 @@ |
|
|
|
[:post "/post-note"] |
|
|
|
[:post "/post-note"] |
|
|
|
{:session session-key |
|
|
|
{:session session-key |
|
|
|
:note test-note |
|
|
|
:note test-note |
|
|
|
:signature (get-signature session-key test-note)})] |
|
|
|
:signature (sign session-key test-note)})] |
|
|
|
(is (has-status resp 302)) |
|
|
|
(is (has-status resp 302)) |
|
|
|
(is (note-exists? (build-key date title))) |
|
|
|
(is (note-exists? (build-key date title))) |
|
|
|
(is (substring? "Hello _world_" |
|
|
|
(is (substring? "Hello _world_" |
|
|
|
@ -57,7 +48,7 @@ |
|
|
|
(not (note-exists? (build-key date title))))))))) |
|
|
|
(not (note-exists? (build-key date title))))))))) |
|
|
|
|
|
|
|
|
|
|
|
(deftest note-creation-utf |
|
|
|
(deftest note-creation-utf |
|
|
|
(let [session-key (create-session) |
|
|
|
(let [session-key "somemd5hash" |
|
|
|
date (get-date) |
|
|
|
date (get-date) |
|
|
|
title "радуга" |
|
|
|
title "радуга" |
|
|
|
note "# Радуга\nкаждый охотник желает знать, где сидят фазаны." |
|
|
|
note "# Радуга\nкаждый охотник желает знать, где сидят фазаны." |
|
|
|
@ -68,7 +59,7 @@ |
|
|
|
[:post "/post-note"] |
|
|
|
[:post "/post-note"] |
|
|
|
{:session session-key |
|
|
|
{:session session-key |
|
|
|
:note note |
|
|
|
:note note |
|
|
|
:signature (get-signature session-key note)}) 302)) |
|
|
|
:signature (sign session-key note)}) 302)) |
|
|
|
(is (note-exists? (build-key date title))) |
|
|
|
(is (note-exists? (build-key date title))) |
|
|
|
(is (substring? "знать" ((send-request (url year month day title)) :body))) |
|
|
|
(is (substring? "знать" ((send-request (url year month day title)) :body))) |
|
|
|
(is (do |
|
|
|
(is (do |
|
|
|
@ -76,11 +67,11 @@ |
|
|
|
(not (note-exists? (build-key date title)))))))) |
|
|
|
(not (note-exists? (build-key date title)))))))) |
|
|
|
|
|
|
|
|
|
|
|
(deftest note-update |
|
|
|
(deftest note-update |
|
|
|
(let [session-key (create-session) |
|
|
|
(let [session-key "somemd5hash" |
|
|
|
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 |
|
|
|
hash (get-signature session-key test-note)] |
|
|
|
hash (sign session-key test-note)] |
|
|
|
(testing "Note update" |
|
|
|
(testing "Note update" |
|
|
|
(is (has-status |
|
|
|
(is (has-status |
|
|
|
(send-request |
|
|
|
(send-request |
|
|
|
@ -128,9 +119,6 @@ |
|
|
|
(is (has-status (send-request "/") 200) "accessing landing page")))) |
|
|
|
(is (has-status (send-request "/") 200) "accessing landing page")))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(deftest test-app |
|
|
|
(deftest test-app |
|
|
|
(testing "main route" |
|
|
|
(testing "main route" |
|
|
|
(let [response (app (request :get "/"))] |
|
|
|
(let [response (app (request :get "/"))] |
|
|
|
|