-
Notifications
You must be signed in to change notification settings - Fork 84
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: encapsulate parsed responses (part 1) #1140
Conversation
src/app/modules/submission/email-submission/email-submission.util.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.util.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.util.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.util.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.util.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.util.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.util.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/__tests__/email-submission.service.spec.ts
Outdated
Show resolved
Hide resolved
865b7fa
to
0aeae38
Compare
src/app/modules/submission/email-submission/email-submission.util.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.util.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.util.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.util.ts
Outdated
Show resolved
Hide resolved
ce8044f
to
d1cade0
Compare
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.
To fix merge conflicts
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.
some small nits + the comment on renaming, otherwise lgtm
src/app/modules/submission/email-submission/email-submission.service.ts
Outdated
Show resolved
Hide resolved
src/app/modules/submission/email-submission/email-submission.util.ts
Outdated
Show resolved
Hide resolved
…cessary Co-authored-by: Yuan Ruo <yuanruo@data.gov.sg>
…teFormattedDataForOneField
496fcd5
to
ce4abdd
Compare
@liangyuanruo merge conflicts resolved, for re-review |
dataCollationData, | ||
formData, |
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.
As we're encapsulating the complexity into the EmailDataObj
class, could you combine the function arguments to accept an instance of that class instead? the service APIs should not need to know or ask for internal representations.
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 also see a lot of integration tests had to be updated, which seems fairly troublesome. One of the goals of encapsulation is to make the code more testable. Instead of long-winded integration tests, perhaps we could simply be writing unit tests against the EmailDataObj
instead?
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.
Post-discussion follow up
- To use
EmailDataObj
in its entirety downstream - Add unit tests for the
EmailDataObj
class
I think the only integration test file which had to be updated was |
export const createEmailData = ( | ||
parsedResponses: ProcessedFieldResponse[], | ||
hashedFields: Set<string>, | ||
authType: AuthType = AuthType.NIL, | ||
): EmailData => { | ||
// First, get an array of email data for each response | ||
// Each field has an array of email data to accommodate table fields, | ||
// which have multiple rows of data per field. Hence flatten and maintain | ||
// the order of responses. | ||
return ( | ||
parsedResponses | ||
.flatMap((response) => createEmailDataForOneField(response, hashedFields)) | ||
// Then reshape such that autoReplyData, jsonData and formData are each arrays | ||
.reduce<EmailData>( | ||
(acc, dataForOneField) => { | ||
if (dataForOneField.autoReplyData) { | ||
acc.autoReplyData.push(dataForOneField.autoReplyData) | ||
} | ||
if (dataForOneField.jsonData) { | ||
acc.jsonData.push(dataForOneField.jsonData) | ||
} | ||
acc.formData.push(dataForOneField.formData) | ||
return acc | ||
}, | ||
{ | ||
autoReplyData: [], | ||
jsonData: [], | ||
formData: [], | ||
}, | ||
) | ||
) | ||
return new SubmissionEmailObj(parsedResponses, hashedFields, 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.
createEmailData
is now a dumb wrapper around the SubmissionEmailObj
constructor and offers no abstraction. can we get rid of it and just call new SubmissionEmailObj(...)
directly?
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.
Alternatively - keep createEmailData
but have it return a Result
for type safety? Either in this PR or the next one.
thanks @liangyuanruo for reviewing, will continue on the issues raised in the next PR |
Problem
Part 1 of #1104
Solution
This PR addresses the comments made in refactor: encapsulate parsedResponses #1070 and refactors the implementation of feat: mask cp uid in autoreply to respondent #1109 into class methods instead of a standalone masking function
As per the objectives stated in Encapsulate the construction and representation of parsed responses into a class #1104, subsequent PR will encapsulate the data processing functions in the middlewares
EmailSubmissionsMiddleware.validateEmailSubmission
,AdminFormController.passThroughSpcp
,SpcpController.appendVerifiedSPCPResponses
into the same classTests