-
Notifications
You must be signed in to change notification settings - Fork 87
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
refactor(email-submission/controller): refactored email submission #1594
Conversation
@LoneRifle any conflicts here and what you're doing? |
Blocks #1571 |
4abb296
to
ee140b9
Compare
@LoneRifle should be fine now; seeing as you will write unit tests for this file, lmk if it reads better/what you'd liek to see improved! |
7829920
to
ad085da
Compare
) | ||
.andThen(({ parsedResponses, form }) => { | ||
const { authType } = form | ||
switch (authType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
point 3 in design considerations
src/app/modules/submission/email-submission/email-submission.controller.ts
Outdated
Show resolved
Hide resolved
@karrui @mantariksh are there any issues apart from the unclear logging? |
parsedResponses, | ||
hashedFields: new Set<string>(), | ||
}) as Result< | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might it be better to extract this Result
type into a separate type definition, and add it as a generic argument to this particular andThen
? so it's very clear exactly what this andThen
block should be returning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree with the first point. extracting it has value, because it helps the reader to understand this whole chunk without getting lost in the details.
for the second point, this is to aid in typehinting for typescript, and even if we were to add it as a generic argument to this particular andThen
, we would still need the annotation on the errors just so that type level information is preserved and not lost (because of the ok
).
i think this would impact readability just by virtue of how verbose it is (due to the errors) and wouldn't significantly impact clarity because the destructuring of the next andThen
makes the shape and types clear
src/app/modules/submission/email-submission/email-submission.controller.ts
Outdated
Show resolved
Hide resolved
) | ||
|
||
// Send email confirmations | ||
return SubmissionService.sendEmailConfirmations({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the intent of the code might be clearer if we prefix this with void
and shift it above the call to res.json
, to make it more obvious that we're not awaiting on the email confirmations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i combined it into a single map
block and prefixed sendEmailConfirmations
with void
; main reason is because we need to call orElse
on sendEmailConfirmations
which requires typehints. The typehinting here is rather verbose due to the parameter forwarding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you also add manual tests for the following (and anything else you can think of)? can't take any chances with email submissions endpoint.
- submit storage mode form to email mode endpoint
- submit form which has been made private
- submit form which has been archived
- submit captcha-enabled form without captcha
- submit captcha-disabled form
- submit form which has exceeded submission limit
- submit form with invalid responses
- create multiple email fields with email confirmation, check that the correct confirmation email is sent for each one
@mantariksh based on the old code, there are the following decision points
i added 1 test based on point 5; unsure how to test point 7. i think the tests that you've described covers the rest of the decision points and i've verified them on local |
src/app/modules/submission/email-submission/email-submission.controller.ts
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.controller.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.controller.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.controller.ts
Outdated
Show resolved
Hide resolved
…or case for submission
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm; update your PR description? Remove the logErrorWithMeta
block hehe since it is already removed
Problem
handleEmailSubmission
uses alot of mutated variables andif/else
, which could have been better written in order to avoid mental overhead on the maintainer and future developersSolution
This PR refactors the
handleEmailSubmission
so that it reads in a sequential fashion and there is only onelet
declared variable.Design Considerations
let
scoped variable -spcpSubmissionFailure
. This is because the flag is set only in 1 place and the frontend does do work if it istrue
. Although there could be a better alternative to avoid thelet
, it is typed asundefined | true
for explicitness and i don't want to significantly refactor the controller just for this.hashedFields/parsedResponses
is still pretty unwieldy and done as aswitch
case - this is becauseMyInfo
treats this differentlyManual Tests