SkillAgentSearch skills...

Easymock

An easy way to mock an api using node

Install / Use

/learn @opedro/Easymock
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

easymock

An easy way to mock an api using node

Getting Started

git clone https://github.com/opedro/easymock.git
npm install
node easymock.js

Prerequisites

You only need Node js to run Easymock

How to use

The project gives you a folder called "mocks", in it you'll find examples of mocks that you can edit as you wish. Every "*.esm" file on the "mocks" folder will be read and each one of them will become an interface on your host.

Example: ex1.esm

{
    "method": "get",
    "success":"{'errorCode': '0', 'amigos': [{'nome': 'Macito', 'idade': '22'}]}",
    "fail": "{'errorCode': '1', 'errorMessage': 'exemplo'}",
    "failChance": "20"
}

This esm file will provide a server on locahost/ex1 with "{'errorCode': '0', 'amigos': [{'nome': 'Pavanelli', 'idade': '23'}]}" as the response 80% of the time (based on the "failChance" parameter). 20% of times the response will be "{'errorCode': '1', 'errorMessage': 'exemplo'}", of course.

ex3.esm

{
    "method": "post",
    "parameters": [{"name": "login", "expect": "correto"},
                    {"name": "password", "expect": "12345678"}
                ],
    "success":"{'errorCode': '0', 'perfil': [{'nome': 'Jonas', 'token': 'asd564a&5d56sa%dsa54$a5s64d'}]}",
    "fail": "{'errorCode': '1', 'errorMessage': 'exemplo'}",
    "failChance": "10"
}

This esm file will provide a server on localhost/ex3 with "{'errorCode': '0', 'perfil': [{'nome': 'Jonas', 'token': 'asd564a&5d56sa%dsa54$a5s64d'}]}" as the response ONLY WHEN the body was "{"login": "correto", "password":"1234565645478"}". Any incorrect data will make the return to be "{'errorCode': '1', 'errorMessage': 'exemplo'}". obs: The correct body will still fail 10% of the times.

Authors

  • Pedro Ruiz - Initial work - opedro

I deserve a coffee

Donate R$ 3,00 https://bit.ly/2u5e6Wn

Related Skills

View on GitHub
GitHub Stars6
CategoryDevelopment
Updated5y ago
Forks1

Languages

JavaScript

Security Score

55/100

Audited on Jun 21, 2020

No findings