11import { spawn , ChildProcess } from 'child_process' ;
22import { writeFile } from 'fs/promises' ;
3+ import { chromium } from 'playwright' ;
34import path from 'path' ;
45
56let serverProcess : ChildProcess ;
@@ -217,16 +218,28 @@ async function extractActivationLinkFromLogs(): Promise<string> {
217218}
218219
219220async function activateUser ( activationUrl : string ) : Promise < void > {
220- // Visit the activation URL directly (like a user clicking the email link)
221- const response = await fetch ( activationUrl , {
222- method : 'GET' ,
223- redirect : 'follow'
224- } ) ;
221+ // Use Playwright to visit the activation page and click the Activate button
222+ const browser = await chromium . launch ( { headless : true } ) ;
223+ const page = await browser . newPage ( ) ;
225224
226- if ( ! response . ok ) {
227- throw new Error ( `Activation failed: ${ response . status } ${ response . statusText } ` ) ;
225+ try {
226+ // Navigate to the activation URL
227+ await page . goto ( activationUrl ) ;
228+ await page . waitForLoadState ( 'networkidle' ) ;
229+
230+ // Look for and click the Activate button
231+ await page . click ( 'button:has-text("Activate")' ) ;
232+
233+ // Wait for any processing to complete
234+ await page . waitForLoadState ( 'networkidle' ) ;
235+
236+ // Give the activation time to process in the database
237+ await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
238+
239+ console . log ( 'Successfully clicked Activate button' ) ;
240+ } catch ( error ) {
241+ throw new Error ( `Activation failed: ${ error . message } ` ) ;
242+ } finally {
243+ await browser . close ( ) ;
228244 }
229-
230- // Give the activation time to process in the database
231- await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
232245}
0 commit comments