@middy/http-response-serializer
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -122,2 +122,28 @@ const createError = require('http-errors') | ||
test('It should use the default when no matching accept preferences are found', async () => { | ||
const handler = middy((event, context, cb) => { | ||
event.preferredContentType = 'text/java' | ||
cb(null, createHttpResponse()) | ||
}) | ||
handler.use(httpResponseSerializer(standardConfiguration)) | ||
const event = { | ||
headers: { | ||
Accept: 'application/java, text/x-dvi; q=0.8, text/x-c' | ||
} | ||
} | ||
const response = await invoke(handler, event) | ||
expect(response).toEqual({ | ||
statusCode: 200, | ||
headers: { | ||
'Content-Type': standardConfiguration.default | ||
}, | ||
body: '{"message":"Hello World"}' | ||
}) | ||
}) | ||
test('It should use `event.preferredContentType` instead of the default', async () => { | ||
@@ -124,0 +150,0 @@ const handler = middy((event, context, cb) => { |
@@ -40,3 +40,3 @@ const Accept = require('@hapi/accept') | ||
// find in order of first preferred type that has a matching serializer | ||
types.find(type => opts.serializers.map(s => { | ||
types.find(type => opts.serializers.find(s => { | ||
const test = s.regex.test(type) | ||
@@ -43,0 +43,0 @@ |
{ | ||
"name": "@middy/http-response-serializer", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "The Http Serializer middleware lets you define serialization mechanisms based on the current content negotiation.", | ||
@@ -53,6 +53,6 @@ "engines": { | ||
"devDependencies": { | ||
"@middy/core": "^1.0.0", | ||
"@middy/core": "^1.1.0", | ||
"es6-promisify": "^6.0.2" | ||
}, | ||
"gitHead": "6d3b35f67dbfda8c8e7ae2885d267687181b2e1d" | ||
"gitHead": "464119c7819be60f5dd85cce7648dd2db6723a55" | ||
} |
18466
324