@@ -399,4 +399,82 @@ describe("ChannelsPublish", function () {
399399 expect ( stdout ) . toMatch ( / e r r o r / i) ;
400400 } ) ;
401401 } ) ;
402+
403+ describe ( "should publish a message with data and extras" , function ( ) {
404+ it ( "should include extras.push when provided in message data" , async function ( ) {
405+ const restMock = getMockAblyRest ( ) ;
406+ const channel = restMock . channels . _getChannel ( "test-channel" ) ;
407+
408+ await runCommand (
409+ [
410+ "channels:publish" ,
411+ "test-channel" ,
412+ '{"data":"hello","extras":{"push":{"notification":{"title":"Test","body":"Push notification"}}}}' ,
413+ "--transport" ,
414+ "rest" ,
415+ ] ,
416+ import . meta. url ,
417+ ) ;
418+
419+ expect ( channel . publish ) . toHaveBeenCalledOnce ( ) ;
420+ const publishArgs = channel . publish . mock . calls [ 0 ] [ 0 ] ;
421+ expect ( publishArgs ) . toHaveProperty ( "data" , "hello" ) ;
422+ expect ( publishArgs ) . toHaveProperty ( "extras" ) ;
423+ expect ( publishArgs . extras ) . toHaveProperty ( "push" ) ;
424+ expect ( publishArgs . extras . push ) . toEqual ( {
425+ notification : { title : "Test" , body : "Push notification" } ,
426+ } ) ;
427+ } ) ;
428+
429+ it ( "should publish a message when only extras is provided without data" , async function ( ) {
430+ const restMock = getMockAblyRest ( ) ;
431+ const channel = restMock . channels . _getChannel ( "test-channel" ) ;
432+
433+ await runCommand (
434+ [
435+ "channels:publish" ,
436+ "test-channel" ,
437+ '{"extras":{"push":{"notification":{"title":"Extras only","body":"No data field"}}}}' ,
438+ "--transport" ,
439+ "rest" ,
440+ ] ,
441+ import . meta. url ,
442+ ) ;
443+
444+ expect ( channel . publish ) . toHaveBeenCalledOnce ( ) ;
445+ const publishArgs = channel . publish . mock . calls [ 0 ] [ 0 ] ;
446+ expect ( publishArgs ) . toHaveProperty ( "extras" ) ;
447+ expect ( publishArgs . extras ) . toHaveProperty ( "push" ) ;
448+ expect ( publishArgs . extras . push ) . toEqual ( {
449+ notification : { title : "Extras only" , body : "No data field" } ,
450+ } ) ;
451+ expect ( publishArgs ) . not . toHaveProperty ( "data" ) ;
452+ } ) ;
453+
454+ it ( "should preserve name when extras is provided without data" , async function ( ) {
455+ const restMock = getMockAblyRest ( ) ;
456+ const channel = restMock . channels . _getChannel ( "test-channel" ) ;
457+
458+ await runCommand (
459+ [
460+ "channels:publish" ,
461+ "test-channel" ,
462+ '{"name":"eventName","extras":{"push":{"notification":{"title":"With name","body":"No data field"}}}}' ,
463+ "--transport" ,
464+ "rest" ,
465+ ] ,
466+ import . meta. url ,
467+ ) ;
468+
469+ expect ( channel . publish ) . toHaveBeenCalledOnce ( ) ;
470+ const publishArgs = channel . publish . mock . calls [ 0 ] [ 0 ] ;
471+ expect ( publishArgs ) . toHaveProperty ( "name" , "eventName" ) ;
472+ expect ( publishArgs ) . toHaveProperty ( "extras" ) ;
473+ expect ( publishArgs . extras ) . toHaveProperty ( "push" ) ;
474+ expect ( publishArgs . extras . push ) . toEqual ( {
475+ notification : { title : "With name" , body : "No data field" } ,
476+ } ) ;
477+ expect ( publishArgs ) . not . toHaveProperty ( "data" ) ;
478+ } ) ;
479+ } ) ;
402480} ) ;
0 commit comments