@@ -28,7 +28,25 @@ test("analyzes the example chat without uploading its contents", async ({
2828 page,
2929} ) => {
3030 const requests = [ ] ;
31+ let paypalSdkUrl ;
3132 page . on ( "request" , ( request ) => requests . push ( request ) ) ;
33+ await page . route ( "https://www.paypal.com/sdk/js?**" , async ( route ) => {
34+ paypalSdkUrl = new URL ( route . request ( ) . url ( ) ) ;
35+ await route . fulfill ( {
36+ contentType : "text/javascript" ,
37+ body : `
38+ window.paypal = {
39+ Buttons: () => ({
40+ render: (selector) => {
41+ document.querySelector(selector).innerHTML =
42+ '<button type="button">Pay with PayPal</button>';
43+ return Promise.resolve();
44+ }
45+ })
46+ };
47+ ` ,
48+ } ) ;
49+ } ) ;
3250
3351 await page . locator ( "#uploadmytextfile" ) . setInputFiles ( exampleChat ) ;
3452
@@ -50,6 +68,15 @@ test("analyzes the example chat without uploading its contents", async ({
5068 . getByRole ( "button" , { name : / D o w n l o a d f r e e p r e v i e w P D F / i } )
5169 . click ( ) ;
5270 await downloadPromise ;
71+
72+ await page . getByRole ( "button" , { name : / D o w n l o a d f u l l c h a t P D F / i } ) . click ( ) ;
73+ await expect ( page . getByText ( "Nice!!" , { exact : true } ) ) . toBeVisible ( ) ;
74+ await expect (
75+ page . getByRole ( "button" , { name : "Pay with PayPal" } )
76+ ) . toBeVisible ( ) ;
77+ expect ( paypalSdkUrl . origin ) . toBe ( "https://www.paypal.com" ) ;
78+ expect ( paypalSdkUrl . searchParams . get ( "currency" ) ) . toBe ( "EUR" ) ;
79+ expect ( paypalSdkUrl . searchParams . get ( "client-id" ) ) . toBeTruthy ( ) ;
5380} ) ;
5481
5582test ( "switches to a localized route" , async ( { page } ) => {
@@ -61,6 +88,46 @@ test("switches to a localized route", async ({ page }) => {
6188 ) . toBeVisible ( ) ;
6289} ) ;
6390
91+ test ( "starts a subscription through the Firebase PayPal endpoint" , async ( {
92+ page,
93+ } ) => {
94+ let functionRequest ;
95+ await page . route ( "**/helloworld" , async ( route ) => {
96+ const request = route . request ( ) ;
97+ if ( request . method ( ) === "OPTIONS" ) {
98+ await route . fulfill ( {
99+ status : 204 ,
100+ headers : {
101+ "access-control-allow-origin" : "*" ,
102+ "access-control-allow-headers" : "content-type" ,
103+ } ,
104+ } ) ;
105+ return ;
106+ }
107+
108+ functionRequest = request ;
109+ await route . fulfill ( {
110+ contentType : "application/json" ,
111+ headers : { "access-control-allow-origin" : "*" } ,
112+ body : JSON . stringify ( {
113+ data : { approveLink : "https://paypal.test/approve" } ,
114+ } ) ,
115+ } ) ;
116+ } ) ;
117+ await page . route ( "https://paypal.test/approve" , ( route ) =>
118+ route . fulfill ( { contentType : "text/html" , body : "PayPal approval" } )
119+ ) ;
120+
121+ await page . goto ( "/subscribe" ) ;
122+ await page . getByRole ( "button" , { name : "Subscribe Now" } ) . click ( ) ;
123+
124+ await expect ( page ) . toHaveURL ( "https://paypal.test/approve" ) ;
125+ expect ( functionRequest . url ( ) ) . toBe (
126+ "https://us-central1-whatsanalyze-80665.cloudfunctions.net/helloworld"
127+ ) ;
128+ expect ( functionRequest . postDataJSON ( ) . data . client_id ) . toBeTruthy ( ) ;
129+ } ) ;
130+
64131test ( "renders migrated markdown content" , async ( { page } ) => {
65132 await page . goto ( "/how-to-export-your-whatsapp-chat" ) ;
66133
0 commit comments