How to test each date field in the array response using Karate

女生的网名这么多〃 提交于 2019-12-02 03:37:38

In many ways, here is one. Refactoring this code to be cleaner is homework for you :P

* def toTime1 =
    """
    function(s) {
      var SimpleDateFormat = Java.type('java.text.SimpleDateFormat');
      var sdf = new SimpleDateFormat("yyyy-MM-dd");
      return sdf.parse(s).time           
    }
    """
* def toTime2 =
    """
    function(s) {
      var SimpleDateFormat = Java.type('java.text.SimpleDateFormat');
      var sdf = new SimpleDateFormat("dd-MM-yyyy");
      return sdf.parse(s).time           
    }
    """  
* def input = toTime2("24-11-2018")
* def today = new java.util.Date().time
* def isValid1 = function(x){ return toTime1(x) < today  }
* def isValid2 = function(x){ return toTime2(x) < input  }

* def response = [{ date1: "2018-12-23", date2: "23-11-2018" }, { date1: "2018-12-20", date2: "23-11-2018" }]
* match each response == { date1: '#? isValid1(_)', date2: '#? isValid2(_)' }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!