@@ -82,6 +82,82 @@ describe('Messaging campaign commands', () => {
8282 } ,
8383 )
8484
85+ test ( 'updates a campaign with a partial JSON body through Messaging PATCH' , async ( ) => {
86+ const input = await jsonInput ( 'campaign-update.json' , {
87+ name : 'Autumn launch' ,
88+ recipientListId : null ,
89+ scheduledAt : null ,
90+ } )
91+ server = await startHttpServer ( {
92+ body : { data : { ...campaign ( ) , name : 'Autumn launch' } , success : true } ,
93+ headers : { 'request-id' : 'req_campaign_update' } ,
94+ } )
95+
96+ const result = await apiKeyEnvironment ( ( ) =>
97+ runCommand (
98+ `campaign update 0198a2cb-0000-7000-8000-0000000000e3 --project-slug project/main --input ${ input } --json` ,
99+ ) ,
100+ )
101+
102+ expect ( result . error ) . toBeUndefined ( )
103+ expect ( JSON . parse ( result . stdout ) ) . toMatchObject ( {
104+ data : { name : 'Autumn launch' } ,
105+ metadata : { attempts : 1 , requestId : 'req_campaign_update' , status : 200 } ,
106+ } )
107+ expect ( server . requests [ 0 ] ) . toMatchObject ( {
108+ method : 'PATCH' ,
109+ url : '/messaging/projects/project%2Fmain/campaigns/0198a2cb-0000-7000-8000-0000000000e3' ,
110+ body : JSON . stringify ( {
111+ name : 'Autumn launch' ,
112+ recipientListId : null ,
113+ scheduledAt : null ,
114+ } ) ,
115+ } )
116+ } )
117+
118+ test . each ( [ { } , { status : 'sent' } , [ ] ] ) (
119+ 'rejects unsupported or empty campaign patches before transport' ,
120+ async ( value ) => {
121+ const input = await jsonInput ( 'campaign-update-invalid.json' , value )
122+ server = await startHttpServer ( { body : { data : campaign ( ) , success : true } } )
123+ const result = await apiKeyEnvironment ( ( ) =>
124+ runCommand (
125+ `campaign update 0198a2cb-0000-7000-8000-0000000000e3 --project-slug project_1 --input ${ input } ` ,
126+ ) ,
127+ )
128+ expect ( exitCode ( result . error ) ) . toBe ( 2 )
129+ expect ( server . requests ) . toHaveLength ( 0 )
130+ } ,
131+ )
132+
133+ test ( 'reports a launched-audience conflict without replaying the PATCH' , async ( ) => {
134+ const input = await jsonInput ( 'campaign-update-conflict.json' , {
135+ recipientListId : null ,
136+ } )
137+ server = await startHttpServer ( {
138+ body : {
139+ error : {
140+ code : 'state_conflict' ,
141+ message : 'The audience is fixed after launch.' ,
142+ } ,
143+ success : false ,
144+ } ,
145+ status : 409 ,
146+ } )
147+
148+ const result = await apiKeyEnvironment ( ( ) =>
149+ runCommand (
150+ `campaign update 0198a2cb-0000-7000-8000-0000000000e3 --project-slug project_1 --input ${ input } --json` ,
151+ ) ,
152+ )
153+
154+ expect ( exitCode ( result . error ) ) . toBe ( 4 )
155+ expect ( JSON . parse ( result . stderr ) ) . toMatchObject ( {
156+ error : { category : 'conflict' , code : 'state_conflict' } ,
157+ } )
158+ expect ( server . requests ) . toHaveLength ( 1 )
159+ } )
160+
85161 test ( 'views one campaign and its exact live analytics counters' , async ( ) => {
86162 server = await startHttpSequenceServer ( [
87163 { body : { data : campaign ( ) , success : true } } ,
0 commit comments