Post by account_disabled on Jan 8, 2024 4:58:23 GMT -5
Response body object Verify that there are two keys in the response and the value of and matches the test user's username Successfully when it should respond with a valid session token. In this test you will again follow a very similar process to the previous two tests. token is present in the response body. Add the following test below the previous test As you can see above the request is sent to the target endpoint and the response body is abstracted from the result. This function is used to verify the presence of the key in the response body. This function is then used to verify the session token. Note: It is important to note that similar to password encryption, it is also important to validate the session token using the same function used in . It should respond with a status code when invalid credentials are given Now you will verify that sending the request body with invalid credentials results in the correct error response. To reproduce this scenario you simply send a request with the test user's correct username but incorrect password. Add the following test As you can see above the response status is expected to be.
Also added an expectation that the response body does not contain attributes since invalid login requests should not trigger the generation of session tokens. Note photo editing servies that the second expectation of this test is not strictly necessary as the status code is enough to know that the condition in the controller has been met to short-circuit the request and respond with an error. It should respond with a status code when the user is not found Here you will test the scenario where the user cannot be found using the provided username. As was the case with the previous test this should short-circuit the request and cause an early response with an error status code. Add the following to your test When given an invalid request body it should respond with a status code In this final test you will verify that sending an.
Invalid request body results in an error response. The middleware used in should catch invalid request bodies and completely short-circuit the authentication controller. Add the following test to complete this set of tests As you can see above the field has been switched to another field as was done in the tests earlier in this article. So the request body does not match the definition of the request body and triggers an error. If you go you should see that the entire set of tests for both endpoints successfully passes all checks. Screen showing the full set of passed integration tests Summary and what's next Congratulations on making it to the end of this article This part of the testing series is packed with information so let's recap. During reading this article you understood what is integration testing Set up a container to run in a test environment.
Also added an expectation that the response body does not contain attributes since invalid login requests should not trigger the generation of session tokens. Note photo editing servies that the second expectation of this test is not strictly necessary as the status code is enough to know that the condition in the controller has been met to short-circuit the request and respond with an error. It should respond with a status code when the user is not found Here you will test the scenario where the user cannot be found using the provided username. As was the case with the previous test this should short-circuit the request and cause an early response with an error status code. Add the following to your test When given an invalid request body it should respond with a status code In this final test you will verify that sending an.
Invalid request body results in an error response. The middleware used in should catch invalid request bodies and completely short-circuit the authentication controller. Add the following test to complete this set of tests As you can see above the field has been switched to another field as was done in the tests earlier in this article. So the request body does not match the definition of the request body and triggers an error. If you go you should see that the entire set of tests for both endpoints successfully passes all checks. Screen showing the full set of passed integration tests Summary and what's next Congratulations on making it to the end of this article This part of the testing series is packed with information so let's recap. During reading this article you understood what is integration testing Set up a container to run in a test environment.