空手道 - GraphQL - 如何验证模式,然后验证响应



我终于让空手道使用 GraphQL 并能够验证一个简单的 200 响应,尽管我在验证模式和响应时遇到了问题。我是超级新人,所以我很抱歉(不是程序员,只是测试人员(。 我想验证架构是否正确,例如结果是否仅返回(提供者ID,名字,姓氏等(,而不是数据。 然后,我想单独验证数据本身。我不明白的另一件事是如何传入数据,例如我可以更改纬度、经度、最大距离等并将其设置为变量。 我在示例中看到"name"如何用作变量,但这些似乎以不同的方式传入,所以我不确定该怎么做。 很抱歉不知道这么多,感谢您的帮助。

Scenario: simple graphql request
    #Verify 200 response status returned    
    Given text query =
        """
     {
                    Results: getSearchResults(searchLatitude:"38.942833", 
    searchLongitude: "-119.984549", providerType: "Primary Care Physicians", 
    sortBy: "distance", maxDistance:"600",skip: 0, take: 10) {
                        providerID
                        firstName 
                        lastName
                        mI
                        title
                        name
                        nameLFMT
                        status
                        specialties
                        locations
                        institutions
                        acceptNewPatient
                        imageUri
                        distanceToNearest
                    }
    } 
        """
    And request { query: '#(query)' }
    When method post
    Then status 200
    # pretty print the response
    * print 'response:', response

    # the '..' wildcard is useful for traversing deeply nested parts of the 
    json
    * def results = get[0] response..Results
    * match results contains { ProviderId: 520, firstName: 'Richard', 
lastName: 'Botto' }

看看replace关键字。

然后试试这个:

Given text query =
    """
 {
                Results: getSearchResults(searchLatitude:"<searchLatitude>", 
searchLongitude: "<searchLongitude>", providerType: "Primary Care Physicians", 
sortBy: "distance", maxDistance:"600",skip: 0, take: 10) {
                    providerID
                    firstName 
                    lastName
                    mI
                    title
                    name
                    nameLFMT
                    status
                    specialties
                    locations
                    institutions
                    acceptNewPatient
                    imageUri
                    distanceToNearest
                }
} 
    """
* replace query.searchLatitude = '38.942833'
* replace query.searchLongitude = '-119.984549'

获得此工作后,请在文档中搜索"graphql"以获取更多想法。

对于匹配架构,应该很容易:

* match results contains { ProviderId: '#number', firstName: '#string', lastName: '#string' }

该文档有一整节关于模糊匹配。

最新更新