This question is resulting from a previous question here
Lets says our implemented server v1 and v2 response looks as follows
* def v1Response = { id: "1", name: "awesome" }
* def v2Response = { id: "2", name: "awesome", value: "karate" }
Similarly we define the client schema for v1 and v2 like as follows
* def v1Schema = { id: "#string", name: "#string }
* def v2Schema = { id: "#string", name: "#string, value: "#string" }
From the above given data, all I want is to test following three cases in a single generic line and they must pass
1. * match v1Response == v1Schema
2. * match v2Response == v2Schema
3. * match v2Response contains v1Schema
using a single generic line as follows
* match response ==/contains schema <--- should be able to test all above three cases above and they must pass.
See my proposed suggestion in previous question for maybe possible ways to achieve this.
I have already tried the solution noted in previous question using karate.filterKeys(), however the third case will fail because it focuses on filtering the keys not the comparison itself so the below last line will not be able to test all three cases above.
* def response = { id: "2", name: "awesome", value: "karate" }
* def schema = { id: "#string", name: "#string" }
* match response == karate.filterKeys(schema, response) <--- This will fail
For an accepted answer all three case must pass
Take a look at contains
:
* def schemas =
"""
{
v1: { id: "#string", name: "#string" },
v2: { id: "#string", name: "#string", value: "#string" }
}
"""
* def env = 'v1'
* def response = { id: "1", name: "awesome" }
* match response contains karate.filterKeys(schemas[env], response)
* def response = { id: "2", name: "awesome", value: "karate" }
* match response contains karate.filterKeys(schemas[env], response)
* def env = 'v2'
* def response = { id: "1", name: "awesome" }
* match response contains karate.filterKeys(schemas[env], response)
* def response = { id: "2", name: "awesome", value: "karate" }
* match response contains karate.filterKeys(schemas[env], response)