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

Save email preferences changes #4548

Merged
merged 5 commits into from
May 21, 2024
Merged

Save email preferences changes #4548

merged 5 commits into from
May 21, 2024

Conversation

codemist
Copy link
Collaborator

References:

Jira: MNTOR-3168

Description

Screenshot (if applicable)

Not applicable.

How to test

Checklist (Definition of Done)

  • Localization strings (if needed) have been added.
  • Commits in this PR are minimal and have descriptive commit messages.
  • I've added or updated the relevant sections in readme and/or code comments
  • I've added a unit test to test for potential regressions of this bug.
  • Product Owner accepted the User Story (demo of functionality completed) or waived the privilege.
  • All acceptance criteria are met.
  • Jira ticket has been updated (if needed) to match changes made during the development process.
  • Jira ticket has been updated (if needed) with suggestions for QA when this PR is deployed to stage.

@codemist codemist requested a review from Vinnl May 16, 2024 16:36
Copy link

Copy link

function isEmailUpdateCommType(
value: string,
): value is EmailUpdateCommTypeOfOptions {
return ["null", "affected", "primary"].includes(value);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: Should we create an enum for these since we seem to semi-duplicate some values here and on L42+L45?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, are there other possible values for value that aren't one of these three?

Copy link
Collaborator

Choose a reason for hiding this comment

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

TypeScript enums are incompatible with the enum proposal for JS and changes runtime behaviour, and unions of literal strings (which we use here - EmailUpdateCommTypeOfOptions) provide the same type safety, so it's recommended to use those.

That type also indicates that indeed, these are the only three valid values :)

That said... See my other comments.

Copy link
Collaborator

@Vinnl Vinnl left a comment

Choose a reason for hiding this comment

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

Sorry for another review with just remarks, but I hope these are small ones...

function isEmailUpdateCommType(
value: string,
): value is EmailUpdateCommTypeOfOptions {
return ["null", "affected", "primary"].includes(value);
Copy link
Collaborator

Choose a reason for hiding this comment

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

TypeScript enums are incompatible with the enum proposal for JS and changes runtime behaviour, and unions of literal strings (which we use here - EmailUpdateCommTypeOfOptions) provide the same type safety, so it's recommended to use those.

That type also indicates that indeed, these are the only three valid values :)

That said... See my other comments.

@@ -48,8 +48,13 @@ export async function POST(req: NextRequest) {
default:
allEmailsToPrimary = null;
}
await setAllEmailsToPrimary(subscriber, allEmailsToPrimary);
await setMonthlyMonitorReport(subscriber, monthlyMonitorReport);

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't leave a comment on the relevant lines because they're unchanged, but it's best to update the type representing the request body to indicate that one of the properties should now be left empty:

export interface EmailUpdateCommOptionRequest {
  instantBreachAlerts?: EmailUpdateCommTypeOfOptions;
  monthlyMonitorReport?: boolean;
}

And then TS will show you what code to wrap in an if (typeof <x> !== "undefined"), and you won't need the custom type guard (isEmailUpdateCommType).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed in 22b41c4

Comment on lines 77 to 80
const body: EmailUpdateCommOptionRequest = {
instantBreachAlerts: chosenOption,
monthlyMonitorReport: monitorReportAllowed,
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you leave this in and make the change to the type that I suggested in the other file, then if people modify the backend, TS will warn us that we'll have to update the frontend as well.

(In fact, we probably want to do the same for the call to update monthlyMonitorReport, since we have no checks that we're matching the request body type there either.)

Suggested change
const body: EmailUpdateCommOptionRequest = {
instantBreachAlerts: chosenOption,
monthlyMonitorReport: monitorReportAllowed,
};
const body: EmailUpdateCommOptionRequest = {
instantBreachAlerts: chosenOption,
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed in 22b41c4

@codemist codemist requested a review from Vinnl May 17, 2024 19:00
Copy link

if (typeof instantBreachAlerts !== "undefined") {
await setAllEmailsToPrimary(subscriber, allEmailsToPrimary);
}
if (typeof monthlyMonitorReport === "boolean") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Vinnl Can the condition here be !== undefined too?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It ended up just being an issue of passing the wrong var! my bad

Copy link
Collaborator

@Vinnl Vinnl left a comment

Choose a reason for hiding this comment

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

Works well for me! (But if it doesn't for you, let's investigate together.)

if (typeof instantBreachAlerts !== "undefined") {
await setAllEmailsToPrimary(subscriber, allEmailsToPrimary);
}
if (typeof monthlyMonitorReport === "boolean") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep!

@codemist codemist merged commit 6928aba into main May 21, 2024
15 checks passed
@codemist codemist deleted the mntor-3168-2 branch May 21, 2024 15:44
Copy link

Cleanup completed - database 'blurts-server-pr-4548' destroyed, cloud run service 'blurts-server-pr-4548' destroyed

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.

None yet

3 participants