Complete the code to validate the response status code is 200.
pm.test('Status code is 200', function () { pm.response.to.have.status([1]); });
The status code 200 means the request was successful. We check this with pm.response.to.have.status(200).
Complete the code to check if the JSON response has a property named 'userId'.
pm.test('Response has userId', function () { pm.expect(pm.response.json()).to.have.property([1]); });
We check if the JSON response has the property userId by passing its name as a string to have.property.
Fix the error in the code to correctly validate the response JSON schema.
const schema = [1]; pm.test('Schema is valid', function () { pm.response.to.have.jsonSchema(schema); });
The schema must be a valid JavaScript object describing the JSON structure. Option D is correct syntax.
Fill both blanks to check that the response JSON has a 'name' property of type string.
const schema = { type: 'object', properties: { name: { type: [1] } }, required: [[2]] };
pm.test('Name property is string', function () { pm.response.to.have.jsonSchema(schema); });The property 'name' should be of type 'string' and must be required, so the required array includes 'name'.
Fill all three blanks to validate a response JSON with 'id' as number, 'email' as string, and both required.
const schema = {
type: 'object',
properties: {
id: { type: [1] },
email: { type: [2] }
},
required: [[3]]
};
pm.test('Validate id and email', function () {
pm.response.to.have.jsonSchema(schema);
});The 'id' property type is 'number', 'email' is 'string', and both are required, so the required array includes both 'id' and 'email' as strings.