Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

corrected users/datatables test cases and added new test cases for do…

…-register
  • Loading branch information...
commit 896f83c5a75ebcd5aa30bbba08781eb85988e374 1 parent 0e25859
@ckirkendall authored
Showing with 80 additions and 17 deletions.
  1. +64 −0 test/foreclojure/test/register.clj
  2. +16 −17 test/foreclojure/test/users.clj
View
64 test/foreclojure/test/register.clj
@@ -0,0 +1,64 @@
+(ns foreclojure.test.register
+ (:require [sandbar.stateful-session :as session]
+ [ring.util.response :as response])
+ (:use [foreclojure.register] :reload)
@amalloy
amalloy added a note

Why are we reloading here? I'm having trouble imagining a scenario in which this is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ (:use [clojure.test])
+ (:use [midje.sweet])
+ (:use [foreclojure.utils :only [form-row assuming flash-error]])
+ (:use [somnium.congomongo :only [insert! fetch-one]]))
+
+
+
+
+(deftest test-do-register
+ (let [uname "username"
+ lngname "thisisalongusername"
+ bname "$#%^$djc"
+ pwd "password"
+ shpwd "pass"
+ email "test@test.com"
+ bemail "testing.com"]
+ (against-background [(fetch-one :users :where {:user lngname}) => nil
+ (fetch-one :users :where {:user bname}) => nil
+ (fetch-one :users :where {:user uname}) => nil
+ (fetch-one :users :where {:email email}) => nil
+ (insert! :users anything) => nil
+ (session/session-put! :user anything) => nil
+ (session/flash-put! :user anything) => nil
+ (session/flash-put! :email anything) => nil]
+ (fact "about do-register - good inputs"
+ (do-register uname pwd pwd email) => truthy
+ (provided
+ (response/redirect "/") => 1))
+ (fact "about do-register - userexists"
+ (do-register uname pwd pwd email) => truthy
+ (provided
+ (fetch-one :users :where {:user uname}) => {:user "username"}
+ (flash-error "/register" "User already exists") => 1))
+ (fact "about do-register - username too long"
+ (do-register lngname pwd pwd email) => truthy
+ (provided
+ (flash-error "/register" "Username must be 4-13 characters long") => 1))
+ (fact "about do-register - username not alphanumeric"
+ (do-register bname pwd pwd email) => truthy
+ (provided
+ (flash-error "/register" "Username must be alphanumeric") => 1))
+ (fact "about do-register - short password"
+ (do-register uname shpwd shpwd email) => truthy
+ (provided
+ (flash-error "/register" "Password must be at least seven characters long") => 1))
+ (fact "about do-register - passwords don't match"
+ (do-register uname pwd shpwd email) => truthy
+ (provided
+ (flash-error "/register" "Passwords don't match") => 1))
+ (fact "about do-register - bad emal"
+ (do-register uname pwd pwd bemail) => truthy
+ (provided
+ (flash-error "/register" "Please enter a valid email address") => 1))
+ (fact "about do-register - email exists"
+ (do-register uname pwd pwd email) => truthy
+ (provided
+ (fetch-one :users :where {:user uname}) => nil
+ (fetch-one :users :where {:email email}) => {:user "username"}
+ (flash-error "/register" "User with this email address already exists") => 1)))))
+
View
33 test/foreclojure/test/users.clj
@@ -5,7 +5,7 @@
(def users [{:user "user1", :solved [1 2 3 4] :rank 1}
{:user "user2", :solved [1 2 3] :rank 2}
- {:user "user3", :sovled [1 2] :rank 3}
+ {:user "user3", :solved [1 2] :rank 3}
{:user "user4", :solved [1] :rank 4}
{:user "user5", :solved [1] :rank 5}
{:user "user6", :solved [1] :rank 6}
@@ -18,31 +18,30 @@
(deftest user-datatables-paging
(facts "about datatable-paging"
- (count (datatable-paging users 0 10)) => 10
- (count (datatable-paging users 8 10)) => 2
- (count (datatable-paging users 2 5))) => 5
- (:user (first (datatable-paging users 2 5))) => "user3"
- (:user (last (datatable-paging users 2 5))) => "user7")
+ (count (datatable-paging 0 10 users)) => 10
+ (count (datatable-paging 8 10 users)) => 2
+ (count (datatable-paging 2 5 users))) => 5
+ (:user (first (datatable-paging 2 5 users))) => "user3"
+ (:user (last (datatable-paging 2 5 users))) => "user7")
(deftest user-datatables-sort-cols
(facts "about datatable sorting by columns"
- (:user (first (datatable-sort-cols users 0))) => "user1"
- (:user (second (datatable-sort-cols users 1))) => "user10"
- (:user (first (datatable-sort-cols users 2))) => "user1"
- (:user (first (datatable-sort-cols users 3))) => "user1"))
+ (:user (first (datatable-sort-cols 0 users))) => "user1"
+ (:user (second (datatable-sort-cols 1 users))) => "user10"
+ (:user (last (datatable-sort-cols 2 users))) => "user1"))
(deftest user-datatables-sort-dir
(facts "about datatable sort direction"
- (:user (first (datatable-sort-dir users "asc"))) => "user1"
- (:user (first (datatable-sort-dir users "desc"))) => "user10"))
+ (:user (first (datatable-sort-dir "asc" users))) => "user1"
+ (:user (first (datatable-sort-dir "desc" users))) => "user10"))
(deftest user-datatables-sort
(facts "about sorting by column and direction combined"
- (:user (first (datatable-sort users 1 "asc"))) => "user1"
- (:user (first (datatable-sort users 1 "desc"))) => "user9"))
+ (:user (first (datatable-sort 1 "asc" users))) => "user1"
+ (:user (first (datatable-sort 1 "desc" users))) => "user9"))
(deftest user-datatables-filter
(facts "about filtering the username by text"
- (:user (first (datatable-filter users "4"))) => "user4"
- (:user (second (datatable-filter users "1"))) => "user10"
- (count (datatable-filter users nil)) => 10))
+ (:user (first (datatable-filter "4" users))) => "user4"
+ (:user (second (datatable-filter "1" users))) => "user10"
+ (count (datatable-filter nil users)) => 10))
Please sign in to comment.
Something went wrong with that request. Please try again.