diff --git a/lib/src/utils/pushrule_evaluator.dart b/lib/src/utils/pushrule_evaluator.dart index 505be3de..a531325f 100644 --- a/lib/src/utils/pushrule_evaluator.dart +++ b/lib/src/utils/pushrule_evaluator.dart @@ -186,6 +186,8 @@ class _OptimizedRules { notificationPermissions.add(key); } break; + default: + throw Exception('Unknown push condition: ${condition.kind}'); } } actions = EvaluatedPushRuleAction.fromActions(rule.actions); diff --git a/test/pushevaluator_test.dart b/test/pushevaluator_test.dart index c02e8697..1d155595 100644 --- a/test/pushevaluator_test.dart +++ b/test/pushevaluator_test.dart @@ -208,6 +208,29 @@ void main() { testNotMatch(override_ruleset2, event); }); + test('invalid push condition', () async { + final invalid_ruleset = PushRuleSet(override: [ + PushRule(ruleId: 'my.rule', default$: false, enabled: true, actions: [ + 'notify', + {'set_tweak': 'highlight', 'value': true}, + {'set_tweak': 'sound', 'value': 'goose.wav'}, + ], conditions: [ + PushCondition( + kind: 'invalidcondition', pattern: 'fox', key: 'content.body'), + ]) + ]); + + expect(() => PushruleEvaluator.fromRuleset(invalid_ruleset), + returnsNormally); + + final evaluator = PushruleEvaluator.fromRuleset(invalid_ruleset); + final event = Event.fromJson(jsonObj, room); + final actions = evaluator.match(event); + expect(actions.highlight, false); + expect(actions.sound, null); + expect(actions.notify, false); + }); + test('match_display_name rule', () async { final event = Event.fromJson(jsonObj, room); (event.room.states[EventTypes.RoomMember] ??= {})[client.userID!] =