https://github.com/phenax/yaatt
Easy tests and documentation for your http api
https://github.com/phenax/yaatt
api documentation-generator http nodejs test-framework testing-tools
Last synced: about 1 year ago
JSON representation
Easy tests and documentation for your http api
- Host: GitHub
- URL: https://github.com/phenax/yaatt
- Owner: phenax
- License: mit
- Created: 2018-06-24T15:17:02.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-22T12:14:31.000Z (over 7 years ago)
- Last Synced: 2025-02-16T21:18:52.747Z (about 1 year ago)
- Topics: api, documentation-generator, http, nodejs, test-framework, testing-tools
- Language: JavaScript
- Size: 359 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Yet another api testing toolkit
Easy tests and documentation for your http api
[](https://www.npmjs.com/org/yaatt)
[](https://circleci.com/gh/phenax/yaatt)
[](https://codecov.io/gh/phenax/yaatt)
[](https://github.com/phenax/yaatt/blob/master/LICENSE)
## Install
Add it globally or locally
```
sudo yarn global add @yaatt/cli
```
OR if you are barbaric,
```
sudo npm i -g @yaatt/cli
```
## Usage
### Creating a test suite
* Create a file `your-test.js`. It is reccommended that you follow a specific directory structure for these tests.
* The general format of a test suite is as follows
```js
module.exports = {
label: 'Httpbin Get call', // A label for your test suite
request: {
url: 'http://httpbin.org/get', // API endpoint
method: 'get', // HTTP method
},
tests: {
'should do stuff': { /* Test case */ },
},
};
```
### Write your first test
* A simple test case for getting user information would look like this
```js
module.exports = {
label: 'Get user data',
request: {
url: 'https://some-domain.com/api/user',
method: 'get',
},
tests: {
'should fetch Waluigi\'s information from api': {
request: {
params: { // Query parameters
userid: 'ZnVjayB5b3U=',
},
},
onResponse: response =>
response
.matchProp([ 'result', 'id' ], 'ZnVjayB5b3U=') // Check if user id is correct
.matchProp([ 'result', 'name' ], 'Waluigi') // Check if the name is correct
.assert(({ data, headers, status }) => {
// Manual test cases go here
})
},
},
};
```
### Define dependencies
* If your api call depends on another api call (for example user authentication), you can define dependencies in your test suite which will be called to provide data to your test cases.
```js
module.exports = {
label: 'Http get call after authentication (dependency)',
request: {
url: 'https://some-domain.com/api/user',
method: 'get',
},
dependencies: {
auth: {
request: {
url: 'https://some-domain.com/api/user/login',
method: 'post',
data: {
email: 'akshaynair1597@gmail.com',
password: 'my_pass1298qwbtgdhsj',
},
},
onResponse: r => r.get([ 'user' ]),
}
},
tests: {
'should have uid set correctly as passed from the dependency': {
request: {
_: ({ dependencies }) => ({
params: {
uid: dependencies.auth.uid,
},
}),
},
onResponse: response =>
response
.matchProp([ 'user', 'name' ], 'Akshay Nair')
},
},
};
```
### Running your test suite
#### Just cli
```
yaatt ./path/to/yourtestsuite1.suite.js ./path/to/yourtestsuite2.suite.js
```
You can even use glob paths
```
yaatt ./path/**/*.test.js
```
#### Using config file
```
yaatt -c config.yaatt.json
```
And in your `config.yaatt.json` -
```json
{
"testSuites": [ "./path/**/*.test.js" ],
}
```