Skip to content

Commit

Permalink
Test for metaredactions (#664)
Browse files Browse the repository at this point in the history
Who redacts the redactions?
  • Loading branch information
richvdh authored Aug 13, 2019
1 parent 8c8e32d commit d53c932
Showing 1 changed file with 59 additions and 6 deletions.
65 changes: 59 additions & 6 deletions tests/30rooms/10redactions.pl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sub make_room_and_message
=head2 matrix_redact_event
my $redaction_event_id = matrix_redact_event(
$user, $room_id, $event_id,
$user, $room_id, $event_id, %params
)->get;
Makes a /redact request
Expand All @@ -30,15 +30,15 @@ =head2 matrix_redact_event

sub matrix_redact_event
{
my ( $user, $room_id, $event_id ) = @_;
my ( $user, $room_id, $event_id, %params ) = @_;

$room_id = uri_escape( $room_id );
my $esc_event_id = uri_escape( $event_id );

do_request_json_for( $user,
method => "POST",
uri => "/r0/rooms/$room_id/redact/$esc_event_id",
content => {},
content => \%params,
)->then( sub {
my ( $body ) = @_;

Expand All @@ -52,7 +52,7 @@ sub matrix_redact_event
=head2 matrix_redact_event_synced
my $redaction_event_id = matrix_redact_event_synced(
$user, $room_id, $event_id,
$user, $room_id, $event_id, %params
)->get;
Makes a /redact request and waits for it to be echoed back in a sync
Expand All @@ -61,13 +61,15 @@ =head2 matrix_redact_event_synced

sub matrix_redact_event_synced
{
my ( $user, $room_id, $event_id ) = @_;
my ( $user, $room_id, $event_id, %params ) = @_;

my $redaction_event_id;

matrix_do_and_wait_for_sync( $user,
do => sub {
matrix_redact_event( $user, $room_id, $event_id )->on_done( sub {
matrix_redact_event(
$user, $room_id, $event_id, %params
)->on_done( sub {
( $redaction_event_id ) = @_;
});
}, check => sub {
Expand Down Expand Up @@ -162,3 +164,54 @@ sub matrix_redact_event_synced
matrix_redact_event( $user2, $room2, $event_id )
})->main::expect_http_400;
};

test "Redaction of a redaction redacts the redaction reason",
requires => [ local_user_fixtures( 2 ),
qw( can_send_message )],

do => sub {
my ( $creator, $sender ) = @_;

my ( $room_id, $redaction_id );

make_room_and_message( [ $creator, $sender ], $sender )
->then( sub {
my $to_redact;
( $room_id, $to_redact ) = @_;

matrix_redact_event_synced(
$creator, $room_id, $to_redact,
reason => "Offensively bad pun",
);
})->then( sub {
( $redaction_id ) = @_;

# fetch the redaction and check the reason is in place
do_request_json_for( $creator,
method => "GET",
uri => "/r0/rooms/$room_id/event/${ \uri_escape( $redaction_id ) }",
);
})->then( sub {
my ( $event ) = @_;
log_if_fail "Fetched redaction before metaredaction", $event;
assert_eq( $event->{content}->{reason}, "Offensively bad pun", "content not in redaction");

# now redact it
matrix_redact_event_synced(
$creator, $room_id, $redaction_id,
);
})->then( sub {
# ... and refetch...

do_request_json_for( $creator,
method => "GET",
uri => "/r0/rooms/$room_id/event/${ \uri_escape( $redaction_id ) }",
);
})->then( sub {
my ( $event ) = @_;
log_if_fail "Fetched redaction after metaredaction", $event;
exists $event->{content}->{reason} and die "Redaction was not redacted";

Future->done;
});
};

0 comments on commit d53c932

Please sign in to comment.