1717 "filters" : {"properties" : [{"key" : "$browser" , "type" : "person" , "value" : ["Chrome" ], "operator" : "exact" }]},
1818}
1919
20+ EVENT_TRIGGER = {
21+ "type" : "event" ,
22+ "filters" : {
23+ "events" : [{"id" : "$pageview" , "name" : "$pageview" , "type" : "events" , "order" : 0 }],
24+ },
25+ }
26+
2027
21- def _make_workflow_payload (workflow_status = "draft" , schedule_config = None ):
28+ def _make_workflow_payload (workflow_status = "draft" , schedule_config = None , trigger_config = None ):
2229 payload = {
2330 "name" : "Test Batch Workflow" ,
2431 "status" : workflow_status ,
@@ -27,7 +34,7 @@ def _make_workflow_payload(workflow_status="draft", schedule_config=None):
2734 "id" : "trigger_node" ,
2835 "name" : "trigger" ,
2936 "type" : "trigger" ,
30- "config" : BATCH_TRIGGER ,
37+ "config" : trigger_config or BATCH_TRIGGER ,
3138 }
3239 ],
3340 }
@@ -356,3 +363,43 @@ def test_schedule_with_timezone_stores_timezone(self):
356363 hog_flow = HogFlow .objects .get (id = workflow ["id" ])
357364 assert hog_flow .schedule_config is not None
358365 assert hog_flow .schedule_config ["timezone" ] == "US/Eastern"
366+
367+ def test_schedule_config_cleared_for_non_batch_trigger (self ):
368+ schedule_config = {
369+ "rrule" : "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO" ,
370+ "starts_at" : "2030-01-01T09:00:00.000Z" ,
371+ }
372+ payload = _make_workflow_payload (
373+ workflow_status = "active" ,
374+ schedule_config = schedule_config ,
375+ trigger_config = EVENT_TRIGGER ,
376+ )
377+ response = self .client .post (f"/api/projects/{ self .team .id } /hog_flows" , payload )
378+ assert response .status_code == status .HTTP_201_CREATED
379+
380+ hog_flow = HogFlow .objects .get (id = response .json ()["id" ])
381+ assert hog_flow .schedule_config is None
382+ assert HogFlowScheduledRun .objects .filter (hog_flow = hog_flow , status = "pending" ).count () == 0
383+
384+ def test_switching_from_batch_to_event_trigger_clears_schedule_and_pending_run (self ):
385+ schedule_config = {
386+ "rrule" : "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO" ,
387+ "starts_at" : "2030-01-01T09:00:00.000Z" ,
388+ }
389+ workflow = self ._create_batch_workflow (schedule_config = schedule_config )
390+ hog_flow = HogFlow .objects .get (id = workflow ["id" ])
391+ assert hog_flow .schedule_config is not None
392+ assert HogFlowScheduledRun .objects .filter (hog_flow = hog_flow , status = "pending" ).count () == 1
393+
394+ # Switch to event trigger
395+ payload = _make_workflow_payload (
396+ workflow_status = "active" ,
397+ schedule_config = schedule_config ,
398+ trigger_config = EVENT_TRIGGER ,
399+ )
400+ response = self .client .patch (f"/api/projects/{ self .team .id } /hog_flows/{ workflow ['id' ]} " , payload )
401+ assert response .status_code == status .HTTP_200_OK
402+
403+ hog_flow .refresh_from_db ()
404+ assert hog_flow .schedule_config is None
405+ assert HogFlowScheduledRun .objects .filter (hog_flow = hog_flow , status = "pending" ).count () == 0
0 commit comments