@@ -150,3 +150,56 @@ describe('GET /:id/profile-image', () => {
150150 . expect ( 'Location' , fallbackImages . avatar ) ;
151151 } ) ;
152152} ) ;
153+
154+ describe ( 'GET /mobile' , ( ) => {
155+ const androidUA =
156+ 'Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36' ;
157+ const iosUA =
158+ 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1' ;
159+
160+ it ( 'should redirect to Play Store for Android' , async ( ) => {
161+ const res = await request ( app . server )
162+ . get ( '/mobile' )
163+ . set ( 'User-Agent' , androidUA )
164+ . expect ( 307 ) ;
165+
166+ expect ( res . headers . location ) . toContain ( 'play.google.com' ) ;
167+ } ) ;
168+
169+ it ( 'should redirect to App Store for iOS' , async ( ) => {
170+ const res = await request ( app . server )
171+ . get ( '/mobile' )
172+ . set ( 'User-Agent' , iosUA )
173+ . expect ( 307 ) ;
174+
175+ expect ( res . headers . location ) . toContain ( 'apps.apple.com' ) ;
176+ } ) ;
177+
178+ it ( 'should redirect logged-in user to webapp by default' , async ( ) => {
179+ await saveFixtures ( con , User , [ { id : '1' , username : 'test' } ] ) ;
180+
181+ const res = await request ( app . server )
182+ . get ( '/mobile' )
183+ . set ( 'User-Agent' , androidUA )
184+ . set ( 'authorization' , `Service ${ process . env . ACCESS_SECRET } ` )
185+ . set ( 'user-id' , '1' )
186+ . set ( 'logged-in' , 'true' )
187+ . expect ( 307 ) ;
188+
189+ expect ( res . headers . location ) . toBe ( 'https://app.daily.dev' ) ;
190+ } ) ;
191+
192+ it ( 'should skip auth redirect when auth=0' , async ( ) => {
193+ await saveFixtures ( con , User , [ { id : '1' , username : 'test' } ] ) ;
194+
195+ const res = await request ( app . server )
196+ . get ( '/mobile?auth=0' )
197+ . set ( 'User-Agent' , androidUA )
198+ . set ( 'authorization' , `Service ${ process . env . ACCESS_SECRET } ` )
199+ . set ( 'user-id' , '1' )
200+ . set ( 'logged-in' , 'true' )
201+ . expect ( 307 ) ;
202+
203+ expect ( res . headers . location ) . toContain ( 'play.google.com' ) ;
204+ } ) ;
205+ } ) ;
0 commit comments