Karate-GraphQL-使用数组验证嵌套JSON

Karate-GraphQL-使用数组验证嵌套JSON,json,automated-tests,cucumber,graphql,karate,Json,Automated Tests,Cucumber,Graphql,Karate,我在用数组验证嵌套JSON时遇到了新问题。我有一个类似这样的GraphQL查询,它是我所拥有的查询中最简单的一个。我已经改变了数据,因为它是真实的生产数据,但obv你可以得到的想法。从之前与@petersmith的聊天中,我意识到*match results contains是一个很好的方法,我也尝试了从.json文件中读取,但我必须将json文件格式化错误,或者出现了一些问题,因为我收到了关于javascript评估失败或未找到数据等的错误消息。我真的只想验证数据类型,字段存在(claimNu

我在用数组验证嵌套JSON时遇到了新问题。我有一个类似这样的GraphQL查询,它是我所拥有的查询中最简单的一个。我已经改变了数据,因为它是真实的生产数据,但obv你可以得到的想法。从之前与@petersmith的聊天中,我意识到*match results contains是一个很好的方法,我也尝试了从.json文件中读取,但我必须将json文件格式化错误,或者出现了一些问题,因为我收到了关于javascript评估失败或未找到数据等的错误消息。我真的只想验证数据类型,字段存在(claimNumber、claimStatus、totalPatientResponsibility、providerName和memberName),我希望传入无效和/或空memberNumber并观察其反应。这些看起来很简单,但我只使用了REST和Cucumber,使用Ruby,所以现在我似乎遇到了麻烦。谢谢

    {

      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

完美@PeterThomas!我想我正在慢慢了解如何用你的例子做到这一点。我们昨晚也工作了,这也起了作用,所以这很有帮助#验证架构和数据类型*是否匹配每个$response.data.getClaimHeaderList包含“{”claimNumber:“#regex[0-9]{2}-[0-9]{6}-[0-9]{3}-[0-9]{2}”,“claimStatus:“#regex(Pended | Posted)”,“totalPatientResponsibility:“#number”,“providerName:“#string',“memberName:#字符串”} """