@@ -7,29 +7,33 @@ import { articleContent, articleExcerpt } from "./utils";
77dotenv . config ( ) ; // Load .env file contents into process.env
88
99export const setup = async ( ) => {
10+ // Dynamically import nanoid
11+ const { nanoid } = await import ( "nanoid" ) ;
12+
1013 if (
1114 ! process . env . DATABASE_URL ||
1215 ! process . env . E2E_USER_ONE_ID ||
1316 ! process . env . E2E_USER_TWO_ID
1417 ) {
1518 throw new Error ( "Missing env variables for DB clean up script" ) ;
1619 }
20+
1721 const db = drizzle ( postgres ( process . env . DATABASE_URL as string ) ) ;
1822
1923 const addE2EArticleAndComment = async (
2024 authorId : string ,
2125 commenterId : string ,
2226 ) => {
23- const publishedPostId = "1nFnMmN1" ;
24- const scheduledPostId = "1nFnMmN2" ;
25- const draftPostId = "1nFnMmN3" ;
27+ const publishedPostId = nanoid ( 8 ) ;
28+ const scheduledPostId = nanoid ( 8 ) ;
29+ const draftPostId = nanoid ( 8 ) ;
2630 const now = new Date ( ) . toISOString ( ) ;
2731
2832 const oneYearFromToday = new Date ( now ) ;
2933 oneYearFromToday . setFullYear ( oneYearFromToday . getFullYear ( ) + 1 ) ;
3034
3135 await Promise . all ( [
32- await db
36+ db
3337 . insert ( post )
3438 . values ( {
3539 id : publishedPostId ,
@@ -46,10 +50,10 @@ export const setup = async () => {
4650 . onConflictDoNothing ( )
4751 . returning ( ) ,
4852
49- await db
53+ db
5054 . insert ( post )
5155 . values ( {
52- id : scheduledPostId ,
56+ id : draftPostId ,
5357 published : null ,
5458 excerpt : articleExcerpt ,
5559 updatedAt : now ,
@@ -63,10 +67,10 @@ export const setup = async () => {
6367 . onConflictDoNothing ( )
6468 . returning ( ) ,
6569
66- await db
70+ db
6771 . insert ( post )
6872 . values ( {
69- id : draftPostId ,
73+ id : scheduledPostId ,
7074 published : oneYearFromToday . toISOString ( ) ,
7175 excerpt : articleExcerpt ,
7276 updatedAt : now ,
0 commit comments