@@ -1309,3 +1309,65 @@ def test_dataset_filter(self):
1309
1309
# without performance-view, we should only see events rules
1310
1310
res = self .get_success_response (self .organization .slug )
1311
1311
self .assert_alert_rule_serialized (events_rule , res .data [0 ], skip_dates = True )
1312
+
1313
+ def test_alert_type_filter (self ):
1314
+ # Setup one of each type of alert rule
1315
+ metric_rule = self .create_alert_rule ()
1316
+ issue_rule = self .create_issue_alert_rule (
1317
+ data = {
1318
+ "project" : self .project ,
1319
+ "name" : "Issue Rule Test" ,
1320
+ "conditions" : [],
1321
+ "actions" : [],
1322
+ "actionMatch" : "all" ,
1323
+ "date_added" : before_now (minutes = 4 ),
1324
+ }
1325
+ )
1326
+ uptime_rule = self .create_project_uptime_subscription (project = self .project )
1327
+ cron_rule = self .create_monitor (project = self .project )
1328
+
1329
+ features = [
1330
+ "organizations:incidents" ,
1331
+ "organizations:performance-view" ,
1332
+ "organizations:insights-crons" ,
1333
+ ]
1334
+
1335
+ # Everything comes back without the query parameter
1336
+ with self .feature (features ):
1337
+ request_data = {"per_page" : "10" , "project" : [self .project .id ]}
1338
+ response = self .client .get (
1339
+ path = self .combined_rules_url ,
1340
+ data = request_data ,
1341
+ content_type = "application/json" ,
1342
+ )
1343
+ assert response .status_code == 200 , response .content
1344
+ assert {r ["id" ] for r in response .data } == {
1345
+ str (metric_rule .id ),
1346
+ str (issue_rule .id ),
1347
+ str (uptime_rule .id ),
1348
+ str (cron_rule .guid ),
1349
+ }
1350
+
1351
+ test_cases : list [tuple [list [str ], set [str ]]] = [
1352
+ (["rule" ], {str (issue_rule .id )}),
1353
+ (["alert_rule" ], {str (metric_rule .id )}),
1354
+ (["monitor" ], {str (cron_rule .guid )}),
1355
+ (["uptime" ], {str (uptime_rule .id )}),
1356
+ (["rule" , "alert_rule" ], {str (issue_rule .id ), str (metric_rule .id )}),
1357
+ (["uptime" , "monitor" ], {str (uptime_rule .id ), str (cron_rule .guid )}),
1358
+ ]
1359
+
1360
+ for alert_type , expected_ids in test_cases :
1361
+ with self .feature (features ):
1362
+ request_data = {
1363
+ "per_page" : "10" ,
1364
+ "project" : [self .project .id ],
1365
+ "alertType" : alert_type ,
1366
+ }
1367
+ response = self .client .get (
1368
+ path = self .combined_rules_url ,
1369
+ data = request_data ,
1370
+ content_type = "application/json" ,
1371
+ )
1372
+ assert response .status_code == 200 , response .content
1373
+ assert {r ["id" ] for r in response .data } == expected_ids
0 commit comments