计算Frisby中对象中数组中的对象

时间:2016-10-20 13:57:47

标签: node.js automated-tests frisby.js

我开始学习FrisbyJS并尝试创建一些断言。

我得到一个看起来像这样的json

[
    {
        "articles": [
            {
                "article": "123-123002",
                "updated": "2016-10-20T14:57:25",
                "sourced balance": [],
                "balance": "50.00"
            },
            {
                "article": "100-123001",
                "updated": "2016-10-20T14:41:36",
                "sourced balance": [],
                "balance": "10.00"
            }
        ],
        "DistrictID": [],
        "WarehouseID": "SebastiansWarehouse",
        "SourceID": "1234",
        "City": "Stockholm",
        "WarehouseName": "Sebastians Warehouse",
        "WarehouseType": "STORE"
    }
]

我想:  1.计算文章对象的数量  2.验证文章数组中的数字X是否具有值为" 123-123002"

的变量

我怎样才能在弗里斯比做到这一点?

我的代码目前是:

var frisby = require('frisby');

frisby.create('Mekonomen RIF1')
  .get('https://10.254.8.67:9443/INTERSHOP/rest/WFS/Mekonomen-MekB2BSE-Site/-/availability/sources/1234/warehouses/SebastiansWarehouse/products/',{ strictSSL: false})
  .expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.expectJSON('?',{
        articles: [],
        DistrictID: [],
        WarehouseID: "SebastiansWarehouse",
        SourceID: '1234',
        City: "Stockholm",
        WarehouseName: "Sebastians Warehouse",
        WarehouseType: "STORE"
    }
)
.expectJSON('?.articles',{
        articles: [],
        DistrictID: [],
        WarehouseID: "SebastiansWarehouse",
        SourceID: '1234',
        City: "Stockholm",
        WarehouseName: "Sebastians Warehouse",
        WarehouseType: "STORE"
    }
)
.expectMaxResponseTime(500)
.toss();

1 个答案:

答案 0 :(得分:1)

你可以包括

.afterJSON(json){ //json.articles can be asserted here //some more assertion on the response }

将解析响应并将其作为参数发送,可以使用简单的javascript条件,语句,循环等来声明它。