How to use loop for response from another feature?

Viewed 43

Іssue in the next.

I have a feature response which I check according to schema validation

   {
    "name": "#string",
    "director_first_name": "##string",
    "director_last_name": "##string",
    "director_phone": "##string",
    "director_email": "##string",
    "language": {
        "id": "#uuid",
        "name": "#string",
        "code": "#string? _.length == 2"
    }
   }

Also I have additional feature, which has list of languages

[
    {
        "id": "fde1312f-2ab2-4fdf-a4f3-a7095dd89a4d",
        "name": "English",
        "code": "EN"
    },
    {
        "id": "0d4c6626-1010-4dda-8721-665071ec3b28",
        "name": "Swedish",
        "code": "SV"
    }
] 

And I need to check the next

  1. Need to take response.language.id from first response and check if this id is represented in the second response. In this case I need to call this second feature.
  2. If it is represented, need to match if id, name, code which belong to first reponse the same as in the second response.
1 Answers

You can do this in one line. I leave it as an exercise to you to get the data from a second feature file if you wish.

* def data =
"""
[
    {
        "id": "fde1312f-2ab2-4fdf-a4f3-a7095dd89a4d",
        "name": "English",
        "code": "EN"
    },
    {
        "id": "0d4c6626-1010-4dda-8721-665071ec3b28",
        "name": "Swedish",
        "code": "SV"
    }
]
"""
* def response =
"""
{
    "language": {
        "id": "fde1312f-2ab2-4fdf-a4f3-a7095dd89a4d",
        "name": "English",
        "code": "EN"
    }
}
"""
* match response.language == data.find(x => x.code == response.language.code)

Take some time to read other answers (and follow the links) for ideas: https://stackoverflow.com/a/70055035/143475

Related