Skip to content

Commit b831576

Browse files
committed
fix filterexposures component
1 parent 1643c55 commit b831576

File tree

2 files changed

+9
-86
lines changed

2 files changed

+9
-86
lines changed

src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/filterExposures.test.ts

Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
import { it, expect } from "@jest/globals";
6-
import {
7-
createRandomBreach,
8-
createRandomScanResult,
9-
} from "../../../../../../../apiMocks/mockData";
6+
import { createRandomBreach } from "../../../../../../../apiMocks/mockData";
107
import { filterExposures } from "./filterExposures";
118
import { CONST_DAY_MILLISECONDS } from "../../../../../../../constants";
129
jest.mock("../../../../../../hooks/useTelemetry");
@@ -30,33 +27,12 @@ const breachOld = createRandomBreach({
3027
addedDate: getDateDaysAgo(1000),
3128
});
3229

33-
const scanResultThisWeek = createRandomScanResult({
34-
fakerSeed: 1234,
35-
createdDate: getDateDaysAgo(2),
36-
});
37-
const scanResultThisMonth = createRandomScanResult({
38-
fakerSeed: 1234,
39-
createdDate: getDateDaysAgo(10),
40-
});
41-
const scanResultThisYear = createRandomScanResult({
42-
fakerSeed: 1234,
43-
createdDate: getDateDaysAgo(100),
44-
});
45-
const scanResultOld = createRandomScanResult({
46-
fakerSeed: 1234,
47-
createdDate: getDateDaysAgo(1000),
48-
});
49-
5030
it("doesn't filter out anything by default", () => {
5131
const exposures = [
5232
breachThisWeek,
53-
scanResultThisWeek,
5433
breachThisMonth,
55-
scanResultThisMonth,
5634
breachThisYear,
57-
scanResultThisYear,
5835
breachOld,
59-
scanResultOld,
6036
];
6137

6238
expect(
@@ -70,38 +46,25 @@ it("doesn't filter out anything by default", () => {
7046
it("can filter out breaches", () => {
7147
const exposures = [
7248
breachThisWeek,
73-
scanResultThisWeek,
7449
breachThisMonth,
75-
scanResultThisMonth,
7650
breachThisYear,
77-
scanResultThisYear,
7851
breachOld,
79-
scanResultOld,
8052
];
8153

8254
expect(
8355
filterExposures(exposures, {
8456
dateFound: "show-all-date-found",
8557
exposureType: "data-broker",
8658
}),
87-
).toStrictEqual([
88-
scanResultThisWeek,
89-
scanResultThisMonth,
90-
scanResultThisYear,
91-
scanResultOld,
92-
]);
59+
).toStrictEqual([]);
9360
});
9461

9562
it("can filter out data brokers", () => {
9663
const exposures = [
9764
breachThisWeek,
98-
scanResultThisWeek,
9965
breachThisMonth,
100-
scanResultThisMonth,
10166
breachThisYear,
102-
scanResultThisYear,
10367
breachOld,
104-
scanResultOld,
10568
];
10669

10770
expect(
@@ -115,85 +78,57 @@ it("can filter out data brokers", () => {
11578
it("can filter out exposures older than a year", () => {
11679
const exposures = [
11780
breachThisWeek,
118-
scanResultThisWeek,
11981
breachThisMonth,
120-
scanResultThisMonth,
12182
breachThisYear,
122-
scanResultThisYear,
12383
breachOld,
124-
scanResultOld,
12584
];
12685

12786
expect(
12887
filterExposures(exposures, {
12988
dateFound: "last-year",
13089
exposureType: "show-all-exposure-type",
13190
}),
132-
).toStrictEqual([
133-
breachThisWeek,
134-
scanResultThisWeek,
135-
breachThisMonth,
136-
scanResultThisMonth,
137-
breachThisYear,
138-
scanResultThisYear,
139-
]);
91+
).toStrictEqual([breachThisWeek, breachThisMonth, breachThisYear]);
14092
});
14193

14294
it("can filter out exposures older than a month", () => {
14395
const exposures = [
14496
breachThisWeek,
145-
scanResultThisWeek,
14697
breachThisMonth,
147-
scanResultThisMonth,
14898
breachThisYear,
149-
scanResultThisYear,
15099
breachOld,
151-
scanResultOld,
152100
];
153101

154102
expect(
155103
filterExposures(exposures, {
156104
dateFound: "thirty-days",
157105
exposureType: "show-all-exposure-type",
158106
}),
159-
).toStrictEqual([
160-
breachThisWeek,
161-
scanResultThisWeek,
162-
breachThisMonth,
163-
scanResultThisMonth,
164-
]);
107+
).toStrictEqual([breachThisWeek, breachThisMonth]);
165108
});
166109

167110
it("can filter out exposures older than a week", () => {
168111
const exposures = [
169112
breachThisWeek,
170-
scanResultThisWeek,
171113
breachThisMonth,
172-
scanResultThisMonth,
173114
breachThisYear,
174-
scanResultThisYear,
175115
breachOld,
176-
scanResultOld,
177116
];
178117

179118
expect(
180119
filterExposures(exposures, {
181120
dateFound: "seven-days",
182121
exposureType: "show-all-exposure-type",
183122
}),
184-
).toStrictEqual([breachThisWeek, scanResultThisWeek]);
123+
).toStrictEqual([breachThisWeek]);
185124
});
186125

187126
it("filters out anything that doesn't match *all* filters", () => {
188127
const exposures = [
189128
breachThisWeek,
190-
scanResultThisWeek,
191129
breachThisMonth,
192-
scanResultThisMonth,
193130
breachThisYear,
194-
scanResultThisYear,
195131
breachOld,
196-
scanResultOld,
197132
];
198133

199134
expect(

src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/filterExposures.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,16 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import {
6-
Exposure,
7-
isScanResult,
8-
} from "../../../../../../components/client/exposure_card/ExposureCard";
95
import { FilterState } from "../../../../../../components/client/ExposuresFilter";
106
import { CONST_DAY_MILLISECONDS } from "../../../../../../../constants";
7+
import { SubscriberBreach } from "../../../../../../../utils/subscriberBreaches";
118

129
export function filterExposures(
13-
exposures: Exposure[],
10+
exposures: SubscriberBreach[],
1411
filters: FilterState,
15-
): Exposure[] {
12+
): SubscriberBreach[] {
1613
return exposures.filter((exposure) => {
17-
if (filters.exposureType === "data-breach" && isScanResult(exposure)) {
18-
return false;
19-
}
20-
if (filters.exposureType === "data-broker" && !isScanResult(exposure)) {
21-
return false;
22-
}
23-
24-
const exposureDate = isScanResult(exposure)
25-
? new Date(exposure.created_at)
26-
: new Date(exposure.addedDate);
14+
const exposureDate = new Date(exposure.addedDate);
2715

2816
if (
2917
filters.dateFound === "seven-days" &&

0 commit comments

Comments
 (0)