1

I have this kind of response in my API and I want to check that any of the list doesn't contain duplicate values.

[["1100","1100"],["123456"],["123456"],["123456"],["123516","110011"],["123515","110010"],["123514","110009"],["123513","110008"]]

when I use * match response == karate.distinct(response) , it compares all the values and not the values within the inner list like below

[["1100","2200"],["123456"],["123516","110011"],["123515","110010"],["123514","110009"],["123513","110008"]]

I only want to check whether inner list doesn't contain duplicate values, regardless of outer list elements.

This is the parent question https://stackoverflow.com/a/71807872/3664382, but now I'm stuck here -

thisisdude
  • 543
  • 1
  • 7
  • 31

1 Answers1

0

Use match each: https://github.com/karatelabs/karate#match-each

And combine it with a "self" validation: https://github.com/karatelabs/karate#self-validation-expressions

* def fun = function(x){ return karate.match(x, karate.distinct(x)).pass }
* match each response == '#? fun(_)'

I have no idea how people end up with these weird situations. Please read this and I hope it makes sense: https://stackoverflow.com/a/54126724/143475

For completeness, you should take some time to understand JsonPath. This below will "flatten" the entire response into a single array:

* def temp = $response[*][*]
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • generally we don't test these weird situations, but this has to be done in order to validate and automate a defect that came up recently. by the way, I'm not able to connect the dots here. – thisisdude Apr 14 '22 at 11:28
  • @thisisdude I'm unable to explain my answer more. hopefully someone else will help – Peter Thomas Apr 14 '22 at 12:19