My function accepts a map argument in which i get the deposit value from it. Currently I'm able to test scenarios like whether the deposit value is empty or whether the deposit value is greater than a certain value etc. My API tracks the number of times a user makes the deposit and keeps track of this using an atom and when user has made more than 4 deposits, he/she should get a certain error message. How can I test this scenario using midje?
Below is my sample test case:
(facts "Mytesting"
(fact "Invalid Amount"
(let [response (httpserver/app (mock/request
:post "/deposit"
{:deposit "9"}))] ;
(:status response) => 422
(:headers response) => {"Content-Type" "application/json; charset=utf-8", "X-Content-Type-Options" "nosniff", "X-Frame-Options" "SAMEORIGIN", "X-XSS-Protection" "1; mode=block"}
(:body response) => (json/write-str {:status-code -2 :status-msg "Invalid Amount"}))))
Well, for starters, you should write your tests first :-).
But since the code already exists, I'll tell you how I usually work:
provided
functionality provided by Midje to verify that the backing functions are invoked correctly.provided
to mock out any other functionality that's not immediately relevant.You can of course also add end-to-end tests that verify the behavior of the entire code stack, but that may involve setting up a database, etc...
To know more about how to test your specific code, I would need to know more about the inner workings.