Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
Feature/user mock data (#119)
Browse files Browse the repository at this point in the history
* Add input test data to configuration

* Moved helpers to /lib/helpers.js
* Added printJSON helper
* Modified testGenResponse to check to see if there is inputTesting
defined for that particular path:operation:response
* Modified templates for put, post, and patch to check for inputs
  • Loading branch information
Remco75 authored and noahdietz committed Oct 13, 2016
1 parent 9faa113 commit ef6deb1
Show file tree
Hide file tree
Showing 23 changed files with 750 additions and 234 deletions.
53 changes: 49 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,63 @@ stt.testGen(swagger, config);

`swagger-test-templates` module exports a function with following arguments and return values:

#### Arguments
### Arguments
* **`assertionFormat`** *required*: One of `should`, `expect` or `assert`. Choose which assertion method should be used in output test code.
* **`testModule`** *required*: One of `supertest` or `request`. Choose between direct API calls (`request`) vs. programatic access to your API (`supertest`).
* **`pathNames`** *required*: List of path names available in your Swagger API spec used to generate tests for. Empty array leads to **all paths**.
* **`pathName`** *required*: List of path names available in your Swagger API spec used to generate tests for. Empty array leads to **all paths**.
* **`statusCodes`** *optional* Array with status codes to generate tests for. Useful for generating only happy-flow tests. Excluding this param will generate tests for all responses.
* **`loadTest`** *optional*: List of objects info in your Swagger API spec used to generate stress tests. If specify, pathName & operation are **required**. Optional fields requests defaults to `1000`, concurrent defaults to `100`.
* **`maxLen`** *optional*: Maximum line length. Defaults to `80`.
* **`maxLen`** *optional*: Maximum line length. If set to `-1`, descriptions will not be truncated. Defaults to `80`.
* **`pathParams`** *optional*: Object containing the values of a specific path parameters.
* **`templatesPath`** *optional* String indicating a custom handlebars-template path for generating the tests. Note: copy all the templates to your custom directory, this is a 'all-or-nothing' path
* **`requestData`** *optional* Array containing data to send with the request See section on requestData for more details

#### Return value
### Return value
An array in which each string is content of a test file and the file name. Use this information to write those files to disk.

## Sending requestData
Bases on your schema there a a few modules out there that allow you to generate mock request.
You can send this mock data along with the tests generated by this module by filling the `requestData` property of the module.
The mock data needs to have with the following structure:

```javascript
{
'/endpoint': {
operation: {
'responseCode': [{ body: {}, description:'some description of the data']
}
}
}

```
so, for example this could be:
```javascript
{
'/pet': {
post: {
'200': [{
body: {
id: 1,
otherProperty: 'some property that is a string'
},
description: 'the description for this data'
}]
},
get: {
'200': [ {
guid: 'some_string_to_place_in_path',
anotherPathParam: 100,
description: 'valid path or query parameters'
}]
}
}
}
```
Note: for get-requests matching data will be transferred to the pathParams. So setting config.pathParams directly will have the same effect (see above).
Every mockData item in the `responseCode` array will be used to generate a test. The description will be added to the "it" function for reference.
##License
[MIT](/LICENSE)
Loading

0 comments on commit ef6deb1

Please sign in to comment.