-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy path07_set_enabled.pl
70 lines (54 loc) · 1.83 KB
/
07_set_enabled.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use Future::Utils qw( repeat );
sub check_change_enabled
{
my ( $user, $scope, $kind, $rule_id, $enabled ) = @_;
matrix_set_push_rule_enabled( $user, $scope, $kind, $rule_id, $enabled )
->then( sub {
# Check that the actions match.
do_request_json_for( $user,
method => "GET",
uri => "/r0/pushrules/$scope/$kind/$rule_id/enabled",
)->on_done( sub {
my ( $body ) = @_;
assert_deeply_eq( $body, { enabled => $enabled } );
});
});
}
sub check_enable_disable_rule {
my ( $user, $scope, $kind, $rule_id ) = @_;
check_change_enabled( $user, $scope, $kind, $rule_id, JSON::true )
->then( sub {
check_change_enabled( $user, $scope, $kind, $rule_id, JSON::false );
})->then( sub {
check_change_enabled( $user, $scope, $kind, $rule_id, JSON::true );
});
}
test "Can enable/disable default rules",
requires => [ local_user_fixture() ],
check => sub {
my ( $user ) = @_;
matrix_get_push_rules( $user )->then( sub {
my ( $body ) = @_;
my @to_check;
foreach my $kind ( keys %{ $body->{global} } ) {
foreach my $rule ( @{ $body->{global}{$kind} } ) {
push @to_check, [ $kind, $rule->{rule_id} ];
}
}
repeat {
my $to_check = shift;
my ( $kind, $rule_id ) = @$to_check;
log_if_fail("testing $rule_id");
check_enable_disable_rule( $user, "global", $kind, $rule_id );
} foreach => \@to_check;
});
};
test "Enabling an unknown default rule fails with 404",
requires => [ local_user_fixture() ],
bug => "SYN-676",
check => sub {
my ( $user ) = @_;
matrix_set_push_rule_enabled(
$user, "global", "override", ".not.a.default.rule", JSON::true
)->main::expect_http_404;
};