I want to dynamically validate the value of JSON request parameters without the use of switch statement
I tried the code below which works fine but it is not optimized as I have to create a case for each field I am validating.
If there a way to achieve the same result without using switch statement
if(responsecode == 200){
const cfields = ["author", "title", "genre", "price"];
cfields.forEach(myFunction);
function myFunction(item) {
var reqprop = item;
pm.test("Verify that "+reqprop+" is not empty", function () {
switch(reqprop) {
case'author':
pm.expect(requestObjectprop.author, "Request is successful with a null '"+reqprop+"' ").and.not.be.empty;
//pm.expect(contentValue).to.be.a('string').and.not.be.empty
break;
case 'title':
pm.expect(requestObjectprop.title, "Request is successful with a null '"+reqprop+"' ").and.not.be.empty;
break;
}
});
}
}
Thank you
Via Active questions tagged javascript - Stack Overflow https://ift.tt/TvU56LY
Comments
Post a Comment