Forum Discussion

shiva1020243's avatar
shiva1020243
Occasional Contributor
3 years ago

Assertion failing when validation with previous month's data

Hi Team,

Can somebody please help me validate this? I'm really getting confused on how to validate with the previous month's data.

 

API1: this will return all users data 
{
"UserInfo" : [
{
"userId" : "5733542",
"userActivities" : {
"Running" : true, //this will be true because API2 noofrunnings is > 0 of current month (in this case Dec 2021)
"Squats" : false, //this will be false because API2 noofsquats is = 0 of previous month (in this case Nov 2021)
"Eating" : false //this will be false because API2 noofeating is = 0 of previous month (in this case Nov 2021)
}
},
{
"userId" : "9345982",
"userActivities" : {
"Running" : false, //this will be false because API2 noofrunnings is = 0 of current month (in this case Dec 2021)
"Squats" : true, //this will be true because API2 noofsquats is > 0 of previous month (in this case Nov 2021)
"Eating" : true //this will be true because API2 noofeating is > 0 of previous month (in this case Nov 2021)
}
},
]
}

API2: This will return data of each userID in every loop 
Response of user = 5733542
{
"userId" : "5733542",
"userInfo" :[
{
"month" : "Dec 2021",
"noofrunnings": "1"
"noofsquats": "1"
"noofeating": "1"

}
{
"month" : "Nov 2021",
"noofrunnings": "1"
"noofsquats": "0"
"noofeating": "0"

}

]
}
Response of user = 9345982
{
"userId" : "9345982",
"userInfo" :[
{
"month" : "Dec 2021",
"noofrunnings": "0"
"noofsquats": "1"
"noofeating": "1"

}
{
"month" : "Nov 2021",
"noofrunnings": "1"
"noofsquats": "1"
"noofeating": "1"
}
]
}

 


I'm trying to validate both these two API's like for 1st iteration of API2 i've to validate against the 1st API, i'm trying this since 12 hrs., but all my assertions are failing. Can someone please help me?

 

my pseudo code is like this,

wrote a switch case which will return month + year 

validating API2's month vs my switch case month 

here i'm failing to write the if, else if, statements and if noofsquats > 0, if noofsquats =0 , similarily for noofrunnings, noofeatings

 

 

Thanks in advance!