@@ -532,9 +532,16 @@ describe("PlatformAuthDOMHandler tests", () => {
532532 nonce : "test-nonce" ,
533533 claims : "test-claims" ,
534534 instanceAware : true ,
535- windowTitleSubstring : "test-window-substring" ,
535+ windowTitleSubstring : null ,
536536 extendedExpiryToken : true ,
537537 signPopToken : true ,
538+ account : {
539+ nativeAccountId : "native-test-id" ,
540+ userName : "test-user" ,
541+ name : "Test User" ,
542+ username : "testest@test.com" ,
543+ } ,
544+ someArrayParam : [ "value1" , "value2" ] ,
538545 } ;
539546 const domExtraParams =
540547 //@ts -ignore
@@ -544,10 +551,79 @@ describe("PlatformAuthDOMHandler tests", () => {
544551 nonce : "test-nonce" ,
545552 claims : "test-claims" ,
546553 instanceAware : "true" ,
547- windowTitleSubstring : "test-window-substring" ,
548554 extendedExpiryToken : "true" ,
549555 signPopToken : "true" ,
556+ account : JSON . stringify ( testExtraParameters . account ) ,
557+ someArrayParam : '["value1","value2"]' ,
558+ } ) ;
559+ } ) ;
560+
561+ it ( "should omit undefined values" , async ( ) => {
562+ getSupportedContractsMock . mockResolvedValue ( [
563+ PlatformAuthConstants . PLATFORM_DOM_APIS ,
564+ ] ) ;
565+ const platformAuthDOMHandler =
566+ await PlatformAuthDOMHandler . createProvider (
567+ logger ,
568+ performanceClient ,
569+ "test-correlation-id"
570+ ) ;
571+
572+ const testExtraParameters = {
573+ prompt : PromptValue . NONE ,
574+ nonce : "test-nonce" ,
575+ claims : "test-claims" ,
576+ instanceAware : undefined ,
577+ } ;
578+
579+ const domExtraParams =
580+ //@ts -ignore
581+ platformAuthDOMHandler . getDOMExtraParams ( testExtraParameters ) ;
582+ expect ( domExtraParams ) . toEqual ( {
583+ prompt : "none" ,
584+ nonce : "test-nonce" ,
585+ claims : "test-claims" ,
550586 } ) ;
587+ expect ( domExtraParams ) . not . toHaveProperty ( "instanceAware" ) ;
588+ } ) ;
589+
590+ it ( "should catch JSON.stringify error and return empty object" , async ( ) => {
591+ getSupportedContractsMock . mockResolvedValue ( [
592+ PlatformAuthConstants . PLATFORM_DOM_APIS ,
593+ ] ) ;
594+ const platformAuthDOMHandler =
595+ await PlatformAuthDOMHandler . createProvider (
596+ logger ,
597+ performanceClient ,
598+ "test-correlation-id"
599+ ) ;
600+
601+ // Create a circular reference that will cause JSON.stringify to throw
602+ const circularObj : any = { name : "test" } ;
603+ circularObj . self = circularObj ;
604+
605+ const testExtraParameters = {
606+ prompt : PromptValue . NONE ,
607+ problemParam : circularObj ,
608+ } ;
609+
610+ console . log ( "Testing circular object:" , testExtraParameters ) ;
611+
612+ const loggerErrorSpy = jest . spyOn ( logger , "error" ) ;
613+ const loggerErrorPiiSpy = jest . spyOn ( logger , "errorPii" ) ;
614+
615+ const domExtraParams =
616+ //@ts -ignore
617+ platformAuthDOMHandler . getDOMExtraParams ( testExtraParameters ) ;
618+
619+ expect ( domExtraParams ) . toEqual ( { } ) ;
620+ expect ( loggerErrorSpy ) . toHaveBeenCalledWith (
621+ "PlatformAuthDOMHandler - Error stringifying extra parameters"
622+ ) ;
623+ expect ( loggerErrorPiiSpy ) . toHaveBeenCalled ( ) ;
624+ expect ( loggerErrorPiiSpy . mock . calls [ 0 ] [ 0 ] ) . toContain (
625+ "Error stringifying extra parameters"
626+ ) ;
551627 } ) ;
552628 } ) ;
553629} ) ;
0 commit comments