Complete the code to set a test variable named 'userId' with value 123.
pm.environment.set('[1]', 123);
The pm.environment.set function sets an environment variable. Here, the variable name should be 'userId' to store the value 123.
Complete the code to check if the response status code is 200.
pm.test('Status code is 200', function () { pm.response.to.have.status([1]); });
The test checks if the response status code is exactly 200, which means success.
Fix the error in the code to parse JSON response body correctly.
let data = pm.response.[1]();text() which returns a string, not parsed JSON.parse() which is not a method of pm.response.The pm.response.json() method parses the response body as JSON and returns the object.
Fill both blanks to write a test that checks if the response body has a property 'success' equal to true.
pm.test('Response has success true', function () { pm.expect(pm.response.[1]()).to.have.property('[2]', true); });
text() instead of json() for parsing.We use pm.response.json() to get the response object, then check it has property 'success' with value true.
Fill all three blanks to write a test that checks if the response header 'Content-Type' includes 'json'.
pm.test('Content-Type is JSON', function () { pm.expect(pm.response.headers.get('[1]')).to.[2]('[3]'); });
The test gets the 'Content-Type' header, then asserts it includes the string 'json' using to.include.