8000 Merge pull request #8 from MrMaximus/ISS-7 · aceew/lambda-proxy-router@174bd3d · GitHub
[go: up one dir, main page]

Skip to content

Commit 174bd3d

Browse files
authored
Merge pull request #8 from MrMaximus/ISS-7
Added support for isBase64Encoded response attribute
2 parents fb43a2e + 6ba5e1f commit 174bd3d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,21 @@ export default class Alpr {
6767
* @param {Object} data.headers
6868
* Any headers to return with the API result.
6969
*
70-
* @param {mixed} body
70+
* @param {mixed} data.body
7171
* Payload to send back as the API response. This will be json stringified.
72+
*
73+
* @param {boolean} data.isBase64Encoded
74+
* Set this to true to return isBase64Encoded true on the response object.
7275
*/
7376
const response = (data = {}) => {
7477
const responseData = {};
7578

7679
responseData.statusCode = Number.isInteger(data.statusCode) ? data.statusCode : 200;
7780
responseData.headers = typeof data.headers === 'object' ? data.headers : {};
7881
responseData.body = JSON.stringify(data.body ? data.body : data);
82+
if (data.isBase64Encoded) {
83+
responseData.isBase64Encoded = true;
84+
}
7985

8086
return instancedClass.callback(null, responseData);
8187
};

test/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,51 @@ test.cb(
198198
}
199199
);
200200

201+
test.cb(
202+
'Route handler > returns isBase64Encoded on the response object when true in response data',
203+
(t) => {
204+
t.plan(3);
205+
const lambdaCallback = (err, response) => {
206+
t.is(typeof response, 'object');
207+
t.deepEqual(response.body, '{}');
208+
t.true(response.isBase64Encoded);
209+
t.end();
210+
};
211+
212+
const alprParams = Object.assign({}, data);
213+
alprParams.callback = lambdaCallback;
214+
215+
const alprLocal = new Alpr(alprParams);
216+
alprLocal.route({
217+ method: data.event.httpMethod,
218+
path: data.event.resource,
219+
handler: (requestData, response) => response({ body: {}, isBase64Encoded: true }),
220+
});
221+
}
222+
);
223+
224+
test.cb(
225+
'Route handler > returns response object without isBase64Encoded when undefined in response data',
226+
(t) => {
227+
t.plan(2);
228+
const lambdaCallback = (err, response) => {
229+
t.is(typeof response, 'object');
230+
t.not(response.isBase64Encoded, true);
231+
t.end();
232+
};
233+
234+
const alprParams = Object.assign({}, data);
235+
alprParams.callback = lambdaCallback;
236+
237+
const alprLocal = new Alpr(alprParams);
238+
alprLocal.route({
239+
method: data.event.httpMethod,
240+
path: data.event.resource,
241+
handler: (requestData, response) => response(),
242+
});
243+
}
244+
);
245+
201246
test('String Matching > will return false when no params are provided', (t) => {
202247
// Just for default params
203248
t.is(Alpr.inArrayOrIsString(), false);

0 commit comments

Comments
 (0)
0