Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sadabnepal/mountebank-supertest-api

service virtualisation using mountebank stub and testing using supertest mocha and chai
https://github.com/sadabnepal/mountebank-supertest-api

api-test chai eslint mocha mochawesome mocks moutebank service-virtualization stub supertest

Last synced: 1 day ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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](https://img.shields.io/badge/-NodeJS-%23339933?logo=npm)](https://nodejs.org/en/download/)
[![VSCode](https://img.shields.io/badge/-Visual%20Studio%20Code-%233178C6?logo=visual-studio-code)](https://code.visualstudio.com/download)

### 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](http://www.mbtest.org) as a service virtualization tool, which provides following endpoints
| http call | endpoint | status code | payload |
|-------------|------------------------|-------------|-----------|
| GET | `/users/` | 200 | N/A |
| GET | `/users?page=` | 200 | N/A |
| POST | `/users` | 201 | `{"name": "sadab", "job": "tester" }` |
| PUT | `/users/` | 200 | `{"name": "saqib", "job": "admin" }` |
| POST | `/register` | 200 | `{"email": "[email protected]", "password": "test@123" }` |
| POST | `/login` | 200 | `{"email": "[email protected]", "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
- [x] stub setup
- [x] simple stub
- [x] convert stub to dynamic
- [x] setup test framework
- [x] create simple test
- [x] add different env stage test support
- [x] add lint support for quality code
- [x] fix linting error in js files
- [x] fix default stub response error
- [x] add more stubs to replicate all https call
- [x] cover all test scenarios
- [x] create complex advance stubs (register and login)
- [x] document all endpoints in readme