Skip to content

Commit

Permalink
Indicate that no subscriber might be found
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinnl committed Jan 20, 2025
1 parent 07dcdee commit abe2549
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,44 @@ it("calls the right telemetry event if a user opts out of monthly report", async
);
});

it("does not crash if no email preferences were found for the current user", () => {
const component = (
<TestComponentWrapper>
<SettingsView
l10n={getL10n()}
user={{
...mockedUser,
subscriber: {
...mockedUser.subscriber!,
all_emails_to_primary: true,
monthly_monitor_report: true,
},
}}
subscriber={{
...mockedSubscriber,
all_emails_to_primary: true,
monthly_monitor_report: true,
}}
breachCountByEmailAddress={{
[mockedUser.email]: 42,
[mockedSecondaryVerifiedEmail.email]: 42,
}}
emailAddresses={[mockedSecondaryVerifiedEmail]}
fxaSettingsUrl=""
fxaSubscriptionsUrl=""
yearlySubscriptionUrl=""
monthlySubscriptionUrl=""
subscriptionBillingAmount={mockedSubscriptionBillingAmount}
enabledFeatureFlags={["UpdatedEmailPreferencesOption"]}
experimentData={defaultExperimentData["Features"]}
isMonthlySubscriber={true}
data={undefined}
/>
</TestComponentWrapper>
);
expect(() => render(component)).not.toThrow();
});

it("refreshes the session token after changing email alert preferences, to ensure the latest pref is available in it", async () => {
global.fetch = jest.fn().mockResolvedValueOnce({ ok: true });
const user = userEvent.setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2395,6 +2395,43 @@ describe("Settings page redesign", () => {
expect(monthlyMonitorReportBtn).toHaveAttribute("aria-checked", "true");
});

it("does not crash when the preference for the monthly monitor report was unset", () => {
const component = (
<SettingsWrapper>
<SettingsView
activeTab="notifications"
l10n={getL10n()}
user={{
...mockedFreeUser,
}}
subscriber={{
...mockedSubscriber,
}}
breachCountByEmailAddress={{
[mockedUser.email]: 42,
[mockedSecondaryVerifiedEmail.email]: 42,
}}
emailAddresses={[mockedSecondaryVerifiedEmail]}
fxaSettingsUrl=""
fxaSubscriptionsUrl=""
yearlySubscriptionUrl=""
monthlySubscriptionUrl=""
subscriptionBillingAmount={mockedSubscriptionBillingAmount}
enabledFeatureFlags={[
"UpdatedEmailPreferencesOption",
"MonthlyReportFreeUser",
"SettingsPageRedesign",
]}
experimentData={defaultExperimentData["Features"]}
isMonthlySubscriber={false}
data={undefined}
/>
</SettingsWrapper>
);

expect(() => render(component)).not.toThrow();
});

it("checks that monthly monitor report is enabled", () => {
render(
<SettingsWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type Props = {
l10n: ExtendedReactLocalization;
user: Session["user"];
subscriber: SubscriberRow;
data: SubscriberEmailPreferencesOutput;
data?: SubscriberEmailPreferencesOutput;
monthlySubscriptionUrl: string;
yearlySubscriptionUrl: string;
subscriptionBillingAmount: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { onRemoveEmail } from "../actions";

export type SettingsPanelEditInfoProps = {
breachCountByEmailAddress: Record<string, number>;
data: SubscriberEmailPreferencesOutput;
data?: SubscriberEmailPreferencesOutput;
emailAddresses: SanitizedEmailAddressRow[];
subscriber: SubscriberRow;
user: Session["user"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { RadioInput } from "../../../../../../../components/client/RadioInput";
import { CONST_URL_MOZILLA_BASKET } from "../../../../../../../../constants";

export type SettingsPanelNotificationsProps = {
data: SubscriberEmailPreferencesOutput;
data?: SubscriberEmailPreferencesOutput;
subscriber: SubscriberRow;
user: Session["user"];
};
Expand Down
2 changes: 1 addition & 1 deletion src/db/tables/subscriber_email_preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ async function unsubscribeMonthlyMonitorReportForUnsubscribeToken(

async function getEmailPreferenceForPrimaryEmail(
email: string,
): Promise<SubscriberEmailPreferencesOutput> {
): Promise<SubscriberEmailPreferencesOutput | undefined> {
logger.info("get_email_preference_for_primary_email", {
email,
});
Expand Down

0 comments on commit abe2549

Please sign in to comment.