-
Notifications
You must be signed in to change notification settings - Fork 218
chore(email-renderer): Flatten types for renderer and fix some tests #19901
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
base: main
Are you sure you want to change the base?
Conversation
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.
These are all the snapshot tests updated after changing the renderer types
Of note too, I did away with the overly complex "renderAndSnapshotTest" function... I got too fancy and it made things too complex
| import * as VerifySecondaryCode from '../templates/verifySecondaryCode'; | ||
| import * as VerifyShortCode from '../templates/verifyShortCode'; | ||
|
|
||
| export type WithFxaLayouts<T> = T & FxaLayouts.TemplateData; |
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.
@dschom - Since all of these need to be paired with the FxaLayouts.TemplateData this felt okay. The other idea I had was to declare/export all of the input types here, then they can be used in the fxa-mailer.ts explicitly, so they stay in sync, something like this:
export type RenderRecoveryInput = WithFxaLayouts<Recovery.TemplateData>;
// on and onFeels a bit like overkill, but also means they can be used in the fxa-mailer and we don't have to then do the same WithFxaLayouts<Recovery.TemplateData>; inside the fxa-mailer on the send functions
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.
IMO, a bunch of redeclaration seems unnecessary to me and just adds maintenance work. And using WithFxaLayouts<Recovery.TemplateData> in fxa-mailer feels totally okay to.
| OmitCommonLinks<renderer.TemplateData> & | ||
| OmitCommonLinks<renderer.passwordForgotOtp.TemplateData> | ||
| OmitCommonLinks< | ||
| renderer.WithFxaLayouts<renderer.passwordForgotOtp.TemplateData> |
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.
Yeah, this is where we could be simplier if we exported the input types
OmitCommonLinks<renderer.PasswordForgotOtpInput>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 think this is fine. I sort of wonder if just changing the import declaration would clean this up e.g. drop * as renderer thing and just do import { WithFxaLayouts, passwordFortgotOtp } from '@fxa/accounts/email-renderer';
| * @param geoData Object containing city, state, and country | ||
| * @returns | ||
| */ | ||
| export function formatGeoData({ |
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.
This kind of feels like a helper for the sake of a helper... We could just align the type inside email-renderer with the same names... but I fear that would be more work than it's worth
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 think this is fine approach.
3d970b6 to
e87fdec
Compare
| const uid = uuid.v4({}, Buffer.alloc(16)).toString('hex'); | ||
| const passwordForgotTokenId = crypto.randomBytes(16).toString('hex'); | ||
| const uid = '6bfe0db9d4b44ccaa7c175a889024b86'; | ||
| const passwordForgotTokenId = |
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 will sometimes make these values more 'test' like. ie Fill the string 1234678, or all zeros... When using a hard coded random values like this, I've seen code analysis will flag and generate a warning about committed token.
| import * as VerifySecondaryCode from '../templates/verifySecondaryCode'; | ||
| import * as VerifyShortCode from '../templates/verifyShortCode'; | ||
|
|
||
| export type WithFxaLayouts<T> = T & FxaLayouts.TemplateData; |
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.
IMO, a bunch of redeclaration seems unnecessary to me and just adds maintenance work. And using WithFxaLayouts<Recovery.TemplateData> in fxa-mailer feels totally okay to.
| sync: false, | ||
| } | ||
| ); | ||
| const email = await r.renderAdminResetAccounts({ |
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.
Nice!
| country: geoData.location?.country, | ||
| stateCode: geoData.location?.state, | ||
| }, | ||
| location: formatGeoData(geoData.location), |
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.
Nice!
| OmitCommonLinks<renderer.TemplateData> & | ||
| OmitCommonLinks<renderer.passwordForgotOtp.TemplateData> | ||
| OmitCommonLinks< | ||
| renderer.WithFxaLayouts<renderer.passwordForgotOtp.TemplateData> |
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 think this is fine. I sort of wonder if just changing the import declaration would clean this up e.g. drop * as renderer thing and just do import { WithFxaLayouts, passwordFortgotOtp } from '@fxa/accounts/email-renderer';
- The types on fxa-email-renderer render functions make them difficult to use in auth-server - And there was some cleanup to do from the first integration with email-sender to auth-server - Flattens the types on fxa-email-renderer functions - Updates snapshot tests (even though they're still skipped) - Updates the fxa-mailer to use the flattened type - Fixes first libs email sender test to use deepEquals assert on params passed to mailer - Adds a formatGeoData to convert app request geo location data to format expected by library Closes: FXA-12885
Because
This pull request
Issue that this pull request solves
Closes: FXA-12885
Checklist
Put an
xin the boxes that applyScreenshots (Optional)
Please attach the screenshots of the changes made in case of change in user interface.
Other information (Optional)
Any other information that is important to this pull request.