Post by account_disabled on Jan 9, 2024 0:06:44 GMT -5
Method used in . set of tests is complete you can move on to writing your tests. Just like before, the next six sections will cover each scenario individually and walk through how the test works. It should respond with a status code when valid credentials are provided. The first test will only verify a valid login request and the correct credentials in the response code from the result. Start by adding a new test in the block of this set of tests just below the function. To test the desired behavior send a request to the endpoint using the same username and password used to create the test user. Then after verifying that the status code of the response is successful it should respond with the user details The next test is very similar to the previous one except instead of checking the response status you will check the object in the response body and validate its content. Add another test with the following content.
The above test content does the following Send a request The request body contains the test user's username and password Extract the keys of the response photo editing servies 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. Only this test will verify that a valid session 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 that the.
The above test content does the following Send a request The request body contains the test user's username and password Extract the keys of the response photo editing servies 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. Only this test will verify that a valid session 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 that the.