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

refactor: encapsulate parsed responses (part 1) #1140

Merged
merged 19 commits into from
Mar 8, 2021

Conversation

tshuli
Copy link
Contributor

@tshuli tshuli commented Feb 15, 2021

Problem

Part 1 of #1104

Solution

Tests

  • Create a corppass form with email autoreply and pdf response. Submit form. Check that the autoreply email and pdf response both have a masked UID number with only the last 4 characters shown (e.g. *****123A)
  • Add a text field to the form with the title 'CorpPass Validated UID'. Check that the response on the text field is not masked in autoreply.
  • Check that the email response to the admin still has the full UID number.

@tshuli tshuli changed the title Refactor encapsulate parsed responses 1 refactor: encapsulate parsed responses (part 1) Feb 15, 2021
@tshuli tshuli marked this pull request as ready for review February 15, 2021 03:28
@tshuli tshuli force-pushed the refactor-encapsulate-parsed-responses-1 branch from 865b7fa to 0aeae38 Compare February 22, 2021 03:57
@tshuli tshuli force-pushed the refactor-encapsulate-parsed-responses-1 branch 2 times, most recently from ce8044f to d1cade0 Compare February 22, 2021 14:44
Copy link
Contributor

@liangyuanruo liangyuanruo left a 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

Copy link
Contributor

@mantariksh mantariksh left a 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

@tshuli tshuli force-pushed the refactor-encapsulate-parsed-responses-1 branch from 496fcd5 to ce4abdd Compare March 4, 2021 03:31
@tshuli
Copy link
Contributor Author

tshuli commented Mar 4, 2021

@liangyuanruo merge conflicts resolved, for re-review

@tshuli tshuli requested a review from liangyuanruo March 4, 2021 03:43
Comment on lines +375 to 376
dataCollationData,
formData,
Copy link
Contributor

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.

Copy link
Contributor

@liangyuanruo liangyuanruo left a 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?

Copy link
Contributor

@liangyuanruo liangyuanruo left a 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

  1. To use EmailDataObj in its entirety downstream
  2. Add unit tests for the EmailDataObj class

@mantariksh
Copy link
Contributor

I also see a lot of integration tests had to be updated, which seems fairly troublesome.

I think the only integration test file which had to be updated was email-submissions.server.controller.spec.js, which only covers middleware used in the preview submissions endpoint. We can probably delete that test file as soon as the preview submissions middleware functions are combined into a controller. the individual functions are all in typescript already.

Comment on lines 57 to 63
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)
}
Copy link
Contributor

@liangyuanruo liangyuanruo Mar 5, 2021

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?

Copy link
Contributor

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.

@tshuli tshuli merged commit 147e5ff into develop Mar 8, 2021
@tshuli
Copy link
Contributor Author

tshuli commented Mar 8, 2021

thanks @liangyuanruo for reviewing, will continue on the issues raised in the next PR

@tshuli tshuli mentioned this pull request Mar 10, 2021
@karrui karrui deleted the refactor-encapsulate-parsed-responses-1 branch April 21, 2021 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants