Tests Call the API as a User Would—Helper Functions
Discover how to test Elixir API boundaries by using helper functions that mimic user actions, such as starting a quiz, selecting questions, and submitting answers. Explore setting up the test environment with persistence and templates, ensuring reliable and clear test outputs.
We'll cover the following...
Starting and taking a quiz
Now, we can move on to the helpers that will let us build, start, and take the quiz:
-
start_quizschedules the quiz to start immediately with more than enough time to take the quiz. We’ll achieve mastery far before the timer runs out. -
take_quizlets a user establish a session.
Answering a quiz
Now, we can move on to the helpers to answer a quiz:
By now, these functions should be pretty familiar. We have a function to select a question and then a couple of functions to provide right and wrong answers. Notice that we provide the persistence function to use for saving the responses. That way, only the tests that use these functions will actually persist ...