断言大动态响应

Asserting Against Large Dynamic Response

我有一个非常大的响应数组,我想对其进行断言,但不知道顺序。我有一个具有预期响应值的变量,因此我可以进行一次巨大的比较,但我无法加载整个响应并将其与整个预期响应变量同时进行比较。

* def obligationsQuery = Java.type("tests.account.sql.Obligations").getObligations(division, account)
    * def getObligations = db.readRows(obligationsQuery)

    Given path "account", "v1", "accounts", systemId, "obligations"
      And header api-key = gatewayKey
    When method GET
    Then status 200
      And match $.data != null
      And match $.data[*].transactionType contains any "<transactionTypeResponse>"
      And match $.data[*] contains only getObligations

    Examples:
      | description | transactionType | transactionTypeResponse |
      | Invoice     | 001             | invoice

我得到的错误是:

get_obligations_collection.feature:49 - path: $.data[*][*], actual: [{"object1"}, {"object2"}, {"etc"}], expected: {"object1"}, reason: actual value does not contain expected

我也尝试过: And match each $.data[*] contains only getObligations 但后来我得到:

get_obligations_collection.feature:49 - path: $[0], actual: [{"object1"}, expected: [{"object1"}, {"object2"}, {"etc"}, reason: actual value is not list-like

我假设 $.data 是一个 JSON 数组,因此无需使用 json-path 通过调用 $.data[*] 再次将数据放入另一个数组中。

所以,

And match $.data contains only getObligations

应该可以。

如果这仍然无效,请提供一些适当的 responsegetObligations 值以进一步调查。

我假设 contains only 会显示我的变量的完整值,但聪明的是,它只显示与 api 响应对象不匹配的对象。能够通过更简单的断言来验证这一点,然后检查错误消息发现 ID 缺少 API 添加的填充,但数据库没有。

像往常一样,只需更仔细地查看返回的数据即可提供简单的解释。