implementing tests
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
server:
|
||||
lein cljsbuild auto &
|
||||
redis-server &
|
||||
java vimclojure.nailgun.NGServer
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
(:use [jayq.core :only [$ css inner val anim show]])
|
||||
(:require [fetch.remotes :as remotes]
|
||||
[goog.dom :as gdom]
|
||||
[NoteHub.crossover.lib :as nh]
|
||||
[NoteHub.crossover.lib :as lib]
|
||||
[clojure.browser.dom :as dom]
|
||||
[clojure.browser.event :as event])
|
||||
(:require-macros [fetch.macros :as fm]))
|
||||
@@ -40,4 +40,4 @@
|
||||
(.click ($ :#publish-button)
|
||||
(fn [e]
|
||||
(val ($ :#session-value)
|
||||
(nh/hash #(.charCodeAt % 0) (str (val $draft) (val $session-key))))))
|
||||
(lib/hash #(.charCodeAt % 0) (str (val $draft) (val $session-key))))))
|
||||
|
||||
+11
-8
@@ -5,14 +5,17 @@
|
||||
|
||||
(def note "note")
|
||||
|
||||
(defn- build-key [[year month day] key]
|
||||
(print-str year month day key))
|
||||
(defn- build-key [[year month day] title]
|
||||
(print-str year month day title))
|
||||
|
||||
(defn set-note [date key v]
|
||||
(redis/hset db note (build-key date key) v))
|
||||
(defn set-note [date title text]
|
||||
(redis/hset db note (build-key date title) text))
|
||||
|
||||
(defn get-note [date key]
|
||||
(redis/hget db note (build-key date key)))
|
||||
(defn get-note [date title]
|
||||
(redis/hget db note (build-key date title)))
|
||||
|
||||
(defn note-exists? [date key]
|
||||
(redis/hexists db note (build-key date key)))
|
||||
(defn note-exists? [date title]
|
||||
(redis/hexists db note (build-key date title)))
|
||||
|
||||
(defn delete-note [date title]
|
||||
(redis/hdel db note (build-key date title)))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns NoteHub.views.pages
|
||||
(:require [NoteHub.views.common :as common])
|
||||
(:require [NoteHub.crossover.lib :as nh])
|
||||
(:require [NoteHub.crossover.lib :as lib])
|
||||
(:use
|
||||
[NoteHub.storage]
|
||||
[clojure.string :rename {replace sreplace} :only [split replace lower-case]]
|
||||
@@ -98,12 +98,12 @@
|
||||
(let [valid-session (flash-get session-key) ; it was posted from a newly generated form
|
||||
valid-draft (not (empty? draft)) ; the note is non-empty
|
||||
valid-hash (= (Short/parseShort session-value) ; the hash code is correct
|
||||
(nh/hash #(.codePointAt % 0) (str draft session-key)))]
|
||||
(lib/hash #(.codePointAt % 0) (str draft session-key)))]
|
||||
(do
|
||||
; TODO: delete this if tests are written
|
||||
(println "session:" valid-session "draft:" valid-draft "hash:"
|
||||
(Short/parseShort session-value)
|
||||
(nh/hash #(.codePointAt % 0) (str draft session-key)))
|
||||
(lib/hash #(.codePointAt % 0) (str draft session-key)))
|
||||
(if (and valid-session valid-draft valid-hash)
|
||||
(do
|
||||
(set-note date title draft)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
(ns NoteHub.test.all
|
||||
(:use [NoteHub.storage] [clojure.test]))
|
||||
|
||||
(def date [2012 06 03])
|
||||
(def test-title "Some title.")
|
||||
(def test-note "This is a test note.")
|
||||
|
||||
(testing "Storage"
|
||||
(testing "of correct note creation"
|
||||
(is (= (do
|
||||
(set-note date test-title test-note)
|
||||
(get-note date test-title))
|
||||
test-note)))
|
||||
(testing "of the note access"
|
||||
(is (not= (get-note date test-title) "any text")))
|
||||
(testing "of note existence"
|
||||
(is (note-exists? 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")))))
|
||||
|
||||
|
||||
|
||||
; to test
|
||||
;
|
||||
; crossover.lib
|
||||
; storage
|
||||
; pages
|
||||
; noir.util.test
|
||||
@@ -0,0 +1,16 @@
|
||||
(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")))))))
|
||||
@@ -0,0 +1,22 @@
|
||||
(ns NoteHub.test.all
|
||||
(:use [NoteHub.storage] [clojure.test]))
|
||||
|
||||
(def date [2012 06 03])
|
||||
(def test-title "Some title.")
|
||||
(def test-note "This is a test note.")
|
||||
|
||||
(testing "Storage"
|
||||
(testing "of correct note creation"
|
||||
(is (= (do
|
||||
(set-note date test-title test-note)
|
||||
(get-note date test-title))
|
||||
test-note)))
|
||||
(testing "of the note access"
|
||||
(is (not= (get-note date test-title) "any text")))
|
||||
(testing "of note existence"
|
||||
(is (note-exists? 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")))))
|
||||
Reference in New Issue
Block a user