Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws apiGateway event - make sure http request parameters have boolean value #8329

Merged

Conversation

thewizarodofoz
Copy link
Contributor

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Oct 2, 2020

Codecov Report

Merging #8329 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #8329   +/-   ##
=======================================
  Coverage   88.01%   88.01%           
=======================================
  Files         249      249           
  Lines        9307     9307           
=======================================
  Hits         8192     8192           
  Misses       1115     1115           
Impacted Files Coverage Δ
...kage/compile/events/apiGateway/lib/method/index.js 100.00% <100.00%> (ø)
lib/plugins/aws/package/compile/functions/index.js 96.64% <0.00%> (-0.02%) ⬇️
lib/classes/Variables.js 99.72% <0.00%> (-0.01%) ⬇️
lib/plugins/aws/provider/awsProvider.js 93.04% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a020a4a...84b2cdf. Read the comment docs.

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @thewizarodofoz ! Please see my comment

@@ -14,7 +14,7 @@ module.exports = {
const requestParameters = {};
if (event.http.request && event.http.request.parameters) {
Object.entries(event.http.request.parameters).forEach(([key, value]) => {
requestParameters[key] = value.required === undefined ? value : value.required;
requestParameters[key] = _.isObject(value) ? value.required || false : value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think intention was to make it required by default when object form is used. So I believe it should be:

_.isObject(value)
  ? ((value.required != null) ? value.required : true)
  : value

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @thewizarodofoz ! We're near there. There are just some convention issues, please see my comment

@@ -14,7 +14,13 @@ module.exports = {
const requestParameters = {};
if (event.http.request && event.http.request.parameters) {
Object.entries(event.http.request.parameters).forEach(([key, value]) => {
requestParameters[key] = value.required === undefined ? value : value.required;
/* eslint-disable no-nested-ternary */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not disable lint. Technically this rule is turned on, on purpose, so code style like that is not introduced :)

I know I've written comment abusing that rule, but it was just for quick reference.

We can write it differently, probably with IIFE:

requestParameters[key] = (() => {
  if (!_.isObject(value)) return value;
  return value.required != null ? value.required : true
})();

@@ -603,6 +603,35 @@ describe('#compileMethods()', () => {
});
});

it('should set required to true when omitted from mapped value', () => {
awsCompileApigEvents.validated.events = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All new tests should be introduced with runServerless util, see https://github.com/serverless/serverless/tree/master/test#unit-tests

Relying on mocked awsCompileApigEvents and other classes like that, is very painful for eventual future refactors

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @thewizarodofoz ! Looks great!

@medikoo medikoo merged commit d2fb696 into serverless:master Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants