api-gateway-mapping-template
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -0,1 +1,11 @@ | ||
<a name="0.0.5"></a> | ||
## [0.0.5](https://github.com/ToQoz/api-gateway-mapping-template/compare/v0.0.4...v0.0.5) (2015-12-18) | ||
### Bug Fixes | ||
* **package:** fix a bug in $input.json ([fde5289](https://github.com/ToQoz/api-gateway-mapping-template/commit/fde5289)) | ||
<a name="0.0.4"></a> | ||
@@ -24,3 +34,8 @@ ## [0.0.4](https://github.com/ToQoz/api-gateway-mapping-template/compare/v0.0.3...v0.0.4) (2015-12-15) | ||
### BREAKING CHANGE | ||
- module.exports takes `parameters` instead of `template`, `payload`, `params`, `context` | ||
<a name="0.0.2"></a> | ||
@@ -27,0 +42,0 @@ ## [0.0.2](https://github.com/ToQoz/api-gateway-mapping-template/compare/v0.0.1...v0.0.2) (2015-12-14) |
14
index.js
@@ -38,9 +38,9 @@ var clone = require('clone'); | ||
json: function(path) { | ||
var obj = JSON.parse(payload); | ||
if (typeof obj === 'string') { | ||
// re-parse when parsed payload is string. | ||
// because of | ||
// - https://github.com/ToQoz/api-gateway-mapping-template/blob/master/test/_.md#example-0ce08526 | ||
// - https://github.com/ToQoz/api-gateway-mapping-template/blob/master/test/_.md#example-1b8d22cd | ||
obj = JSON.parse(obj); | ||
var obj; | ||
// if payload starts with `{` or `[` or `"`, treat as JSON | ||
if (/^\s*(?:{|\[|")/.test(this._payload)) { | ||
obj = JSON.parse(this._payload); | ||
} else { | ||
// treat as string | ||
obj = this._payload; | ||
} | ||
@@ -47,0 +47,0 @@ |
{ | ||
"name": "api-gateway-mapping-template", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Make AWS API Gateway's Mapping Template testable.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -23,12 +23,16 @@ // This file is generated by `TEST=test/_.js node misc/gen.js` | ||
}); | ||
// https://github.com/ToQoz/api-gateway-mapping-template/blob/master/test/_.md#example-a669d28c | ||
describe('H=`{}` P=`a=b` ===> T=`"$input.json(\'$\')"`', function() { | ||
it('throw error', function() { | ||
assert.throws(function() { mappingTemplate({template: "\"$input.json('$')\"", payload: "a=b"}); }); | ||
// https://github.com/ToQoz/api-gateway-mapping-template/blob/master/test/_.md#example-0dce6fa3 | ||
describe('H=`{}` P=`a=b` ===> T=`$input.json(\'$\')`', function() { | ||
it('return a=b', function() { | ||
var expected = "a=b"; | ||
var actual = JSON.parse(mappingTemplate({template: "$input.json('$')", payload: "a=b"})); | ||
assert.deepEqual(expected, actual); | ||
}); | ||
}); | ||
// https://github.com/ToQoz/api-gateway-mapping-template/blob/master/test/_.md#example-0ce08526 | ||
describe('H=`{}` P=`"a=b"` ===> T=`"$input.json(\'$\')"`', function() { | ||
it('throw error', function() { | ||
assert.throws(function() { mappingTemplate({template: "\"$input.json('$')\"", payload: "\"a=b\""}); }); | ||
// https://github.com/ToQoz/api-gateway-mapping-template/blob/master/test/_.md#example-dbd6cf1c | ||
describe('H=`{}` P=`"a=b"` ===> T=`$input.json(\'$\')`', function() { | ||
it('return "a=b"', function() { | ||
var expected = "a=b"; | ||
var actual = JSON.parse(mappingTemplate({template: "$input.json('$')", payload: "\"a=b\""})); | ||
assert.deepEqual(expected, actual); | ||
}); | ||
@@ -52,7 +56,7 @@ }); | ||
}); | ||
// https://github.com/ToQoz/api-gateway-mapping-template/blob/master/test/_.md#example-c1b4a9a5 | ||
describe('H=`{}` P=`{}` ===> T=`"$input.json(\'$\')"`', function() { | ||
// https://github.com/ToQoz/api-gateway-mapping-template/blob/master/test/_.md#example-b9f18c27 | ||
describe('H=`{}` P=`{}` ===> T=`$input.json(\'$\')`', function() { | ||
it('return {}', function() { | ||
var expected = "{}"; | ||
var actual = JSON.parse(mappingTemplate({template: "\"$input.json('$')\"", payload: "{}"})); | ||
var expected = {}; | ||
var actual = JSON.parse(mappingTemplate({template: "$input.json('$')", payload: "{}"})); | ||
assert.deepEqual(expected, actual); | ||
@@ -59,0 +63,0 @@ }); |
@@ -11,11 +11,11 @@ ## example-12f77fd5 | ||
## example-a669d28c | ||
## example-0dce6fa3 | ||
Template|Header|Payload|Status code|Result | ||
--------|------|-------|-----------|------ | ||
`"$input.json('$')"`|`None`|`a=b`|`200`|`{errorMessage=Unable to parse input as json: Unexpected token a, errorType=SyntaxError}` | ||
`$input.json('$')`|`None`|`a=b`|`200`|`"a=b"` | ||
## example-0ce08526 | ||
## example-dbd6cf1c | ||
Template|Header|Payload|Status code|Result | ||
--------|------|-------|-----------|------ | ||
`"$input.json('$')"`|`None`|`"a=b"`|`200`|`{errorMessage=Unable to parse input as json: Unexpected token a, errorType=SyntaxError}` | ||
`$input.json('$')`|`None`|`"a=b"`|`200`|`"a=b"` | ||
@@ -32,6 +32,6 @@ ## example-03be1e25 | ||
## example-c1b4a9a5 | ||
## example-b9f18c27 | ||
Template|Header|Payload|Status code|Result | ||
--------|------|-------|-----------|------ | ||
`"$input.json('$')"`|`None`|`{}`|`200`|`"{}"` | ||
`$input.json('$')`|`None`|`{}`|`200`|`{}` | ||
@@ -38,0 +38,0 @@ ## example-25c6993c |
30909
474