I have couple of issues as below. I tried couple of times but it is not working. I would appreciate your help and please also recommend the best way to get rid of the errors.
JSON response
[
{
“studentName”: “Mike Tucker”,
“startDate”: “2011-08-08 12:12:16.257”,
“isActive”: “true”,
“statusDescription”: “Pass”,
“studentId”: “39524”
},
{
“studentName”: “James Brown”,
“startDate”: “2012-11-06 12:15:12.72”,
“isActive”: “true”,
“courseDescription”: “Fail”,
“studentId”: “52412”
}
]
I would like to know the ‘courseDescription’ value is either “Pass” or “Fail” from the above json output
I tried the following script but it is not working
var jsonData = pm.response.json();
var courseDescription =[‘Pass’,‘Fail’];
pm.test(“courseDescription’ is working as expected”,()=>{
pm.expect(‘Active)’).to.be.oneOf(‘courseDescription’));
});
Error : AssertionError: expected ‘courseDescription’ to be an array
I would like to know the date format above output is YYYY-MM-DD with the script below for all json objects
I tried the script below and it is not working
var josnData= pm.response.json();
var moment = require(‘moment’);
var startDate= ‘YYYY-MM-DD’;
pm.test(“Checking date format”, () =>
{
pm.expect(jsonData.data.startDate).to.include(moment).format(startDate)});
Error : ReferenceError: jsonData is not defined
I would like to check the studentID is an integer for all the json objects and length of it .i.e in this case stuedntID length is 5 digit. I tried the following script ,please let me know the piece I am missing
AssertionError: expected undefined to be a number
var data = pm.response.json();
pm.test(“studentID is integer and be below 6 digit”, function () {
pm.expect(data.studentID).to.be.a(“number”);
pm.expect(data.studentID).be.below(6);
});
Error : AssertionError: expected undefined to be a number
I would like to check details of studentID # 52412 from all the json output above. I tried the script below and need your suggestions to work
var jsonData = pm.response.json();
pm.test(‘studentID 52412’, function() {
pm.expect(jsonData).to.have.property(jsonData.data.studentID==52412’);
});
Please also refer any good json libraries that are helpful for me to learn for future.
I’ve already tried: