From 12e8dbf543c6e3db8df2d905e784edd5611b5295 Mon Sep 17 00:00:00 2001 From: Kaitlyn Date: Tue, 17 Dec 2024 19:46:50 -0500 Subject: [PATCH] add more unit tests --- src/app/components/server/StatusPill.tsx | 1 + .../server/getRelevantGuidedSteps.test.ts | 211 +++++++++++++++++- .../server/getRelevantGuidedSteps.ts | 13 +- 3 files changed, 218 insertions(+), 7 deletions(-) diff --git a/src/app/components/server/StatusPill.tsx b/src/app/components/server/StatusPill.tsx index 69daca659e..4cd5fe1845 100644 --- a/src/app/components/server/StatusPill.tsx +++ b/src/app/components/server/StatusPill.tsx @@ -119,6 +119,7 @@ export const getExposureStatus = ( const additionalRemovalStatusesEnabled = enabledFeatureFlags.includes( "AdditionalRemovalStatuses", ); + // TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag const manualRemovalEnabled = enabledFeatureFlags.includes( "EnableRemovalUnderMaintenanceStep", ); diff --git a/src/app/functions/server/getRelevantGuidedSteps.test.ts b/src/app/functions/server/getRelevantGuidedSteps.test.ts index ca2c4f3ef3..75585f6816 100644 --- a/src/app/functions/server/getRelevantGuidedSteps.test.ts +++ b/src/app/functions/server/getRelevantGuidedSteps.test.ts @@ -3,7 +3,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { describe, expect, it } from "@jest/globals"; -import { getNextGuidedStep } from "./getRelevantGuidedSteps"; +import { + getNextGuidedStep, + hasCompletedStep, + isEligibleForStep, +} from "./getRelevantGuidedSteps"; import { createRandomBreach, createRandomScanResult, @@ -562,7 +566,7 @@ describe("getNextGuidedStep", () => { ).toBe("Done"); }); - it("links to the removal under maintenance step if a user has scan resutls with a data broker that has a removal under maintenance status", () => { + it("links to the removal under maintenance step if a user has scan results with a data broker that has a removal under maintenance status", () => { expect( getNextGuidedStep( { @@ -596,6 +600,209 @@ describe("getNextGuidedStep", () => { }); }); + // TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag + it("does not link to the removal under maintenance step if the feature flag is off", () => { + expect( + getNextGuidedStep({ + countryCode: "us", + latestScanData: { + scan: { + ...completedScan.scan!, + onerep_scan_status: "finished", + }, + results: [ + createRandomScanResult({ + status: "optout_in_progress", + manually_resolved: false, + broker_status: "removal_under_maintenance", + }), + ], + }, + subscriberBreaches: [], + user: { + email: "arbitrary@example.com", + }, + }).id, + ).toBe("Done"); + }); + + it("returns true when all data brokers that are removal under maintenance are resolved", () => { + expect( + hasCompletedStep( + { + countryCode: "us", + latestScanData: { + scan: { + ...completedScan.scan!, + onerep_scan_status: "finished", + }, + results: [ + createRandomScanResult({ + manually_resolved: true, + status: "optout_in_progress", + broker_status: "removal_under_maintenance", + }), + ], + }, + subscriberBreaches: [], + user: { email: "arbitrary@example.com" }, + }, + "DataBrokerManualRemoval", + // TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag + ["EnableRemovalUnderMaintenanceStep"], + ), + ).toBe(true); + }); + + it("returns false when data brokers that are removal under maintenance are not resolved", () => { + expect( + hasCompletedStep( + { + countryCode: "us", + latestScanData: { + scan: { + ...completedScan.scan!, + onerep_scan_status: "finished", + }, + results: [ + createRandomScanResult({ + manually_resolved: false, + status: "optout_in_progress", + broker_status: "removal_under_maintenance", + }), + ], + }, + subscriberBreaches: [], + user: { email: "arbitrary@example.com" }, + }, + "DataBrokerManualRemoval", + // TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag + ["EnableRemovalUnderMaintenanceStep"], + ), + ).toBe(false); + }); + + // TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag + it("returns false when data brokers that are removal under maintenance are resolved, but the flag is off", () => { + expect( + hasCompletedStep( + { + countryCode: "us", + latestScanData: { + scan: { + ...completedScan.scan!, + onerep_scan_status: "finished", + }, + results: [ + createRandomScanResult({ + manually_resolved: true, + status: "optout_in_progress", + broker_status: "removal_under_maintenance", + }), + ], + }, + subscriberBreaches: [], + user: { email: "arbitrary@example.com" }, + }, + "DataBrokerManualRemoval", + [], + ), + ).toBe(false); + }); + + it("is not eligible for step if the data brokers under maintenance is already removed", () => { + expect( + isEligibleForStep( + { + countryCode: "us", + latestScanData: { + scan: { + ...completedScan.scan!, + onerep_scan_status: "finished", + }, + results: [ + createRandomScanResult({ + manually_resolved: false, + status: "removed", + broker_status: "removal_under_maintenance", + }), + ], + }, + subscriberBreaches: [], + user: { email: "arbitrary@example.com" }, + }, + "DataBrokerManualRemoval", + // TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag + ["EnableRemovalUnderMaintenanceStep"], + ), + ).toBe(false); + }); + + it("is not eligible for step if the data brokers under maintenance is already manually resolved", () => { + expect( + isEligibleForStep( + { + countryCode: "us", + latestScanData: { + scan: { + ...completedScan.scan!, + onerep_scan_status: "finished", + }, + results: [ + createRandomScanResult({ + manually_resolved: true, + status: "optout_in_progress", + broker_status: "removal_under_maintenance", + }), + ], + }, + subscriberBreaches: [], + user: { email: "arbitrary@example.com" }, + }, + "DataBrokerManualRemoval", + // TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag + ["EnableRemovalUnderMaintenanceStep"], + ), + ).toBe(false); + }); + + it("is eligible for step if there are valid data brokers under maintenance", () => { + expect( + isEligibleForStep( + { + countryCode: "us", + latestScanData: { + scan: { + ...completedScan.scan!, + onerep_scan_status: "finished", + }, + results: [ + createRandomScanResult({ + manually_resolved: true, + status: "optout_in_progress", + broker_status: "removal_under_maintenance", + }), + createRandomScanResult({ + manually_resolved: false, + status: "removed", + broker_status: "removal_under_maintenance", + }), + createRandomScanResult({ + manually_resolved: false, + status: "optout_in_progress", + broker_status: "removal_under_maintenance", + }), + ], + }, + subscriberBreaches: [], + user: { email: "arbitrary@example.com" }, + }, + "DataBrokerManualRemoval", + ["EnableRemovalUnderMaintenanceStep"], + ), + ).toBe(true); + }); + it("links to the Credit Card step if the user's credit card has been breached", () => { expect( getNextGuidedStep({ diff --git a/src/app/functions/server/getRelevantGuidedSteps.ts b/src/app/functions/server/getRelevantGuidedSteps.ts index cc6737df5b..f782badc9a 100644 --- a/src/app/functions/server/getRelevantGuidedSteps.ts +++ b/src/app/functions/server/getRelevantGuidedSteps.ts @@ -145,12 +145,15 @@ export function isEligibleForStep( ): boolean { // Only premium users can see the manual data broker removal flow, once they have run a scan if ( + // TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag enabledFeatureFlags?.includes("EnableRemovalUnderMaintenanceStep") && stepId === "DataBrokerManualRemoval" ) { const dataBrokersRequireManualRemoval = data.latestScanData?.results?.some((result) => { - return isDataBrokerUnderMaintenance(result); + return ( + isDataBrokerUnderMaintenance(result) && !result.manually_resolved + ); }) ?? false; return dataBrokersRequireManualRemoval; @@ -211,8 +214,9 @@ export function hasCompletedStepSection( | "DataBrokerManualRemoval", enabledFeatureFlags?: FeatureFlagName[], ): boolean { - /* c8 ignore next 6 */ + /* c8 ignore next 7 */ if ( + // TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag enabledFeatureFlags?.includes("EnableRemovalUnderMaintenanceStep") && section === "DataBrokerManualRemoval" ) { @@ -260,16 +264,15 @@ export function hasCompletedStep( stepId: StepLink["id"], enabledFeatureFlags?: FeatureFlagName[], ): boolean { - // TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag if ( + // TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag enabledFeatureFlags?.includes("EnableRemovalUnderMaintenanceStep") && stepId === "DataBrokerManualRemoval" ) { return ( data.latestScanData?.results?.every( (result) => - result.broker_status !== "removal_under_maintenance" || - result.manually_resolved, + !isDataBrokerUnderMaintenance(result) || result.manually_resolved, ) ?? false ); }