Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for event_format in filters #488

Merged
merged 1 commit into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions tests/31sync/13filtered_sync.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use JSON qw( encode_json );

test "Can pass a JSON filter as a query parameter",
requires => [ local_user_fixture() ],

check => sub {
my ( $user ) = @_;

my ( $room_id );

matrix_create_room_synced( $user )->then( sub {
( $room_id ) = @_;

matrix_sync( $user, filter => encode_json( {
room => {
state => { types => [ "m.room.member" ] },
timeline => { limit => 0 },
}
}));
})->then( sub {
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};

assert_json_empty_list( $room->{timeline}{events} );

@{ $room->{state}{events} } == 1
or die "Expected a single state event because of the filter";

$room->{state}{events}[0]{type} eq "m.room.member"
or die "Expected a single member event because of the filter";

Future->done(1);
});
};


test "Can request federation format via the filter",
requires => [ local_user_fixture( with_events => 0 ),
qw( can_sync ) ],

check => sub {
my ( $user ) = @_;

my ( $filter_id, $room_id, $event_id_1 );

my $filter = {
event_format => 'federation',
room => { timeline => { limit => 1 } },
};

matrix_create_filter( $user, $filter )->then( sub {
( $filter_id ) = @_;

matrix_create_room_synced( $user )
})->then( sub {
( $room_id ) = @_;

matrix_send_room_text_message_synced( $user, $room_id,
body => "Test message",
);
})->then( sub {
( $event_id_1 ) = @_;

matrix_sync( $user, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};

log_if_fail "sync room result", $room;

assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));

assert_eq( scalar @{ $room->{timeline}{events} }, 1, "timeline event count" );

assert_json_keys(
$room->{timeline}{events}[0], qw(
event_id content room_id sender origin origin_server_ts type
prev_events auth_events depth hashes signatures
)
);

assert_eq( $room->{timeline}{events}[0]{content}{body}, "Test message", "timeline message" );
assert_eq( $room->{timeline}{events}[0]{event_id}, $event_id_1, "timeline event id" );

Future->done(1);
});
};
35 changes: 0 additions & 35 deletions tests/31sync/13inline_filter.pl

This file was deleted.