Git Product home page Git Product logo

easymock's Introduction

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

easymock's People

Contributors

opedro avatar mademateuslourencao avatar madematheuspavanelli avatar madepedrobeani avatar

Stargazers

Gabriel Vieira avatar Rudson Lima avatar Matheus Pavanelli avatar Paulo Gaspar Sena do Vale avatar Alex Aguiar avatar Luis Felipe A.S. avatar

Watchers

Paulo Gaspar Sena do Vale avatar  avatar Luis Felipe A.S. avatar Alex Aguiar avatar

Forkers

pbeani

easymock's Issues

Check parameters

Still isn't possible to insert parameters of an interface on .esm files.

post method

Isn't possible to create an interface using post method

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.