Skip to content

Instantly share code, notes, and snippets.

@souenzzo
Created August 20, 2018 23:51
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 souenzzo/ac749129ac29d85a053b52b663d6e4d0 to your computer and use it in GitHub Desktop.
Save souenzzo/ac749129ac29d85a053b52b663d6e4d0 to your computer and use it in GitHub Desktop.
TDD de uma API REST
(deftest create-user
(let [email-count (atom 0)
token (atom nil)
id (atom nil)]
;; redefinindo função que envia emal
(binding [ses/send-email (fn [_] (swap! email-count inc) true)]
(fact
"Post de criação do usuário"
(POST "/user"
{:user/name "Me" :user/email "me@gmail.com"})
=> (contains {:body (contains {;; conferindo algumas chaves que voltaram
:user/active? false
;; conferindo e armazenando o token
:user/id #(string? (reset! id %))
:user/token #(string? (reset! token %))})
:status 200}))
(fact
"conferindo email enviado"
@email-count => 1)
(fact
"Ativando email"
(GET "/active-user" {:id @id :token @token})
=> (contains {:status 200}))
(fact
"Conferindo se usuário foi ativado"
(GET (str "/user/" @id))
=> (contains {:body (contains {:user/active? true})})))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment