@@ -10,11 +10,19 @@ import postgres from "postgres";
1010
1111const DATABASE_URL = process . env . DATABASE_URL || "" ;
1212// These can be removed in a follow on PR. Until this hits main we cant add E2E_USER_* stuff to the env.
13- const E2E_SESSION_ID =
13+ const E2E_USER_ONE_SESSION_ID =
1414 process . env . E2E_USER_ONE_SESSION_ID || "df8a11f2-f20a-43d6-80a0-a213f1efedc1" ;
15- const E2E_USER_ID =
16- process . env . E2E_USER_ID || "8e3179ce-f32b-4d0a-ba3b-234d66b836ad" ;
17- const E2E_USER_EMAIL = process . env . E2E_USER_EMAIL || "[email protected] " ; 15+ const E2E_USER_ONE_ID =
16+ process . env . E2E_USER_ONE_ID || "8e3179ce-f32b-4d0a-ba3b-234d66b836ad" ;
17+ const E2E_USER_ONE_EMAIL =
18+ process . env . E2E_USER_ONE_EMAIL || "[email protected] " ; 19+
20+ const E2E_USER_TWO_SESSION_ID =
21+ process . env . E2E_USER_TWO_SESSION_ID || "10134766-bc6c-4b52-83d7-46ec0a4cb95d" ;
22+ const E2E_USER_TWO_ID =
23+ process . env . E2E_USER_TWO_ID || "a15a104a-0e34-4101-8800-ed25c9231345" ;
24+ const E2E_USER_TWO_EMAIL =
25+ process . env . E2E_USER_TWO_EMAIL || "[email protected] " ; 1826
1927if ( ! DATABASE_URL ) {
2028 throw new Error ( "DATABASE_URL is not set" ) ;
@@ -116,27 +124,25 @@ ${chance.paragraph()}
116124 return users ;
117125 } ;
118126
119- const seedE2EUser = async ( ) => {
120- const name = "E2E Test User" ;
121-
127+ const seedE2EUser = async ( email : string , id : string , name : string ) => {
122128 const [ existingE2EUser ] = await db
123129 . selectDistinct ( )
124130 . from ( user )
125- . where ( eq ( user . id , E2E_USER_ID ) ) ;
131+ . where ( eq ( user . id , id ) ) ;
126132
127133 if ( existingE2EUser ) {
128134 console . log ( "E2E Test user already exists. Skipping creation" ) ;
129135 return existingE2EUser ;
130136 }
131137
132138 const userData = {
133- id : E2E_USER_ID ,
139+ id : id ,
134140 username : `${ name . split ( " " ) . join ( "-" ) . toLowerCase ( ) } -${ chance . integer ( {
135141 min : 0 ,
136142 max : 999 ,
137143 } ) } `,
138144 name,
139- email : E2E_USER_EMAIL ,
145+ email,
140146 image : `https://robohash.org/${ encodeURIComponent ( name ) } ?bgset=bg1` ,
141147 location : chance . country ( { full : true } ) ,
142148 bio : chance . sentence ( { words : 10 } ) ,
@@ -146,11 +152,11 @@ ${chance.paragraph()}
146152 return createdUser ;
147153 } ;
148154
149- const seedE2EUserSession = async ( userId : string ) => {
155+ const seedE2EUserSession = async ( userId : string , sessionToken : string ) => {
150156 const [ existingE2EUserSession ] = await db
151157 . selectDistinct ( )
152158 . from ( session )
153- . where ( eq ( session . sessionToken , E2E_SESSION_ID ) ) ;
159+ . where ( eq ( session . sessionToken , sessionToken ) ) ;
154160
155161 if ( existingE2EUserSession ) {
156162 console . log ( "E2E Test session already exists. Skipping creation" ) ;
@@ -164,7 +170,7 @@ ${chance.paragraph()}
164170 . insert ( session )
165171 . values ( {
166172 userId,
167- sessionToken : E2E_SESSION_ID ,
173+ sessionToken,
168174 // Set session to expire in 6 months.
169175 expires : new Date ( currentDate . setMonth ( currentDate . getMonth ( ) + 6 ) ) ,
170176 } )
@@ -249,8 +255,19 @@ ${chance.paragraph()}
249255
250256 try {
251257 await addUserData ( ) ;
252- const user = await seedE2EUser ( ) ;
253- await seedE2EUserSession ( user . id ) ;
258+ const userOne = await seedE2EUser (
259+ E2E_USER_ONE_EMAIL ,
260+ E2E_USER_ONE_ID ,
261+ "E2E Test User One" ,
262+ ) ;
263+ const userTwo = await seedE2EUser (
264+ E2E_USER_TWO_EMAIL ,
265+ E2E_USER_TWO_ID ,
266+ "E2E Test User Two" ,
267+ ) ;
268+
269+ await seedE2EUserSession ( userOne . id , E2E_USER_ONE_SESSION_ID ) ;
270+ await seedE2EUserSession ( userTwo . id , E2E_USER_TWO_SESSION_ID ) ;
254271 } catch ( error ) {
255272 console . log ( "Error:" , error ) ;
256273 }
0 commit comments