@@ -312,3 +312,104 @@ describe('W3SSdk > Apple OAuth', () => {
312312 expect ( handleLoginFailureSpy ) . toHaveBeenCalledTimes ( 1 )
313313 } )
314314} )
315+
316+ describe ( 'W3SSdk > Google OAuth > selectAccountPrompt is true' , ( ) => {
317+ let sdk : W3SSdk
318+ const configs : Configs = {
319+ appSettings : {
320+ appId : 'test-app-id' ,
321+ } ,
322+ loginConfigs : {
323+ deviceToken : 'device-token' ,
324+ deviceEncryptionKey : 'device-encryption-key' ,
325+ google : {
326+ clientId : 'test-client-id' ,
327+ redirectUri : 'test-redirect-uri' ,
328+ selectAccountPrompt : true ,
329+ } ,
330+ } ,
331+ }
332+
333+ beforeEach ( ( ) => {
334+ ; ( W3SSdk as any ) . instance = null
335+ jest . resetAllMocks ( )
336+
337+ const onLoginComplete = jest . fn ( )
338+ sdk = new W3SSdk ( configs , onLoginComplete )
339+ } )
340+
341+ it ( 'should generate the right parameters' , async ( ) => {
342+ const performGoogleLoginSpy = jest . spyOn ( sdk as any , 'performGoogleLogin' )
343+
344+ const generateOauthUrlWithParamsSpy = jest . spyOn (
345+ sdk as any ,
346+ 'generateOauthUrlWithParams' ,
347+ )
348+
349+ await sdk . performLogin ( SocialLoginProvider . GOOGLE )
350+
351+ expect ( performGoogleLoginSpy ) . toHaveBeenCalled ( )
352+ expect ( generateOauthUrlWithParamsSpy ) . toHaveBeenLastCalledWith (
353+ 'Google' ,
354+ 'test-client-id' ,
355+ 'test-redirect-uri' ,
356+ true ,
357+ )
358+ } )
359+
360+ it ( 'should update the global this location href correctly' , async ( ) => {
361+ await sdk . performLogin ( SocialLoginProvider . GOOGLE )
362+
363+ expect ( window . location . href ) . toContain ( 'prompt=select_account' )
364+ } )
365+ } )
366+
367+ describe ( 'W3SSdk > Google OAuth > selectAccountPrompt is false or empty' , ( ) => {
368+ let sdk : W3SSdk
369+ const configs : Configs = {
370+ appSettings : {
371+ appId : 'test-app-id' ,
372+ } ,
373+ loginConfigs : {
374+ deviceToken : 'device-token' ,
375+ deviceEncryptionKey : 'device-encryption-key' ,
376+ google : {
377+ clientId : 'test-client-id' ,
378+ redirectUri : 'test-redirect-uri' ,
379+ } ,
380+ } ,
381+ }
382+
383+ beforeEach ( ( ) => {
384+ ; ( W3SSdk as any ) . instance = null
385+ jest . resetAllMocks ( )
386+
387+ const onLoginComplete = jest . fn ( )
388+ sdk = new W3SSdk ( configs , onLoginComplete )
389+ } )
390+
391+ it ( 'should generate the right parameters' , async ( ) => {
392+ const performGoogleLoginSpy = jest . spyOn ( sdk as any , 'performGoogleLogin' )
393+
394+ const generateOauthUrlWithParamsSpy = jest . spyOn (
395+ sdk as any ,
396+ 'generateOauthUrlWithParams' ,
397+ )
398+
399+ await sdk . performLogin ( SocialLoginProvider . GOOGLE )
400+
401+ expect ( performGoogleLoginSpy ) . toHaveBeenCalled ( )
402+ expect ( generateOauthUrlWithParamsSpy ) . toHaveBeenLastCalledWith (
403+ 'Google' ,
404+ 'test-client-id' ,
405+ 'test-redirect-uri' ,
406+ undefined ,
407+ )
408+ } )
409+
410+ it ( 'should update the global this location href correctly' , async ( ) => {
411+ await sdk . performLogin ( SocialLoginProvider . GOOGLE )
412+
413+ expect ( window . location . href ) . toContain ( 'prompt=none' )
414+ } )
415+ } )
0 commit comments