@@ -20,6 +20,7 @@ import {AvailableTopicsQuery} from '../../api/graphql/webhooks/generated/availab
20
20
import { CliTesting , CliTestingMutation } from '../../api/graphql/webhooks/generated/cli-testing.js'
21
21
import { SendSampleWebhookVariables } from '../../services/webhook/request-sample.js'
22
22
import { CreateApp } from '../../api/graphql/app-management/generated/create-app.js'
23
+ import { BrandingSpecIdentifier } from '../../models/extensions/specifications/app_config_branding.js'
23
24
import { describe , expect , test , vi } from 'vitest'
24
25
import { CLI_KIT_VERSION } from '@shopify/cli-kit/common/version'
25
26
import { fetch } from '@shopify/cli-kit/node/http'
@@ -558,3 +559,198 @@ describe('sendSampleWebhook', () => {
558
559
expect ( result . sendSampleWebhook . userErrors ) . toEqual ( [ { message : 'Invalid api_version' , fields : [ ] } ] )
559
560
} )
560
561
} )
562
+
563
+ describe ( 'deploy' , ( ) => {
564
+ // Given
565
+ const client = new AppManagementClient ( )
566
+ client . token = ( ) => Promise . resolve ( 'token' )
567
+
568
+ test ( 'creates version with correct metadata and modules' , async ( ) => {
569
+ // Given
570
+ const versionTag = '1.0.0'
571
+ const message = 'Test deploy'
572
+ const commitReference = 'https://github.com/org/repo/commit/123'
573
+ const appModules = [
574
+ {
575
+ uid : 'branding' ,
576
+ config : JSON . stringify ( { name : 'Test App' } ) ,
577
+ handle : 'test-app' ,
578
+ specificationIdentifier : BrandingSpecIdentifier ,
579
+ context : 'unused-context' ,
580
+ } ,
581
+ ]
582
+
583
+ const mockResponse = {
584
+ appVersionCreate : {
585
+ version : {
586
+ id : 'gid://shopify/Version/1' ,
587
+ metadata : {
588
+ versionTag,
589
+ message,
590
+ sourceControlUrl : commitReference ,
591
+ } ,
592
+ appModules : [
593
+ {
594
+ uuid : 'some_uuid' ,
595
+ } ,
596
+ ] ,
597
+ } ,
598
+ userErrors : [ ] ,
599
+ } ,
600
+ }
601
+ vi . mocked ( appManagementRequestDoc ) . mockResolvedValueOnce ( mockResponse )
602
+
603
+ // When
604
+ await client . deploy ( {
605
+ apiKey : 'api-key' ,
606
+ appId : 'gid://shopify/App/123' ,
607
+ name : 'Test App' ,
608
+ appModules,
609
+ organizationId : 'gid://shopify/Organization/123' ,
610
+ versionTag,
611
+ message,
612
+ commitReference,
613
+ skipPublish : true ,
614
+ } )
615
+
616
+ // Then
617
+ expect ( appManagementRequestDoc ) . toHaveBeenCalledWith ( 'gid://shopify/Organization/123' , expect . anything ( ) , 'token' , {
618
+ appId : 'gid://shopify/App/123' ,
619
+ version : {
620
+ source : {
621
+ name : 'Test App' ,
622
+ modules : [
623
+ {
624
+ uid : 'branding' ,
625
+ type : BrandingSpecIdentifier ,
626
+ handle : 'test-app' ,
627
+ config : { name : 'Test App' } ,
628
+ } ,
629
+ ] ,
630
+ } ,
631
+ } ,
632
+ metadata : {
633
+ versionTag,
634
+ message,
635
+ sourceControlUrl : commitReference ,
636
+ } ,
637
+ } )
638
+ } )
639
+
640
+ test ( 'uses bundleUrl when provided instead of modules' , async ( ) => {
641
+ // Given
642
+ const bundleUrl = 'https://storage.test/bundle.zip'
643
+ const mockResponse = {
644
+ appVersionCreate : {
645
+ version : {
646
+ id : 'gid://shopify/Version/1' ,
647
+ metadata : { } ,
648
+ appModules : [ ] ,
649
+ } ,
650
+ userErrors : [ ] ,
651
+ } ,
652
+ }
653
+ vi . mocked ( appManagementRequestDoc ) . mockResolvedValueOnce ( mockResponse )
654
+
655
+ // When
656
+ await client . deploy ( {
657
+ apiKey : 'api-key' ,
658
+ appId : 'gid://shopify/App/123' ,
659
+ name : 'Test App' ,
660
+ organizationId : 'gid://shopify/Organization/123' ,
661
+ bundleUrl,
662
+ versionTag : '1.0.0' ,
663
+ skipPublish : true ,
664
+ } )
665
+
666
+ // Then
667
+ expect ( appManagementRequestDoc ) . toHaveBeenCalledWith ( 'gid://shopify/Organization/123' , expect . anything ( ) , 'token' , {
668
+ appId : 'gid://shopify/App/123' ,
669
+ version : {
670
+ sourceUrl : bundleUrl ,
671
+ } ,
672
+ metadata : expect . any ( Object ) ,
673
+ } )
674
+ } )
675
+
676
+ test ( 'updates name from branding module if present' , async ( ) => {
677
+ // Given
678
+ const appModules = [
679
+ {
680
+ uuid : 'branding' ,
681
+ config : JSON . stringify ( { name : 'Updated App Name' } ) ,
682
+ handle : 'branding' ,
683
+ specificationIdentifier : BrandingSpecIdentifier ,
684
+ context : 'unused-context' ,
685
+ } ,
686
+ ]
687
+ const mockResponse = {
688
+ appVersionCreate : {
689
+ version : {
690
+ id : 'gid://shopify/Version/1' ,
691
+ metadata : { } ,
692
+ appModules : [ ] ,
693
+ } ,
694
+ userErrors : [ ] ,
695
+ } ,
696
+ }
697
+ vi . mocked ( appManagementRequestDoc ) . mockResolvedValueOnce ( mockResponse )
698
+
699
+ // When
700
+ await client . deploy ( {
701
+ apiKey : 'api-key' ,
702
+ appId : 'gid://shopify/App/123' ,
703
+ name : 'Original Name' ,
704
+ appModules,
705
+ organizationId : 'gid://shopify/Organization/123' ,
706
+ versionTag : '1.0.0' ,
707
+ skipPublish : true ,
708
+ } )
709
+
710
+ // Then
711
+ expect ( appManagementRequestDoc ) . toHaveBeenCalledWith (
712
+ 'gid://shopify/Organization/123' ,
713
+ expect . anything ( ) ,
714
+ 'token' ,
715
+ expect . objectContaining ( {
716
+ version : {
717
+ source : {
718
+ name : 'Updated App Name' ,
719
+ modules : expect . any ( Array ) ,
720
+ } ,
721
+ } ,
722
+ } ) ,
723
+ )
724
+ } )
725
+
726
+ test ( 'handles version creation errors' , async ( ) => {
727
+ // Given
728
+ const mockResponse = {
729
+ appVersionCreate : {
730
+ version : null ,
731
+ userErrors : [
732
+ {
733
+ field : [ 'version' ] ,
734
+ message : 'Invalid version' ,
735
+ details : [ ] ,
736
+ } ,
737
+ ] ,
738
+ } ,
739
+ }
740
+ vi . mocked ( appManagementRequestDoc ) . mockResolvedValueOnce ( mockResponse )
741
+
742
+ // When
743
+ const result = await client . deploy ( {
744
+ apiKey : 'api-key' ,
745
+ appId : 'gid://shopify/App/123' ,
746
+ name : 'Test App' ,
747
+ organizationId : 'gid://shopify/Organization/123' ,
748
+ versionTag : '1.0.0' ,
749
+ skipPublish : true ,
750
+ } )
751
+
752
+ // Then
753
+ expect ( result . appDeploy . userErrors ) . toHaveLength ( 1 )
754
+ expect ( result . appDeploy . userErrors [ 0 ] ?. message ) . toBe ( 'Invalid version' )
755
+ } )
756
+ } )
0 commit comments