as you can see in the console, the value of the ādataā field is not JSON but a String!
However, the 8th assertion in the submit collection API is checking for this particular string āpm.response.jsonā in the test script of the āecho the userā API, otherwise, I could just use the pm.repsonse.text() method instead.
After doing some research on the internet and ask the chat GPT, Iām not entirely sure if the failure of the 8th assertion is the wrong formatted json body or not. So, please feel free to share your insights :v
P/s: I think this issue has just occurred recently. I vividly remembered the response body of the echo API was neat and tidy when I did the day 5 challenge
This is using Postman echo, and it should be returning an object, not a string.
What does your body look like as Postman echo just echoās the body back under the data element.
I get this from time to time when using Postman Echo, where the body looks fine but it keeps returning a string.
Sometimes I have to paste the body into notepad to remove any potential extra formatting, and then paste it back in which can fix the issue. Make sure all of the quotes are normal double quotes, etc as that can also affect it.
For this particular challenge, the variables in the body need to be within quotes like following.
I donāt have any problems with the challenge, the problem is lying within the test script of the submit collection API. For some reasons, the āeventā variable of the below block of code is undefined. I wonder if the reason is due to the incorrect formatted of the echo APIās response body
pm.test(āEcho test addedā, () => {
let echoRequest = folder.item.find(req => { return req.name === āecho the userā})
console.log(echoRequest)
console.log(echoRequest.event)
let event = echoRequest.event.find(e => {return e.listen === ātestā})
pm.expect(event.script.exec.toString(), ācheck parse objectā).contains(āpm.response.jsonā)
pass += 1
})
First of all, this should be its own question. Rather than hi-jacking someone elseās question (which is not related apart from its the same challenge).
I can only recommend to re-read the instructions. These challenges arenāt meant to catch you out, and telling you the answers defeats the main purpose of the challenges\training.
Take a step back and think about the error message.
Itās expecting a variable in the GET request called ānameā.
You are meant to set the collection variables for name, email and UUID from the GET request response as individual elements in the tests tab.
Youāve set an collection variable called āuserdataā using the full response which you then pull apart in the pre-request script for the POST request. You donāt need to do this in the pre-request script. Just set the collection variables for the three elements from the GET request.
Dude, after I tried to submit my collection again, for some unknown reasons all of 8 assertions passed !!?
I have not changed anything at all since I posted this topic.
About the response of my āecho the userā API, itās still the same. The value of ādataā is a string with \r\n all over the place
Now when I check the echoRequest and echoRequest.event with console.log, the result of echoRequest.event is no longer undefined which is of course because the test no longer fails
I literally have not changed anything at all and suddenly it works. Still confused as hell.
Anyway, thanks a lot for trying to help me out. Have a nice day.
wow, it takes me a while to realize what you have been trying to tell me to do.
I did missed those quotes in my body. It worked well in the day 5 challenge without the quotes so I did not think twice about it. Btw I actually thought that you were referring to the double curly brackets since quote could be translated to that in my mother tongue. Silly me :v
Now itās all clear. Thanks a ton, man xD