@@ -11,44 +11,48 @@ const getPadIdFromUrl = (url: string) => {
1111 return match [ 1 ] ;
1212} ;
1313
14+ const absoluteUrl = ( pageUrl : string , path : string ) => new URL ( path , pageUrl ) . toString ( ) ;
15+
1416test . describe ( 'ep_post_data' , ( ) => {
1517 test ( 'pad loads with plugin installed' , async ( { page} ) => {
1618 const padBody = await getPadBody ( page ) ;
1719 await expect ( padBody ) . toBeVisible ( ) ;
1820 } ) ;
1921
2022 test ( 'PATCH /post appends text to an existing pad' , async ( { page} ) => {
21- const padId = getPadIdFromUrl ( page . url ( ) ) ;
23+ const pageUrl = page . url ( ) ;
24+ const padId = getPadIdFromUrl ( pageUrl ) ;
25+ const postUrl = absoluteUrl ( pageUrl , '/post' ) ;
2226
23- const postResponse = await page . request . fetch ( '/post' , {
24- method : 'POST' ,
27+ const postResponse = await page . request . post ( postUrl , {
2528 headers : { 'X-PAD-ID' : padId } ,
2629 data : 'first' ,
2730 } ) ;
2831 expect ( postResponse . ok ( ) ) . toBeTruthy ( ) ;
2932
30- const patchResponse = await page . request . fetch ( '/post' , {
33+ const patchResponse = await page . request . fetch ( postUrl , {
3134 method : 'PATCH' ,
3235 headers : { 'X-PAD-ID' : padId } ,
3336 data : ' second' ,
3437 } ) ;
3538 expect ( patchResponse . ok ( ) ) . toBeTruthy ( ) ;
3639
37- const txtResponse = await page . request . get ( `/p/${ padId } /export/txt` ) ;
40+ const txtResponse = await page . request . get ( absoluteUrl ( pageUrl , `/p/${ padId } /export/txt` ) ) ;
3841 expect ( txtResponse . ok ( ) ) . toBeTruthy ( ) ;
3942 expect ( ( await txtResponse . text ( ) ) . trimEnd ( ) ) . toBe ( 'first second' ) ;
4043 } ) ;
4144
4245 test ( 'PATCH /post creates pad when it does not exist' , async ( { page} ) => {
46+ const pageUrl = page . url ( ) ;
4347 const padId = `ep-post-data-${ Date . now ( ) . toString ( 36 ) } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 10 ) } ` ;
44- const patchResponse = await page . request . fetch ( '/post' , {
48+ const patchResponse = await page . request . fetch ( absoluteUrl ( pageUrl , '/post' ) , {
4549 method : 'PATCH' ,
4650 headers : { 'X-PAD-ID' : padId } ,
4751 data : 'created via patch' ,
4852 } ) ;
4953 expect ( patchResponse . ok ( ) ) . toBeTruthy ( ) ;
5054
51- const txtResponse = await page . request . get ( `/p/${ padId } /export/txt` ) ;
55+ const txtResponse = await page . request . get ( absoluteUrl ( pageUrl , `/p/${ padId } /export/txt` ) ) ;
5256 expect ( txtResponse . ok ( ) ) . toBeTruthy ( ) ;
5357 expect ( ( await txtResponse . text ( ) ) . trimEnd ( ) ) . toBe ( 'created via patch' ) ;
5458 } ) ;
0 commit comments