How can emulate behaviour on mock?


#1

Hi,

I still evaluating Stoplight for my company as part of the assessment.

I think it’s clear to me how to mock, and create authentication, but I still struggled (sorry if I’m asking something quite obvious) on mocking behaviours. We’re implemeting an extremely easy business case of an API which returns code country from a country name and a country name from a code.

These are a few scenarios I’d like to write using Stoplight:

Scenario Outline: Getting a Country Name from a Country Code
Given a Country Code “CountryCode”
When I request Country Name
Then the result should be “CountryName”
Examples:
| CountryName | CountryCode |
| India | IN |
| Spain | ES |
| United States | US |

I’ve been able, by configuring examples, to return following model:

{
“countryname”: “IN”,
“countrycode”: “India”,
“”: {
“message”: {
“message”: “Found”
}
}
}

However, in order to model such scenarios, I would need, to send a code “US” and return “United States”.

What I’ve read is I can use javascript to model mock behaviour, so I could keep a map of codes and countries and my scenario could work fine.

I’ve gone through the documentation, but I’m a little confuse about this point. Could you suggest me a point to start modelling behaviours?
FYI, I’m working behind a corporate proxy, so I cannot use local prism (unless cheating IT Security policies with ngrok or something like that).

Thanks