@@ -475,6 +475,247 @@ test('toNextState with for kafka trigger', (t) => {
475475 } ) ;
476476} ) ;
477477
478+ test ( 'toNextState sets webhook_reply when specified' , ( t ) => {
479+ const state = { workflows : { } } ;
480+ const spec = {
481+ name : 'my project' ,
482+ workflows : {
483+ w : {
484+ name : 'workflow' ,
485+ jobs : { } ,
486+ triggers : {
487+ t : { type : 'webhook' , webhook_reply : 'before_start' } ,
488+ } ,
489+ edges : { } ,
490+ } ,
491+ } ,
492+ } ;
493+
494+ const result = mergeSpecIntoState ( state , spec ) ;
495+ t . is ( result . workflows . w . triggers . t . webhook_reply , 'before_start' ) ;
496+ } ) ;
497+
498+ test ( 'toNextState omits webhook_reply when not specified' , ( t ) => {
499+ const state = { workflows : { } } ;
500+ const spec = {
501+ name : 'my project' ,
502+ workflows : {
503+ w : {
504+ name : 'workflow' ,
505+ jobs : { } ,
506+ triggers : {
507+ t : { type : 'webhook' } ,
508+ } ,
509+ edges : { } ,
510+ } ,
511+ } ,
512+ } ;
513+
514+ const result = mergeSpecIntoState ( state , spec ) ;
515+ t . false ( 'webhook_reply' in result . workflows . w . triggers . t ) ;
516+ } ) ;
517+
518+ test ( 'toNextState sets cron_cursor_job_id when specified' , ( t ) => {
519+ const state = { workflows : { } } ;
520+ const spec = {
521+ name : 'my project' ,
522+ workflows : {
523+ w : {
524+ name : 'workflow' ,
525+ jobs : {
526+ 'job-a' : {
527+ name : 'job a' ,
528+ adaptor : '@openfn/language-http' ,
529+ body : 'fn()' ,
530+ } ,
531+ } ,
532+ triggers : {
533+ t : {
534+ type : 'cron' ,
535+ cron_expression : '0 * * * *' ,
536+ cron_cursor_job : 'job-a' ,
537+ } ,
538+ } ,
539+ edges : { } ,
540+ } ,
541+ } ,
542+ } ;
543+
544+ const result = mergeSpecIntoState ( state , spec ) ;
545+ const jobId = result . workflows . w . jobs [ 'job-a' ] . id ;
546+ t . is ( result . workflows . w . triggers . t . cron_cursor_job_id , jobId ) ;
547+ } ) ;
548+
549+ test ( 'toNextState omits cron_cursor_job_id when not specified' , ( t ) => {
550+ const state = { workflows : { } } ;
551+ const spec = {
552+ name : 'my project' ,
553+ workflows : {
554+ w : {
555+ name : 'workflow' ,
556+ jobs : {
557+ 'job-a' : {
558+ name : 'job a' ,
559+ adaptor : '@openfn/language-http' ,
560+ body : 'fn()' ,
561+ } ,
562+ } ,
563+ triggers : {
564+ t : { type : 'cron' , cron_expression : '0 * * * *' } ,
565+ } ,
566+ edges : { } ,
567+ } ,
568+ } ,
569+ } ;
570+
571+ const result = mergeSpecIntoState ( state , spec ) ;
572+ t . false ( 'cron_cursor_job_id' in result . workflows . w . triggers . t ) ;
573+ } ) ;
574+
575+ test ( 'toNextState sets webhook_reply on existing trigger' , ( t ) => {
576+ const triggerId = 'aaa-bbb-ccc' ;
577+ const state = {
578+ workflows : {
579+ w : {
580+ id : 'wf-1' ,
581+ name : 'workflow' ,
582+ jobs : { } ,
583+ triggers : {
584+ t : { id : triggerId , type : 'webhook' , enabled : true } ,
585+ } ,
586+ edges : { } ,
587+ } ,
588+ } ,
589+ } ;
590+ const spec = {
591+ name : 'my project' ,
592+ workflows : {
593+ w : {
594+ name : 'workflow' ,
595+ jobs : { } ,
596+ triggers : {
597+ t : { type : 'webhook' , webhook_reply : 'after_completion' } ,
598+ } ,
599+ edges : { } ,
600+ } ,
601+ } ,
602+ } ;
603+
604+ const result = mergeSpecIntoState ( state , spec ) ;
605+ t . is ( result . workflows . w . triggers . t . id , triggerId ) ;
606+ t . is ( result . workflows . w . triggers . t . webhook_reply , 'after_completion' ) ;
607+ } ) ;
608+
609+ test ( 'toNextState omits webhook_reply on existing trigger when not specified' , ( t ) => {
610+ const triggerId = 'aaa-bbb-ccc' ;
611+ const state = {
612+ workflows : {
613+ w : {
614+ id : 'wf-1' ,
615+ name : 'workflow' ,
616+ jobs : { } ,
617+ triggers : {
618+ t : { id : triggerId , type : 'webhook' , enabled : true } ,
619+ } ,
620+ edges : { } ,
621+ } ,
622+ } ,
623+ } ;
624+ const spec = {
625+ name : 'my project' ,
626+ workflows : {
627+ w : {
628+ name : 'workflow' ,
629+ jobs : { } ,
630+ triggers : {
631+ t : { type : 'webhook' } ,
632+ } ,
633+ edges : { } ,
634+ } ,
635+ } ,
636+ } ;
637+
638+ const result = mergeSpecIntoState ( state , spec ) ;
639+ t . false ( 'webhook_reply' in result . workflows . w . triggers . t ) ;
640+ } ) ;
641+
642+ test ( 'toNextState sets cron_cursor_job_id on existing trigger' , ( t ) => {
643+ const triggerId = 'aaa-bbb-ccc' ;
644+ const jobId = 'job-uuid-111' ;
645+ const state = {
646+ workflows : {
647+ w : {
648+ id : 'wf-1' ,
649+ name : 'workflow' ,
650+ jobs : {
651+ 'job-a' : { id : jobId , name : 'job a' } ,
652+ } ,
653+ triggers : {
654+ t : { id : triggerId , type : 'cron' , enabled : true } ,
655+ } ,
656+ edges : { } ,
657+ } ,
658+ } ,
659+ } ;
660+ const spec = {
661+ name : 'my project' ,
662+ workflows : {
663+ w : {
664+ name : 'workflow' ,
665+ jobs : {
666+ 'job-a' : { name : 'job a' , adaptor : '@openfn/language-http' , body : 'fn()' } ,
667+ } ,
668+ triggers : {
669+ t : { type : 'cron' , cron_expression : '0 * * * *' , cron_cursor_job : 'job-a' } ,
670+ } ,
671+ edges : { } ,
672+ } ,
673+ } ,
674+ } ;
675+
676+ const result = mergeSpecIntoState ( state , spec ) ;
677+ t . is ( result . workflows . w . triggers . t . id , triggerId ) ;
678+ t . is ( result . workflows . w . triggers . t . cron_cursor_job_id , jobId ) ;
679+ } ) ;
680+
681+ test ( 'toNextState omits cron_cursor_job_id on existing trigger when not specified' , ( t ) => {
682+ const triggerId = 'aaa-bbb-ccc' ;
683+ const jobId = 'job-uuid-111' ;
684+ const state = {
685+ workflows : {
686+ w : {
687+ id : 'wf-1' ,
688+ name : 'workflow' ,
689+ jobs : {
690+ 'job-a' : { id : jobId , name : 'job a' } ,
691+ } ,
692+ triggers : {
693+ t : { id : triggerId , type : 'cron' , enabled : true } ,
694+ } ,
695+ edges : { } ,
696+ } ,
697+ } ,
698+ } ;
699+ const spec = {
700+ name : 'my project' ,
701+ workflows : {
702+ w : {
703+ name : 'workflow' ,
704+ jobs : {
705+ 'job-a' : { name : 'job a' , adaptor : '@openfn/language-http' , body : 'fn()' } ,
706+ } ,
707+ triggers : {
708+ t : { type : 'cron' , cron_expression : '0 * * * *' } ,
709+ } ,
710+ edges : { } ,
711+ } ,
712+ } ,
713+ } ;
714+
715+ const result = mergeSpecIntoState ( state , spec ) ;
716+ t . false ( 'cron_cursor_job_id' in result . workflows . w . triggers . t ) ;
717+ } ) ;
718+
478719test ( 'mergeProjectIntoState with no changes' , ( t ) => {
479720 let existingState = fullExampleState ( ) ;
480721 const workflowOne = existingState . workflows [ 'workflow-one' ] ;
0 commit comments