11import type { Domain } from '@sthrift/domain' ;
22
3- export const ONE_DAY_MS = 86_400_000 ;
3+ export type { TestUserData } from '@sthrift-verification/verification-shared/helpers' ;
4+ export {
5+ makeTestUserData ,
6+ ONE_DAY_MS ,
7+ resolveActorName ,
8+ } from '@sthrift-verification/verification-shared/helpers' ;
9+
410export const DEFAULT_SHARING_PERIOD_DAYS = 30 ;
511
6- // Resolve Gherkin pronoun references to actor names
7- export function resolveActorName ( actorName : string , defaultName = 'Alice' ) : string {
8- return / ^ ( s h e | h e | t h e y ) $ / i. test ( actorName ) ? defaultName : actorName ;
9- }
12+ const ONE_DAY = 86_400_000 ;
1013
1114type ItemListingProps = Domain . Contexts . Listing . ItemListing . ItemListingProps ;
12- type ItemListingEntityReference = Domain . Contexts . Listing . ItemListing . ItemListingEntityReference ;
13- type ReservationRequestProps = Domain . Contexts . ReservationRequest . ReservationRequest . ReservationRequestProps ;
15+ type ItemListingEntityReference =
16+ Domain . Contexts . Listing . ItemListing . ItemListingEntityReference ;
17+ type ReservationRequestProps =
18+ Domain . Contexts . ReservationRequest . ReservationRequest . ReservationRequestProps ;
1419type UserEntityReference = Domain . Contexts . User . UserEntityReference ;
1520type Passport = Domain . Passport ;
1621
1722export function makeTestPassport ( ) : Passport {
18- const alwaysAllow = { determineIf : ( fn : ( p : Record < string , boolean > ) => boolean ) => fn ( new Proxy ( { } , { get : ( ) => true } ) ) } ;
23+ const alwaysAllow = {
24+ determineIf : ( fn : ( permissions : Record < string , boolean > ) => boolean ) =>
25+ fn ( new Proxy ( { } , { get : ( ) => true } ) as Record < string , boolean > ) ,
26+ } ;
27+
1928 return {
2029 listing : { forItemListing : ( ) => alwaysAllow } ,
2130 user : {
@@ -30,28 +39,14 @@ export function makeTestPassport(): Passport {
3039 } as unknown as Passport ;
3140}
3241
33- interface TestUserData {
34- id : string ;
35- email : string ;
36- firstName : string ;
37- lastName : string ;
38- }
39-
40- export function makeTestUserData ( actorName : string , overrides ?: Partial < TestUserData > ) : TestUserData {
41- const defaultId = `test-user-${ actorName . toLowerCase ( ) } ` ;
42- const defaultEmail = `${ actorName . toLowerCase ( ) } @test.com` ;
43- const defaultFirstName = actorName ;
44- const defaultLastName = 'Tester' ;
45-
46- return {
47- id : overrides ?. id ?? defaultId ,
48- email : overrides ?. email ?? defaultEmail ,
49- firstName : overrides ?. firstName ?? defaultFirstName ,
50- lastName : overrides ?. lastName ?? defaultLastName ,
51- } ;
52- }
53-
54- export function makeSharerUser ( overrides : Partial < { id : string ; email : string ; firstName : string ; lastName : string } > = { } ) : UserEntityReference {
42+ export function makeSharerUser (
43+ overrides : Partial < {
44+ id : string ;
45+ email : string ;
46+ firstName : string ;
47+ lastName : string ;
48+ } > = { } ,
49+ ) : UserEntityReference {
5550 return {
5651 id : overrides . id ?? 'test-sharer-1' ,
5752 userType : 'personal-user' ,
@@ -84,9 +79,15 @@ export function makeSharerUser(overrides: Partial<{ id: string; email: string; f
8479 transactions : {
8580 items : [ ] ,
8681 getNewItem : ( ) => ( { } ) ,
87- addItem : ( ) => { /* no-op */ } ,
88- removeItem : ( ) => { /* no-op */ } ,
89- removeAll : ( ) => { /* no-op */ } ,
82+ addItem : ( ) => {
83+ /* no-op */
84+ } ,
85+ removeItem : ( ) => {
86+ /* no-op */
87+ } ,
88+ removeAll : ( ) => {
89+ /* no-op */
90+ } ,
9091 } ,
9192 } ,
9293 } ,
@@ -97,8 +98,11 @@ export function makeSharerUser(overrides: Partial<{ id: string; email: string; f
9798 } as unknown as UserEntityReference ;
9899}
99100
100- export function makeItemListingProps ( overrides : Partial < ItemListingProps > = { } ) : ItemListingProps {
101+ export function makeItemListingProps (
102+ overrides : Partial < ItemListingProps > = { } ,
103+ ) : ItemListingProps {
101104 const sharer = makeSharerUser ( ) ;
105+
102106 return {
103107 id : overrides . id ?? `listing-${ Date . now ( ) } ` ,
104108 sharer,
@@ -107,8 +111,10 @@ export function makeItemListingProps(overrides: Partial<ItemListingProps> = {}):
107111 description : 'Default Description' ,
108112 category : 'Electronics' ,
109113 location : 'Seattle, WA' ,
110- sharingPeriodStart : new Date ( Date . now ( ) + 86_400_000 ) ,
111- sharingPeriodEnd : new Date ( Date . now ( ) + 86_400_000 * 30 ) ,
114+ sharingPeriodStart : new Date ( Date . now ( ) + ONE_DAY ) ,
115+ sharingPeriodEnd : new Date (
116+ Date . now ( ) + ONE_DAY * DEFAULT_SHARING_PERIOD_DAYS ,
117+ ) ,
112118 state : 'Active' ,
113119 images : [ ] ,
114120 sharingHistory : [ ] ,
@@ -121,16 +127,20 @@ export function makeItemListingProps(overrides: Partial<ItemListingProps> = {}):
121127 } as ItemListingProps ;
122128}
123129
124- export function makeListingReference ( overrides : Partial < { id : string ; state : string } > = { } ) : ItemListingEntityReference {
130+ export function makeListingReference (
131+ overrides : Partial < { id : string ; state : string } > = { } ,
132+ ) : ItemListingEntityReference {
125133 return {
126134 id : overrides . id ?? `listing-${ Date . now ( ) } ` ,
127135 sharer : makeSharerUser ( ) ,
128136 title : 'Test Listing' ,
129137 description : 'Test' ,
130138 category : 'Electronics' ,
131139 location : 'Seattle' ,
132- sharingPeriodStart : new Date ( Date . now ( ) + 3_600_000 ) ,
133- sharingPeriodEnd : new Date ( Date . now ( ) + 7_200_000 ) ,
140+ sharingPeriodStart : new Date ( Date . now ( ) + ONE_DAY ) ,
141+ sharingPeriodEnd : new Date (
142+ Date . now ( ) + ONE_DAY * DEFAULT_SHARING_PERIOD_DAYS ,
143+ ) ,
134144 state : overrides . state ?? 'Active' ,
135145 createdAt : new Date ( '2024-01-01' ) ,
136146 updatedAt : new Date ( '2024-01-01' ) ,
@@ -139,11 +149,16 @@ export function makeListingReference(overrides: Partial<{ id: string; state: str
139149 } as ItemListingEntityReference ;
140150}
141151
142- export function makeReservationRequestProps ( overrides : Partial < ReservationRequestProps > = { } ) : ReservationRequestProps {
152+ export function makeReservationRequestProps (
153+ overrides : Partial < ReservationRequestProps > = { } ,
154+ ) : ReservationRequestProps {
143155 const listing = makeListingReference ( ) ;
144156 const reserver = makeSharerUser ( { id : 'reserver-1' } ) ;
145- const tomorrow = new Date ( Date . now ( ) + 86_400_000 ) ;
146- const nextMonth = new Date ( Date . now ( ) + 86_400_000 * 30 ) ;
157+ const tomorrow = new Date ( Date . now ( ) + ONE_DAY ) ;
158+ const nextMonth = new Date (
159+ Date . now ( ) + ONE_DAY * DEFAULT_SHARING_PERIOD_DAYS ,
160+ ) ;
161+
147162 return {
148163 id : overrides . id ?? `rr-${ Date . now ( ) } ` ,
149164 state : 'Requested' ,
0 commit comments