@@ -39,8 +39,8 @@ describe('OAuthConsent', () => {
3939 writable : true ,
4040 value : {
4141 ...originalLocation ,
42- search : '?client_id=client_test' ,
43- href : 'https://app.example/?client_id=client_test' ,
42+ search : '?client_id=client_test&redirect_uri=https%3A%2F%2Fapp.example%2Fcallback ' ,
43+ href : 'https://app.example/?client_id=client_test&redirect_uri=https%3A%2F%2Fapp.example%2Fcallback ' ,
4444 } ,
4545 } ) ;
4646 } ) ;
@@ -237,4 +237,74 @@ describe('OAuthConsent', () => {
237237 getByText ( 'Allow' ) . click ( ) ;
238238 expect ( onAllowSpy ) . toHaveBeenCalledTimes ( 1 ) ;
239239 } ) ;
240+
241+ it ( 'shows missing client_id error in the public flow' , async ( ) => {
242+ Object . defineProperty ( window , 'location' , {
243+ configurable : true ,
244+ writable : true ,
245+ value : {
246+ ...window . location ,
247+ search : '' ,
248+ href : 'https://app.example/' ,
249+ } ,
250+ } ) ;
251+
252+ const { wrapper, fixtures, props } = await createFixtures ( f => {
253+ f . withUser ( { email_addresses : [ 'jane@example.com' ] } ) ;
254+ } ) ;
255+
256+ mockOAuthApplication ( fixtures . clerk , { getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfo ) } ) ;
257+
258+ props . setProps ( { componentName : 'OAuthConsent' } as any ) ;
259+
260+ const { getByText } = render ( < OAuthConsent /> , { wrapper } ) ;
261+
262+ await waitFor ( ( ) => {
263+ expect ( getByText ( / c l i e n t I D i s m i s s i n g / i) ) . toBeVisible ( ) ;
264+ } ) ;
265+ } ) ;
266+
267+ it ( 'shows missing redirect_uri error in the public flow' , async ( ) => {
268+ Object . defineProperty ( window , 'location' , {
269+ configurable : true ,
270+ writable : true ,
271+ value : {
272+ ...window . location ,
273+ search : '?client_id=client_test' ,
274+ href : 'https://app.example/?client_id=client_test' ,
275+ } ,
276+ } ) ;
277+
278+ const { wrapper, fixtures, props } = await createFixtures ( f => {
279+ f . withUser ( { email_addresses : [ 'jane@example.com' ] } ) ;
280+ } ) ;
281+
282+ mockOAuthApplication ( fixtures . clerk , { getConsentInfo : vi . fn ( ) . mockResolvedValue ( fakeConsentInfo ) } ) ;
283+
284+ props . setProps ( { componentName : 'OAuthConsent' } as any ) ;
285+
286+ const { getByText } = render ( < OAuthConsent /> , { wrapper } ) ;
287+
288+ await waitFor ( ( ) => {
289+ expect ( getByText ( / r e d i r e c t U R I i s m i s s i n g / i) ) . toBeVisible ( ) ;
290+ } ) ;
291+ } ) ;
292+
293+ it ( 'shows error message when the consent fetch fails in the public flow' , async ( ) => {
294+ const { wrapper, fixtures, props } = await createFixtures ( f => {
295+ f . withUser ( { email_addresses : [ 'jane@example.com' ] } ) ;
296+ } ) ;
297+
298+ mockOAuthApplication ( fixtures . clerk , {
299+ getConsentInfo : vi . fn ( ) . mockRejectedValue ( new Error ( 'Invalid OAuth client' ) ) ,
300+ } ) ;
301+
302+ props . setProps ( { componentName : 'OAuthConsent' } as any ) ;
303+
304+ const { getByText } = render ( < OAuthConsent /> , { wrapper } ) ;
305+
306+ await waitFor ( ( ) => {
307+ expect ( getByText ( / I n v a l i d O A u t h c l i e n t / i) ) . toBeVisible ( ) ;
308+ } ) ;
309+ } ) ;
240310} ) ;
0 commit comments