Reputation: 139
I am having newb trouble validating nested JSON with arrays. I have a GraphQL query that looks like this, it is the simplest of the ones I have. I have changed the data as it is real production data but obv you can get the idea. I realize from previous chats with @petersmith that * match results contains is a great way to go and I have also tried reading from a .json file but I must be formatting the json file wrong or something is off because I get error messages about javascript evaluation failed or no data found, etc. I really just want to validate the datatypes, that the fields exist at all (claimNumber, claimStatus, totalPatientResponsibility, providerName, and memberName) and I want to pass in an invalid and/or null memberNumber and watch how it reacts. These seem so simple but I have only done it with REST and Cucumber using Ruby so now I seem to be having trouble. Thanks!
{
getClaimHeadersList(memberNumber:"1111111111") {
claimNumber
claimStatus
totalPatientResponsibility
providerName
memberName
}
}
The response back is the following:
{
"data": {
"getClaimHeadersList": [
{
"claimNumber": "01-010111-111-11",
"claimStatus": "Pended",
"totalPatientResponsibility": 0.00,
"providerName": "LastName, FirstName",
"memberName": "LastName, FirstName M"
},
{
"claimNumber": "01-010111-111-11",
"claimStatus": "Pended",
"totalPatientResponsibility": 0.00,
"providerName": "LastName, FirstName",
"memberName": "LastName, FirstName M"
},
{
"claimNumber": "01-010111-111-11",
"claimStatus": "Pended",
"totalPatientResponsibility": 0.00,
"providerName": "LastName, FirstName",
"memberName": "LastName, FirstName M"
},
{
"claimNumber": "01-010111-111-11",
"claimStatus": "Posted",
"totalPatientResponsibility": 0.00,
"providerName": "LastName, FirstName",
"memberName": "LastName, FirstName M"
},
{
"claimNumber": "01-010111-111-11",
"claimStatus": "Posted",
"totalPatientResponsibility": 0.00,
"providerName": "LastName, FirstName",
"memberName": "LastName, FirstName M"
},
{
"claimNumber": "01-010111-111-11",
"claimStatus": "Posted",
"totalPatientResponsibility": 0.00,
"providerName": "LastName, FirstName",
"memberName": "LastName, FirstName M"
},
{
"claimNumber": "01-010111-111-11",
"claimStatus": "Posted",
"totalPatientResponsibility": 0.00,
"providerName": "LastName, FirstName",
"memberName": "LastName, FirstName M"
},
{
"claimNumber": "01-010111-111-11",
"claimStatus": "Posted",
"totalPatientResponsibility": 0.00,
"providerName": "LastName, FirstName",
"memberName": "LastName, FirstName M"
},
{
"claimNumber": "01-010111-111-11",
"claimStatus": "Posted",
"totalPatientResponsibility": 0.00,
"providerName": "LastName, FirstName",
"memberName": "LastName, FirstName M"
},
{
"claimNumber": "01-010111-111-11",
"claimStatus": "Posted",
"totalPatientResponsibility": 0.00,
"providerName": "LastName, FirstName",
"memberName": "LastName, FirstName M"
}
]
}
}
Upvotes: 1
Views: 725
Reputation: 58058
You can paste the entire section below into a fresh scenario and see it work.
* def response =
"""
{
"data":{
"getClaimHeadersList":[
{
"claimNumber":"01-010111-111-11",
"claimStatus":"Pended",
"totalPatientResponsibility":0.00,
"providerName":"LastName, FirstName",
"memberName":"LastName, FirstName M"
},
{
"claimNumber":"01-010111-111-11",
"claimStatus":"Pended",
"totalPatientResponsibility":0.00,
"providerName":"LastName, FirstName",
"memberName":"LastName, FirstName M"
},
{
"claimNumber":"01-010111-111-11",
"claimStatus":"Pended",
"totalPatientResponsibility":0.00,
"providerName":"LastName, FirstName",
"memberName":"LastName, FirstName M"
},
{
"claimNumber":"01-010111-111-11",
"claimStatus":"Posted",
"totalPatientResponsibility":0.00,
"providerName":"LastName, FirstName",
"memberName":"LastName, FirstName M"
},
{
"claimNumber":"01-010111-111-11",
"claimStatus":"Posted",
"totalPatientResponsibility":0.00,
"providerName":"LastName, FirstName",
"memberName":"LastName, FirstName M"
},
{
"claimNumber":"01-010111-111-11",
"claimStatus":"Posted",
"totalPatientResponsibility":0.00,
"providerName":"LastName, FirstName",
"memberName":"LastName, FirstName M"
},
{
"claimNumber":"01-010111-111-11",
"claimStatus":"Posted",
"totalPatientResponsibility":0.00,
"providerName":"LastName, FirstName",
"memberName":"LastName, FirstName M"
},
{
"claimNumber":"01-010111-111-11",
"claimStatus":"Posted",
"totalPatientResponsibility":0.00,
"providerName":"LastName, FirstName",
"memberName":"LastName, FirstName M"
},
{
"claimNumber":"01-010111-111-11",
"claimStatus":"Posted",
"totalPatientResponsibility":0.00,
"providerName":"LastName, FirstName",
"memberName":"LastName, FirstName M"
},
{
"claimNumber":"01-010111-111-11",
"claimStatus":"Posted",
"totalPatientResponsibility":0.00,
"providerName":"LastName, FirstName",
"memberName":"LastName, FirstName M"
}
]
}
}
"""
# get only the claims part out of the response as an array
* def claims = get[0] response $..getClaimHeadersList
* print claims
# assert that there are exactly 10 claims
* match claims == '#[10]'
# assert that each claim has the exact values. note the special handling of 'claimStatus'
* match each claims == { "claimNumber":"01-010111-111-11", "claimStatus":"#? _ == 'Pended' || _ == 'Posted'", "totalPatientResponsibility":0.00, "providerName":"LastName, FirstName", "memberName":"LastName, FirstName M" }
# define a reusable 'schema' for the claim object, includes example of regex validation
* def claimSchema = { claimNumber: '#regex [0-1-]*', claimStatus: '#string', totalPatientResponsibility: '#number', providerName: '#string', memberName: '#string' }
# assert that each claim has all the keys expected and in the format expected
* match each claims == claimSchema
Upvotes: 1