Created
August 20, 2018 23:51
-
-
Save souenzzo/ac749129ac29d85a053b52b663d6e4d0 to your computer and use it in GitHub Desktop.
TDD de uma API REST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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