33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
55import { faker } from "@faker-js/faker" ;
6- import { AudienceRow , OnerepScanResultDataBrokerRow } from "knex/types/tables" ;
7- import {
8- RemovalStatus ,
9- RemovalStatusMap ,
10- } from "../app/functions/universal/scanResult" ;
11- import { StateAbbr } from "../utils/states" ;
6+ import { AudienceRow } from "knex/types/tables" ;
127import {
138 BreachDataTypes ,
149 HighRiskDataTypes ,
@@ -20,90 +15,8 @@ import {
2015import { Session } from "next-auth" ;
2116import { HibpLikeDbBreach } from "../utils/hibp" ;
2217import { SerializedSubscriber } from "../next-auth" ;
23- import { DataBrokerRemovalStatus } from "../app/functions/universal/dataBroker" ;
2418import { UserAnnouncementWithDetails } from "../db/tables/user_announcements" ;
2519
26- // Setting this to a constant value produces the same result when the same methods
27- // with the same version of faker are called.
28- // @see https://faker.readthedocs.io/en/master/index.html#seeding-the-generator
29- const fakerSeed = 123 ;
30-
31- // This is a full list of scan results, all pages, and would normally be
32- // stored in the `onerep_scan_results` table.
33- export function mockedOneRepScanResults ( ) {
34- faker . seed ( fakerSeed ) ;
35- return {
36- data : Array . from ( { length : 3 } , ( ) => createRandomScanResult ( ) ) ,
37- } ;
38- }
39-
40- export type RandomScanResultOptions = Partial < {
41- createdDate : Date ;
42- fakerSeed : number ;
43- status : RemovalStatus ;
44- manually_resolved : boolean ;
45- broker_status : DataBrokerRemovalStatus ;
46- data_broker : string ;
47- url : OnerepScanResultDataBrokerRow [ "url" ] ;
48- updated_at : Date ;
49- } > ;
50-
51- /**
52- * Generates scan result with randomly-generated mock data.
53- *
54- * @param options
55- * @returns A single scan result.
56- */
57- export function createRandomScanResult (
58- options : RandomScanResultOptions = { } ,
59- ) : OnerepScanResultDataBrokerRow {
60- faker . seed ( options . fakerSeed ) ;
61- const optout_attempts =
62- options . status === "waiting_for_verification"
63- ? faker . number . int ( { min : 1 , max : 42 } )
64- : undefined ;
65- const url = options . url ?? faker . internet . url ( ) ;
66- return {
67- id : faker . number . int ( ) ,
68- onerep_scan_result_id : faker . number . int ( ) ,
69- onerep_scan_id : faker . number . int ( ) ,
70- first_name : faker . person . firstName ( ) ,
71- last_name : faker . person . lastName ( ) ,
72- middle_name : faker . person . middleName ( ) ,
73- age : faker . number . int ( { min : 14 , max : 120 } ) ,
74- status :
75- options . status ??
76- ( faker . helpers . arrayElement (
77- Object . values ( RemovalStatusMap ) ,
78- ) as RemovalStatus ) ,
79- manually_resolved : options . manually_resolved ?? faker . datatype . boolean ( ) ,
80- addresses : Array . from ( { length : 3 } , ( ) => ( {
81- zip : faker . location . zipCode ( ) ,
82- city : faker . location . city ( ) ,
83- state : faker . location . state ( { abbreviated : true } ) as StateAbbr ,
84- street : faker . location . street ( ) ,
85- } ) ) ,
86- phones : [ faker . phone . number ( ) ] ,
87- emails : [ faker . internet . exampleEmail ( ) ] ,
88- relatives : Array . from ( { length : 3 } , ( ) => faker . person . fullName ( ) ) ,
89- link : url ,
90- data_broker : options . data_broker ?? new URL ( url ) . hostname ,
91- data_broker_id : faker . number . int ( ) ,
92- created_at : options . createdDate ?? faker . date . recent ( { days : 2 } ) ,
93- updated_at : options . updated_at ?? faker . date . recent ( { days : 1 } ) ,
94- optout_attempts,
95- last_optout_at :
96- typeof optout_attempts === "number" && optout_attempts > 0
97- ? faker . date . recent ( { days : 3 } )
98- : undefined ,
99- broker_status : options . broker_status ?? "active" ,
100- scan_result_status : faker . helpers . arrayElement (
101- Object . values ( RemovalStatusMap ) ,
102- ) as RemovalStatus ,
103- url : url ,
104- } ;
105- }
106-
10720export type RandomAnnouncementOptions = Partial < {
10821 status : string ;
10922 audience : AudienceRow ;
@@ -188,7 +101,7 @@ export function createRandomBreach(
188101 } ;
189102}
190103
191- export function createUserWithPremiumSubscription ( ) : Session [ "user" ] {
104+ export function createRandomUser ( ) : Session [ "user" ] {
192105 return {
193106194107 fxa : {
@@ -197,7 +110,7 @@ export function createUserWithPremiumSubscription(): Session["user"] {
197110 metricsEnabled : false ,
198111 avatar : "https://profile.stage.mozaws.net/v1/avatar/e" ,
199112 avatarDefault : true ,
200- subscriptions : [ "monitor" ] ,
113+ subscriptions : [ ] ,
201114 } ,
202115 subscriber : {
203116 id : 42 ,
0 commit comments