Hi everyone, I'd like to understand whether it's p...
# general
g
Hi everyone, I'd like to understand whether it's possible to write a test that will check for the uniqueness of a data field for each item in an array. For instance, if my response is
Copy code
{
  "items": [
    {
      "id": 1
    },
    {
      "id": 2
    }
  ]
}
is there way to write a test that will check that the values of "id" is unique for each item? Many thanks!
b
Maybe there is (although I don't think so, I've never seen something like this) but moreover, I don't think a check like this is the responsibility of a contract test, as you're testing the implementation of a provider, not communication between a consumer and a provider. So, ideally the provider should verify this, but if they can't / won't / don't, you can use any general-purpose API testing client to extract all the IDs into a list, remove duplicates and see if the new list is the same length..
g
thank you for your help. Looks like a conversation with the provider is needed ๐Ÿ™‚
๐Ÿงก 1