@@ -652,6 +652,140 @@ describe('createApp', () => {
652652 expect ( result ) . toMatchObject ( expectedApp )
653653 } )
654654
655+ test ( 'uses applicationUrl and redirectUrls from options when provided' , async ( ) => {
656+ // Given
657+ const client = AppManagementClient . getInstance ( )
658+ const org = testOrganization ( )
659+ vi . mocked ( webhooksRequestDoc ) . mockResolvedValueOnce ( {
660+ publicApiVersions : [ { handle : '2024-07' } , { handle : '2024-10' } , { handle : '2025-01' } , { handle : 'unstable' } ] ,
661+ } )
662+ vi . mocked ( appManagementRequestDoc ) . mockResolvedValueOnce ( {
663+ appCreate : {
664+ app : { id : '1' , key : 'key' , activeRoot : { clientCredentials : { secrets : [ { key : 'secret' } ] } } } ,
665+ userErrors : [ ] ,
666+ } ,
667+ } )
668+
669+ // When
670+ client . token = ( ) => Promise . resolve ( 'token' )
671+ await client . createApp ( org , {
672+ name : 'app-name' ,
673+ isLaunchable : false ,
674+ applicationUrl : 'https://extensions.shopifycdn.com' ,
675+ redirectUrls : [ 'https://shopify.dev/apps/default-app-home/api/auth' ] ,
676+ } )
677+
678+ // Then
679+ expect ( vi . mocked ( appManagementRequestDoc ) ) . toHaveBeenCalledWith ( {
680+ query : CreateApp ,
681+ token : 'token' ,
682+ variables : {
683+ organizationId : 'gid://shopify/Organization/1' ,
684+ initialVersion : {
685+ source : {
686+ name : 'app-name' ,
687+ modules : expect . arrayContaining ( [
688+ {
689+ type : 'app_home' ,
690+ config : {
691+ app_url : 'https://extensions.shopifycdn.com' ,
692+ embedded : true ,
693+ } ,
694+ } ,
695+ {
696+ type : 'app_access' ,
697+ config : {
698+ redirect_url_allowlist : [ 'https://shopify.dev/apps/default-app-home/api/auth' ] ,
699+ } ,
700+ } ,
701+ ] ) ,
702+ } ,
703+ } ,
704+ } ,
705+ unauthorizedHandler : {
706+ handler : expect . any ( Function ) ,
707+ type : 'token_refresh' ,
708+ } ,
709+ } )
710+ } )
711+
712+ test ( 'includes admin module with static_root when staticRoot is provided' , async ( ) => {
713+ // Given
714+ const client = AppManagementClient . getInstance ( )
715+ const org = testOrganization ( )
716+ vi . mocked ( webhooksRequestDoc ) . mockResolvedValueOnce ( {
717+ publicApiVersions : [ { handle : '2024-07' } , { handle : '2024-10' } , { handle : '2025-01' } , { handle : 'unstable' } ] ,
718+ } )
719+ vi . mocked ( appManagementRequestDoc ) . mockResolvedValueOnce ( {
720+ appCreate : {
721+ app : { id : '1' , key : 'key' , activeRoot : { clientCredentials : { secrets : [ { key : 'secret' } ] } } } ,
722+ userErrors : [ ] ,
723+ } ,
724+ } )
725+
726+ // When
727+ client . token = ( ) => Promise . resolve ( 'token' )
728+ await client . createApp ( org , {
729+ name : 'app-name' ,
730+ isLaunchable : false ,
731+ applicationUrl : 'https://extensions.shopifycdn.com' ,
732+ staticRoot : './dist' ,
733+ } )
734+
735+ // Then
736+ expect ( vi . mocked ( appManagementRequestDoc ) ) . toHaveBeenCalledWith (
737+ expect . objectContaining ( {
738+ variables : expect . objectContaining ( {
739+ initialVersion : expect . objectContaining ( {
740+ source : expect . objectContaining ( {
741+ modules : expect . arrayContaining ( [
742+ {
743+ type : 'admin' ,
744+ config : { admin : { static_root : './dist' } } ,
745+ } ,
746+ ] ) ,
747+ } ) ,
748+ } ) ,
749+ } ) ,
750+ } ) ,
751+ )
752+ } )
753+
754+ test ( 'does not include admin module when staticRoot is not provided' , async ( ) => {
755+ // Given
756+ const client = AppManagementClient . getInstance ( )
757+ const org = testOrganization ( )
758+ vi . mocked ( webhooksRequestDoc ) . mockResolvedValueOnce ( {
759+ publicApiVersions : [ { handle : '2024-07' } , { handle : '2024-10' } , { handle : '2025-01' } , { handle : 'unstable' } ] ,
760+ } )
761+ vi . mocked ( appManagementRequestDoc ) . mockResolvedValueOnce ( {
762+ appCreate : {
763+ app : { id : '1' , key : 'key' , activeRoot : { clientCredentials : { secrets : [ { key : 'secret' } ] } } } ,
764+ userErrors : [ ] ,
765+ } ,
766+ } )
767+
768+ // When
769+ client . token = ( ) => Promise . resolve ( 'token' )
770+ await client . createApp ( org , {
771+ name : 'app-name' ,
772+ isLaunchable : false ,
773+ } )
774+
775+ // Then
776+ expect ( vi . mocked ( appManagementRequestDoc ) ) . toHaveBeenCalledWith (
777+ expect . objectContaining ( {
778+ variables : expect . objectContaining ( {
779+ initialVersion : expect . objectContaining ( {
780+ source : expect . objectContaining ( {
781+ modules : expect . not . arrayContaining ( [ expect . objectContaining ( { type : 'admin' } ) ] ) ,
782+ } ) ,
783+ } ) ,
784+ } ) ,
785+ } ) ,
786+ )
787+ } )
788+
655789 test ( 'sets embedded to true in app home module' , async ( ) => {
656790 // Given
657791 const client = AppManagementClient . getInstance ( )
0 commit comments