空手道 - GraphQL - 使用数组验证嵌套 JSON
Karate - GraphQL - Validating nested JSON with arrays
我在使用数组验证嵌套 JSON 时遇到了新问题。我有一个看起来像这样的 GraphQL 查询,它是我拥有的最简单的查询。我已经更改了数据,因为它是真实的生产数据,但你可以明白这一点。我从之前与@petersmith 的聊天中意识到 * 匹配结果包含是一个很好的方法,我也尝试过从 .json 文件中读取,但我必须格式化 json 文件错误或有什么问题关闭,因为我收到有关 javascript 评估失败或未找到数据等的错误消息。我真的只想验证数据类型,字段是否存在(claimNumber、claimStatus、totalPatientResponsibility、providerName 和 memberName),我想传递一个无效的 and/or null memberNumber 并观察它的反应。这些看起来很简单,但我只使用 Ruby 使用 REST 和 Cucumber 完成过,所以现在我似乎遇到了麻烦。谢谢!
{
getClaimHeadersList(memberNumber:"1111111111") {
claimNumber
claimStatus
totalPatientResponsibility
providerName
memberName
}
}
返回的响应如下:
{
"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"
}
]
}
}
您可以将下面的整个部分粘贴到一个新的场景中,看看它是否有效。
* 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
我在使用数组验证嵌套 JSON 时遇到了新问题。我有一个看起来像这样的 GraphQL 查询,它是我拥有的最简单的查询。我已经更改了数据,因为它是真实的生产数据,但你可以明白这一点。我从之前与@petersmith 的聊天中意识到 * 匹配结果包含是一个很好的方法,我也尝试过从 .json 文件中读取,但我必须格式化 json 文件错误或有什么问题关闭,因为我收到有关 javascript 评估失败或未找到数据等的错误消息。我真的只想验证数据类型,字段是否存在(claimNumber、claimStatus、totalPatientResponsibility、providerName 和 memberName),我想传递一个无效的 and/or null memberNumber 并观察它的反应。这些看起来很简单,但我只使用 Ruby 使用 REST 和 Cucumber 完成过,所以现在我似乎遇到了麻烦。谢谢!
{
getClaimHeadersList(memberNumber:"1111111111") {
claimNumber
claimStatus
totalPatientResponsibility
providerName
memberName
}
}
返回的响应如下:
{
"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"
}
]
}
}
您可以将下面的整个部分粘贴到一个新的场景中,看看它是否有效。
* 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