Skip to content

Instantly share code, notes, and snippets.

@amacdougall
Created January 3, 2016 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amacdougall/e869c4cadd61a3d86bae to your computer and use it in GitHub Desktop.
Save amacdougall/e869c4cadd61a3d86bae to your computer and use it in GitHub Desktop.
Test using Prismatic Schema generated users with distinct email/username
(defn- distinct-users []
(let [step (fn step [users usernames emails]
(lazy-seq
((fn [[u :as users] usernames emails] ; first user, usernames, emails
(when-let [s (seq users)]
(if (or (contains? usernames (:username u))
(contains? emails (:email u)))
(recur (rest s) usernames emails)
(cons u (step (rest s)
(conj usernames (:username u))
(conj emails (:email u)))))))
users usernames emails)))]
(step (repeatedly (partial generate NewUser)) #{} #{})))
(deftest test-user-list
(with-rollback-transaction [t-conn db/conn]
(let [users (doall (map user/create! (take 100 (distinct-users))))
user-page (user/get-users)]
(is (= 100 (count users)) "user list should be created")
(is (not (nil? user-page)) "user page should exist")
(is (= 30 (count user-page)) "default user page should have 30 results"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment