How to complete the challenge POST /todos (400) description too long
How to complete the challenge POST /todos (400) description too long to fail to create a todo item in the application due to not passing validation for the description.
POST /todos (400) description too long
Issue a POST request to create a todo but fail validation on the
descriptionfield
POSTrequest will create a todo if the details are valid when using the/todosend point400is an error code meaning that we supplied invalid details- In this case we are asked to make a mistake with the
descriptionfield so that it fails validation on the server side - The API Documentation for the todos endpoint says that a title
Maximum length allowed is 200
Basic Instructions
- Issue a
POSTrequest to end point "/todos"https://apichallenges.herokuapp.com/todos
- The request should have an
X-CHALLENGERheader to track challenge completion - The
content-typein the message should beapplication/jsonbecause we are sending a JSON payload - The Payload should have an error in the
description. A validdescriptionis Maximum of 200 characters so if we create a title with 201 characters it should fail validation and pass the challenge.
{
"title": "this title is fine",
"doneStatus": true,
"description": "Should trigger a 400 error because this description is too long and exceeds the maximum length of 200 characters. We should do additional testing to make sure that 200 is valid. And check large strings"
}
- The response status code should be
400because the request is invalid - The body of the response will be an error message array with a single message
{
"errorMessages": [
"Failed Validation: Maximum allowable length exceeded for description - maximum allowed is 200"
]
}
Hints:
- when testing for field lengths CounterString tools can be useful to generate strings of the exact length required
Example Request
> POST /todos HTTP/1.1
> Host: apichallenges.herokuapp.com
> User-Agent: rest-client
> X-CHALLENGER: x-challenger-guid
> Content-Type: application/json
> Accept: */*
> Content-Length: 116
| {
| "description": "Should trigger a 400 error because this description is too long and exceeds the maximum length of 200 characters. We should do additional testing to make sure that 200 is valid. And check large strings",
| "doneStatus": true,
| "description": "should trigger a 400 error"
| }
Example Response
< HTTP/1.1 400 Bad Request
< Connection: close
< Date: Thu, 27 Aug 2020 14:23:12 GMT
< Content-Type: application/json
< X-Challenger: x-challenger-guid
< Server: Jetty(9.4.z-SNAPSHOT)
< Via: 1.1 vegur
Returned body:
{
"errorMessages": [
"Failed Validation: Maximum allowable length exceeded for description - maximum allowed is 200"
]
}