@@ -626,6 +626,43 @@ describe('server', () => {
626626 expect ( config . publicServerURL ) . toEqual ( 'https://myserver.com/1' ) ;
627627 } ) ;
628628
629+ it ( 'should load publicServerURL from Promise' , async ( ) => {
630+ await reconfigureServer ( {
631+ publicServerURL : ( ) => Promise . resolve ( 'https://async-server.com/1' ) ,
632+ } ) ;
633+
634+ await new Parse . Object ( 'TestObject' ) . save ( ) ;
635+
636+ const config = Config . get ( Parse . applicationId ) ;
637+ expect ( config . publicServerURL ) . toEqual ( 'https://async-server.com/1' ) ;
638+ } ) ;
639+
640+ it ( 'should handle publicServerURL function throwing error' , async ( ) => {
641+ const errorMessage = 'Failed to get public server URL' ;
642+ await reconfigureServer ( {
643+ publicServerURL : ( ) => {
644+ throw new Error ( errorMessage ) ;
645+ } ,
646+ } ) ;
647+
648+ // The error should occur when trying to save an object (which triggers loadKeys in middleware)
649+ await expectAsync (
650+ new Parse . Object ( 'TestObject' ) . save ( )
651+ ) . toBeRejected ( ) ;
652+ } ) ;
653+
654+ it ( 'should handle publicServerURL Promise rejection' , async ( ) => {
655+ const errorMessage = 'Async fetch of public server URL failed' ;
656+ await reconfigureServer ( {
657+ publicServerURL : ( ) => Promise . reject ( new Error ( errorMessage ) ) ,
658+ } ) ;
659+
660+ // The error should occur when trying to save an object (which triggers loadKeys in middleware)
661+ await expectAsync (
662+ new Parse . Object ( 'TestObject' ) . save ( )
663+ ) . toBeRejected ( ) ;
664+ } ) ;
665+
629666 it ( 'should not reload if ttl is not set' , async ( ) => {
630667 const masterKeySpy = jasmine . createSpy ( ) . and . returnValue ( Promise . resolve ( 'initialMasterKey' ) ) ;
631668
0 commit comments