Skip to content

Commit

Permalink
Only check state/ephemeral if needed (#1298)
Browse files Browse the repository at this point in the history
Removes the state/ephemeral checks, since they are not required as per the spec
  • Loading branch information
S7evinK authored Oct 6, 2022
1 parent d0a5dd3 commit 3871417
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 50 deletions.
8 changes: 5 additions & 3 deletions tests/10apidoc/09synced.pl
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,13 @@ sub assert_room_members {
my ( $body, $room_id, $memberships ) = @_;

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

#log_if_fail "Room", $room;

assert_json_keys( $room, qw( timeline state ephemeral ));

if ( scalar @{ $memberships } == 0 && !exists ( $room->{state} ) ) {
return 1;
}
assert_json_keys( $room, qw( state ));

return assert_state_room_members_match( $room->{state}{events}, $memberships );
}
Expand Down
4 changes: 2 additions & 2 deletions tests/30rooms/30history-visibility.pl
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ sub test_history_visibility
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room, qw( timeline ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));

# look at the last four events
Expand Down Expand Up @@ -481,7 +481,7 @@ sub test_history_visibility
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room, qw( timeline ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));

# look at the last four events
Expand Down
34 changes: 23 additions & 11 deletions tests/31sync/03joined.pl
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room, qw( timeline ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));
assert_json_keys( $room->{state}, qw( events ));
assert_json_keys( $room->{ephemeral}, qw( events ));

if (exists($room->{state})) {
assert_json_empty_list( $room->{state}{events} );
}
if (exists($room->{ephemeral})) {
assert_json_empty_list( $room->{ephemeral}{events} );
}

matrix_sync_again( $user, filter => $filter_id );
})->then( sub {
Expand Down Expand Up @@ -67,11 +72,14 @@
my ( $body ) = @_;

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

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

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

Future->done(1)
})
Expand Down Expand Up @@ -103,10 +111,14 @@
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room, qw( timeline ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));
assert_json_keys( $room->{state}, qw( events ));
assert_json_keys( $room->{ephemeral}, qw( events ));
if (exists($room->{state})) {
assert_json_empty_list( $room->{state}{events} );
}
if (exists($room->{ephemeral})) {
assert_json_empty_list( $room->{ephemeral}{events} );
}

matrix_sync_again( $user, filter => $filter_id );
})->then( sub {
Expand Down
32 changes: 17 additions & 15 deletions tests/31sync/04timeline.pl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room, qw( timeline ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));
@{ $room->{timeline}{events} } == 2
or die "Expected two timeline events";
Expand Down Expand Up @@ -87,7 +87,7 @@
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room, qw( timeline ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));
@{ $room->{timeline}{events} } == 1
or die "Expected only one timeline event";
Expand Down Expand Up @@ -148,10 +148,11 @@
log_if_fail "Sync response", $body;

my $room = $body->{rooms}{join}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room->{state}, qw( events ));
assert_json_keys( $room, qw( timeline ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));
assert_json_empty_list( $room->{state}{events} );
if (exists($room->{state})) {
assert_json_empty_list( $room->{state}{events} );
}
@{ $room->{timeline}{events} } == 1
or die "Expected only one timeline event";
$room->{timeline}{events}[0]{event_id} eq $event_id
Expand Down Expand Up @@ -206,10 +207,11 @@
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room->{state}, qw( events ));
assert_json_keys( $room, qw( timeline ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));
assert_json_empty_list( $room->{state}{events} );
if (exists($room->{state})) {
assert_json_empty_list( $room->{state}{events} );
}
@{ $room->{timeline}{events} } == 1
or die "Expected only one timeline event";
$room->{timeline}{events}[0]{event_id} eq $event_id
Expand Down Expand Up @@ -247,8 +249,10 @@
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room->{state}, qw( events ));
assert_json_keys( $room, qw( timeline ));
if (exists($room->{state})) {
assert_json_empty_list( $room->{state}{events} );
}
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));
(not $room->{timeline}{limited})
or die "Did not expect timeline to be limited";
Expand Down Expand Up @@ -297,7 +301,7 @@
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room, qw( timeline ));

@{ $room->{timeline}{events} } == 1
or die "Expected only one timeline event";
Expand Down Expand Up @@ -343,8 +347,7 @@
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room->{state}, qw( events ));
assert_json_keys( $room, qw( timeline ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));
@{ $room->{timeline}{events} } == 1
or die "Expected only one timeline event";
Expand Down Expand Up @@ -406,8 +409,7 @@

