Skip to content

service virtualisation using mountebank stub and testing using supertest mocha and chai

Notifications You must be signed in to change notification settings

sadabnepal/mountebank-supertest-api

Repository files navigation

Mountebank Supertest mocha stub and test framework

boilerplate project to showcase virtualization of rest services using mountebank and testing rest api using supertest nodejs library with mocha framework

getting started

git clone https://github.com/sadabnepal/mountebank-supertest-api.git
cd mountebank-supertest-api

pre-requisite

NodeJs VSCode

install packages

npm install

start stub [ for ENV=local]

npm start

set env

export ENV=local
         OR
export ENV=dev

base url

local: http://localhost:4545/api 
dev: https://reqres.in/api

run test

npm run test

stub details

The project is using mountebank as a service virtualization tool, which provides following endpoints

http call endpoint status code payload
GET /users/<id> 200 N/A
GET /users?page=<number> 200 N/A
POST /users 201 {"name": "sadab", "job": "tester" }
PUT /users/<id> 200 {"name": "saqib", "job": "admin" }
POST /register 200 {"email": "test@test.com", "password": "test@123" }
POST /login 200 {"email": "test@test.com", "password": "test@123" }

Note: default response will be empty object {} with response code: 404

learning references:

mountebank: http://www.mbtest.org
supertest: http://visionmedia.github
mocha: https://ricostacruz.com/mocha/
mocharc: https://github.com/mochajs/mocha/tree/master/example/config
chai: https://www.chaijs.com
report: https://github.com/adamgruber/mochawesome
eslint: https://eslint.org/docs/latest/use/getting-started
vscode settings: https://code.visualstudio.com/docs/getstarted/settings

TODO

  • stub setup
  • simple stub
  • convert stub to dynamic
  • setup test framework
  • create simple test
  • add different env stage test support
  • add lint support for quality code
  • fix linting error in js files
  • fix default stub response error
  • add more stubs to replicate all https call
  • cover all test scenarios
  • create complex advance stubs (register and login)
  • document all endpoints in readme

About

service virtualisation using mountebank stub and testing using supertest mocha and chai

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published