lambda-test
Advanced tools
Comparing version 2.0.2 to 3.0.0
@@ -18,3 +18,2 @@ | ||
files: [ | ||
'lib/LambdaTest.js', | ||
'lib/HandlerTester.js' | ||
@@ -21,0 +20,0 @@ ] |
'use strict'; | ||
const LambdaTest = require('./lib/LambdaTest'); | ||
const HandlerTester = require('./lib/HandlerTester'); | ||
@@ -17,5 +16,3 @@ | ||
function test (handler, statusCode, httpMethod) { | ||
const t = new LambdaTest(); | ||
return t.test(handler, statusCode, httpMethod); | ||
return new HandlerTester(handler, statusCode, httpMethod); | ||
} | ||
@@ -25,3 +22,2 @@ | ||
module.exports.LambdaTest = LambdaTest; | ||
module.exports.HandlerTester = HandlerTester; |
@@ -10,10 +10,6 @@ 'use strict'; | ||
* @param {string|null} [httpMethod] | ||
* @param {string|null} [route] | ||
* @param {ApiBlueprint|null} [api] | ||
*/ | ||
constructor (handler, statusCode = null, httpMethod = null, route = null, api = null) { | ||
constructor (handler, statusCode = null, httpMethod = null) { | ||
this._handler = handler; | ||
this._api = api; | ||
this._httpMethod = httpMethod; | ||
this._route = route; | ||
this._statusCode = statusCode; | ||
@@ -30,3 +26,3 @@ | ||
* | ||
* @param {Object|null} query - the query string | ||
* @param {object|null} query - the query string | ||
* @returns {this} | ||
@@ -38,3 +34,5 @@ */ | ||
return this; | ||
} else if (this._queryStringParameters === null) { | ||
} | ||
if (this._queryStringParameters === null) { | ||
this._queryStringParameters = {}; | ||
@@ -52,3 +50,3 @@ } | ||
* | ||
* @param {Object|string} body - request body | ||
* @param {object|string} body - request body | ||
* @returns {this} | ||
@@ -71,3 +69,3 @@ */ | ||
* | ||
* @param {Object|null} headers | ||
* @param {object|null} headers | ||
* @returns {this} | ||
@@ -86,3 +84,3 @@ */ | ||
* | ||
* @param {Object|null} params | ||
* @param {object|null} params | ||
* @returns {this} | ||
@@ -94,3 +92,5 @@ */ | ||
return this; | ||
} else if (this._pathParameters === null) { | ||
} | ||
if (this._pathParameters === null) { | ||
this._pathParameters = {}; | ||
@@ -112,3 +112,3 @@ } | ||
* | ||
* @returns {Promise<Object>} | ||
* @returns {Promise<object>} | ||
*/ | ||
@@ -142,3 +142,3 @@ run () { | ||
* | ||
* @returns {Promise<Object>} | ||
* @returns {Promise<object>} | ||
*/ | ||
@@ -154,17 +154,3 @@ verify () { | ||
if (this._api === null) { | ||
return res; | ||
} | ||
try { | ||
this._api | ||
.responseMatches(res.body, this._route, this._method(), this._statusCode); | ||
return res; | ||
} catch (e) { | ||
const messages = (e.errors || []).map(err => ` - ${err.stack}`).join('\n'); | ||
Object.assign(e, { | ||
message: `${e.message}: \n${messages}` | ||
}); | ||
throw e; | ||
} | ||
return res; | ||
}); | ||
@@ -171,0 +157,0 @@ } |
{ | ||
"name": "lambda-test", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"description": "", | ||
@@ -27,21 +27,28 @@ "main": "index.js", | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/davidmenger/lambda-test.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/davidmenger/lambda-test/issues" | ||
}, | ||
"homepage": "https://github.com/davidmenger/lambda-test#readme", | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"eslint": "^4.19.1", | ||
"eslint-config-airbnb": "^16.1.0", | ||
"eslint-mocha": "^0.4.0", | ||
"eslint-plugin-import": "^2.11.0", | ||
"eslint-plugin-jsdoc": "^3.6.2", | ||
"eslint-plugin-jsx-a11y": "^6.0.3", | ||
"eslint-plugin-mocha": "^5.0.0", | ||
"eslint-plugin-react": "^7.7.0", | ||
"chai": "^4.2.0", | ||
"eslint": "^5.16.0", | ||
"eslint-config-airbnb": "^17.1.0", | ||
"eslint-mocha": "^0.7.2", | ||
"eslint-plugin-import": "^2.17.3", | ||
"eslint-plugin-jsdoc": "^7.2.3", | ||
"eslint-plugin-jsx-a11y": "^6.2.1", | ||
"eslint-plugin-mocha": "^5.3.0", | ||
"eslint-plugin-react": "^7.13.0", | ||
"istanbul": "^0.4.5", | ||
"jsdoc-to-markdown": "^4.0.1", | ||
"mocha": "^5.0.5", | ||
"jsdoc-to-markdown": "^5.0.0", | ||
"mocha": "^6.1.4", | ||
"mocha-istanbul": "^0.3.0" | ||
}, | ||
"dependencies": { | ||
"jsonschema": "^1.2.4", | ||
"protagonist": "1.5.2" | ||
"jsonschema": "^1.2.4" | ||
} | ||
} |
@@ -21,80 +21,5 @@ # Lambda test | ||
or much more sophisticated with Api Blueprint check | ||
```javascript | ||
const assert = require('assert'); | ||
const { LambdaTest } = require('lambda-test'); | ||
const { updateById } = require('../../routes/users.js'); | ||
// in project root | ||
const tester = new LambdaTest('./apiBlueprint.apib'); | ||
describe('UPDATE /users/{id}', () => { | ||
it('should get user by id', async () => { | ||
const response = await tester.test(updateById, '/users/{id}', 'UPDATE', 200) | ||
.pathParameters({ id: 123 }) | ||
.queryStringParameters({ fields: 'name' }) | ||
.headers({ Authorization: 'secret' }) | ||
.body({ name: 'John Doe' }) | ||
.verify(); | ||
assert.equal(response.body.name, 'John Doe'); | ||
}); | ||
}); | ||
``` | ||
----------------- | ||
# API | ||
## Classes | ||
<dl> | ||
<dt><a href="#LambdaTest">LambdaTest</a></dt> | ||
<dd></dd> | ||
<dt><a href="#HandlerTester">HandlerTester</a></dt> | ||
<dd></dd> | ||
</dl> | ||
<a name="LambdaTest"></a> | ||
## LambdaTest | ||
**Kind**: global class | ||
* [LambdaTest](#LambdaTest) | ||
* [new LambdaTest([blueprintFile])](#new_LambdaTest_new) | ||
* [._getBlueprint()](#LambdaTest+_getBlueprint) ⇒ <code>ApiBlueprint</code> | ||
* [.test(handler, [routeOrStatus], [httpMethod], [statusCode])](#LambdaTest+test) ⇒ [<code>HandlerTester</code>](#HandlerTester) | ||
<a name="new_LambdaTest_new"></a> | ||
### new LambdaTest([blueprintFile]) | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| [blueprintFile] | <code>string</code> | <code>null</code> | api blueprint | | ||
<a name="LambdaTest+_getBlueprint"></a> | ||
### lambdaTest._getBlueprint() ⇒ <code>ApiBlueprint</code> | ||
**Kind**: instance method of [<code>LambdaTest</code>](#LambdaTest) | ||
<a name="LambdaTest+test"></a> | ||
### lambdaTest.test(handler, [routeOrStatus], [httpMethod], [statusCode]) ⇒ [<code>HandlerTester</code>](#HandlerTester) | ||
Create test and checks for status code | ||
when first parameter is API path, response is checked against api blueprint | ||
**Kind**: instance method of [<code>LambdaTest</code>](#LambdaTest) | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| handler | <code>function</code> | | function to test | | ||
| [routeOrStatus] | <code>number</code> \| <code>string</code> | <code>200</code> | route path for blueprint or status code | | ||
| [httpMethod] | <code>string</code> | <code>null</code> | http method to use | | ||
| [statusCode] | <code>number</code> \| <code>null</code> | <code></code> | expected status code | | ||
<a name="HandlerTester"></a> | ||
@@ -106,3 +31,3 @@ | ||
* [HandlerTester](#HandlerTester) | ||
* [new HandlerTester(handler, [statusCode], [httpMethod], [route], [api])](#new_HandlerTester_new) | ||
* [new HandlerTester(handler, [statusCode], [httpMethod])](#new_HandlerTester_new) | ||
* [.queryStringParameters(query)](#HandlerTester+queryStringParameters) ⇒ <code>this</code> | ||
@@ -112,8 +37,8 @@ * [.body(body)](#HandlerTester+body) ⇒ <code>this</code> | ||
* [.pathParameters(params)](#HandlerTester+pathParameters) ⇒ <code>this</code> | ||
* [.run()](#HandlerTester+run) ⇒ <code>Promise.<Object></code> | ||
* [.verify()](#HandlerTester+verify) ⇒ <code>Promise.<Object></code> | ||
* [.run()](#HandlerTester+run) ⇒ <code>Promise.<object></code> | ||
* [.verify()](#HandlerTester+verify) ⇒ <code>Promise.<object></code> | ||
<a name="new_HandlerTester_new"></a> | ||
### new HandlerTester(handler, [statusCode], [httpMethod], [route], [api]) | ||
### new HandlerTester(handler, [statusCode], [httpMethod]) | ||
@@ -125,4 +50,2 @@ | Param | Type | Default | | ||
| [httpMethod] | <code>string</code> \| <code>null</code> | <code>null</code> | | ||
| [route] | <code>string</code> \| <code>null</code> | <code>null</code> | | ||
| [api] | <code>ApiBlueprint</code> \| <code>null</code> | <code></code> | | ||
@@ -138,3 +61,3 @@ <a name="HandlerTester+queryStringParameters"></a> | ||
| --- | --- | --- | --- | | ||
| query | <code>Object</code> \| <code>null</code> | <code></code> | the query string | | ||
| query | <code>object</code> \| <code>null</code> | <code></code> | the query string | | ||
@@ -150,3 +73,3 @@ <a name="HandlerTester+body"></a> | ||
| --- | --- | --- | --- | | ||
| body | <code>Object</code> \| <code>string</code> | <code></code> | request body | | ||
| body | <code>object</code> \| <code>string</code> | <code></code> | request body | | ||
@@ -162,3 +85,3 @@ <a name="HandlerTester+headers"></a> | ||
| --- | --- | --- | | ||
| headers | <code>Object</code> \| <code>null</code> | <code></code> | | ||
| headers | <code>object</code> \| <code>null</code> | <code></code> | | ||
@@ -172,7 +95,7 @@ <a name="HandlerTester+pathParameters"></a> | ||
| --- | --- | --- | | ||
| params | <code>Object</code> \| <code>null</code> | <code></code> | | ||
| params | <code>object</code> \| <code>null</code> | <code></code> | | ||
<a name="HandlerTester+run"></a> | ||
### handlerTester.run() ⇒ <code>Promise.<Object></code> | ||
### handlerTester.run() ⇒ <code>Promise.<object></code> | ||
Send request | ||
@@ -183,5 +106,5 @@ | ||
### handlerTester.verify() ⇒ <code>Promise.<Object></code> | ||
### handlerTester.verify() ⇒ <code>Promise.<object></code> | ||
Send request | ||
**Kind**: instance method of [<code>HandlerTester</code>](#HandlerTester) |
@@ -17,3 +17,3 @@ 'use strict'; | ||
username: 'mtakac', | ||
email: 'marek.takac@pragonauts.com' | ||
email: 'marek.takac@gmail.com' | ||
}) | ||
@@ -20,0 +20,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1
1
0
1
16927
13
278
102
1
- Removedprotagonist@1.5.2
- Removednan@2.2.1(transitive)
- Removedprotagonist@1.5.2(transitive)