根据初始值、更新值和预期值表评估响应值

问题描述 投票:0回答:1

我们希望创建一个参考表,我们可以用它来根据初始值(从之前的请求中提取的 currentStatus)和更新值(应用了更新的 serviceLevel)来验证结果(应用更新后的 opStatus)。 虽然我们可以创建大量 if 语句,但我希望有一种更有效的方法来评估响应。

    * table data
    | currentStatus              | serviceLevel | opStatus          |
    | Connected                  | basicService | Suspended         |
    | Connected                  | noService    | Suspended         |
    | Connected                  | fullService  | Connected         |
    | Offline                    | basicService | Offline_Suspended |
    | Offline                    | noService    | Offline_Suspended |
    | Offline                    | fullService  | Offline           |
    | Suspended                  | fullService  | Connected         |
    | Suspended                  | basicService | Suspended         |
    | Suspended                  | noService    | Suspended         |
    | Connected                  | fullService  | Connected         |
    | Connected                  | basicService | Suspended         |
    | Connected                  | noService    | Suspended         |
    | Offline_Suspended          | fullService  | Offline           |
    | Offline_Suspended          | basicService | Offline_Suspended |
    | Offline_Suspended          | noService    | Offline_Suspended |
    | Pending_Suspension         | basicService | Suspended         |
    | Pending_Suspension         | noService    | Suspended         |
    | Pending_Suspension         | fullService  | Connected         |
    | Offline_Pending_Suspension | basicService | Offline_Suspended |
    | Offline_Pending_Suspension | noService    | Offline_Suspended |
    | Offline_Pending_Suspension | fullService  | Offline           |

我们正在尝试比较的回复示例摘录

  "service": {
    "alpha": {
      "serviceCode": [
        "123456",
        "abcdef"
      ],
      "baseServiceCode": "baseServiceCode",
      "category": "Internet",
      "opStatus": "CONNECTED",
      "status": "ACTIVE",
      "resources": [
        {
          "model": "TestModel",
          "ssid": "SpectrumSetup-TestModel",
          "serial": "FAKESERIALNUM00",
          "opStatus": "CONNECTED",
          "admStatus": "ACTIVE",
          "macAddr": "0011223344ff",
          "resourceId": "0011223344ff"
        }
      ]
    }
karate
1个回答
0
投票

这是一种方法,您需要的所有概念都已捕获。核心概念是编写一个能够循环所有组合并找到正确组合的函数。请记住,在幕后,

data
是一个 JSON 数组,您可以
* print data
查看它。然后应用普通的 JS 概念,如果需要,可以寻求熟悉 JS 的人的帮助。

* table data
| arg1 | arg2 | result |
| 'a'  | 'b'  | 1      |
| 'a'  | 'c'  | 2      |

* def lookup = function(v1, v2){ return data.find(x => x.arg1 == v1 && x.arg2 == v2) }
# test if our custom lookup function works
# * match lookup('a', 'b') == { arg1: 'a', arg2: 'b', result: 1 }

* def currentStatus = 'a'
* def response = { serviceLevel: 'c', opStatus: 2 }
* def expected = lookup(currentStatus, response.serviceLevel)
* match response.opStatus == expected.result

为了其他可能看到此答案的人的利益,我不建议向此类测试添加逻辑,请参阅:https://stackoverflow.com/a/54126724/143475

© www.soinside.com 2019 - 2024. All rights reserved.