log_if_fail "Sync for room", $room;

assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room->{state}, qw( events ));
assert_json_keys( $room, qw( timeline ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));
@{ $room->{timeline}{events} } == 1
or die "Expected only one timeline event";
Expand Down
10 changes: 7 additions & 3 deletions tests/31sync/07invited.pl
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@
my ( $room ) = @_;
log_if_fail "post-join sync", $room;

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

Future->done(1);
})
Expand Down
21 changes: 12 additions & 9 deletions tests/31sync/09archived.pl
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@
my ( $body ) = @_;

my $room = $body->{rooms}{leave}{$room_id};
assert_json_keys( $room, qw( timeline state ));

@{ $room->{state}{events} } == 0
or die "Expected no state events";
assert_json_keys( $room, qw( timeline ));
if ( exists ( $room->{state} ) ) {
@{ $room->{state}{events} } == 0
or die "Expected no state events";
}

Future->done(1);
});
Expand Down Expand Up @@ -101,10 +102,12 @@
log_if_fail "sync result", $body;

my $room = $body->{rooms}{leave}{$room_id};
assert_json_keys( $room, qw( timeline state ));
assert_json_keys( $room, qw( timeline ));

assert_eq( scalar @{ $room->{state}{events} }, 0,
"state events" );
if ( exists ( $room->{state} ) ) {
@{ $room->{state}{events} } == 0
or die "Expected no state events";
}

# we should see our own leave event
assert_eq( scalar @{ $room->{timeline}{events} }, 1,
Expand Down Expand Up @@ -206,7 +209,7 @@
my ( $body ) = @_;

my $room = $body->{rooms}{leave}{$room_id_1};
assert_json_keys( $room, qw( timeline state ));
assert_json_keys( $room, qw( timeline ));

Future->done(1);
});
Expand Down Expand Up @@ -298,7 +301,7 @@
my ( $body ) = @_;

my $room = $body->{rooms}{leave}{$room_id};
assert_json_keys( $room, qw( timeline state ));
assert_json_keys( $room, qw( timeline ));

Future->done(1);
});
Expand Down
4 changes: 2 additions & 2 deletions tests/31sync/10archived-ban.pl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ sub ban_user_synced
my ( $body ) = @_;

my $room = $body->{rooms}{leave}{$room_id};
assert_json_keys( $room, qw( timeline state ));
assert_json_keys( $room, qw( timeline ));

Future->done(1);
});
Expand Down Expand Up @@ -134,7 +134,7 @@ sub ban_user_synced
my ( $body ) = @_;

my $room = $body->{rooms}{leave}{$room_id};
assert_json_keys( $room, qw( timeline state ));
assert_json_keys( $room, qw( state ));

Future->done(1);
});
Expand Down
4 changes: 3 additions & 1 deletion tests/31sync/13filtered_sync.pl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

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

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

@{ $room->{state}{events} } == 1
or die "Expected a single state event because of the filter";
Expand Down
11 changes: 7 additions & 4 deletions tests/31sync/17peeking.pl
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@
log_if_fail "first sync response", $body;

my $room = $body->{rooms}{peek}{$room_id};
assert_json_keys( $room, qw( timeline state ephemeral ));
assert_json_keys( $room, qw( timeline ));
assert_json_keys( $room->{timeline}, qw( events limited prev_batch ));
assert_json_keys( $room->{state}, qw( events ));
assert_json_keys( $room->{ephemeral}, qw( events ));
if (exists($room->{state})) {
assert_json_empty_list( $room->{state}{events} );
}
if (exists($room->{ephemeral})) {
assert_json_empty_list( $room->{ephemeral}{events} );
}

assert_ok( $room->{timeline}->{events}->[0]->{type} eq 'm.room.create', "peek has m.room.create" );
assert_ok( $room->{timeline}->{events}->[-1]->{type} eq 'm.room.message', "peek has message type" );
assert_ok( $room->{timeline}->{events}->[-1]->{content}->{body} eq 'something to peek', "peek has message body" );
assert_ok( @{$room->{state}->{events}} == 0 );

assert_ok( scalar keys(%{$body->{rooms}{join}}) == 0, "no joined rooms present");

Expand Down

0 comments on commit 3871417

Please sign in to comment.