Skip to content

Commit

Permalink
add more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codemist committed Dec 18, 2024
1 parent 846f431 commit 12e8dbf
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/app/components/server/StatusPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const getExposureStatus = (
const additionalRemovalStatusesEnabled = enabledFeatureFlags.includes(
"AdditionalRemovalStatuses",
);
// TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag
const manualRemovalEnabled = enabledFeatureFlags.includes(
"EnableRemovalUnderMaintenanceStep",
);
Expand Down
211 changes: 209 additions & 2 deletions src/app/functions/server/getRelevantGuidedSteps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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: "[email protected]",
},
}).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: "[email protected]" },
},
"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: "[email protected]" },
},
"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: "[email protected]" },
},
"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: "[email protected]" },
},
"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: "[email protected]" },
},
"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: "[email protected]" },
},
"DataBrokerManualRemoval",
["EnableRemovalUnderMaintenanceStep"],
),
).toBe(true);
});

it("links to the Credit Card step if the user's credit card has been breached", () => {
expect(
getNextGuidedStep({
Expand Down
13 changes: 8 additions & 5 deletions src/app/functions/server/getRelevantGuidedSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
) {
Expand Down Expand Up @@ -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
);
}
Expand Down

0 comments on commit 12e8dbf

Please sign in to comment.