Skip to content

Commit

Permalink
Merge pull request #470 from matrix-org/matthew/room_summary
Browse files Browse the repository at this point in the history
initial room summary tests
  • Loading branch information
richvdh committed Aug 16, 2018
2 parents 548787d + 79b6132 commit c3980aa
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/31sync/15lazy-members.pl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
matrix_create_room_synced( $alice );
})->then( sub {
( $room_id ) = @_;
matrix_put_room_state( $alice, $room_id,
type => "m.room.name",
content => { name => "A room name" },
);
})->then( sub {
matrix_join_room( $bob, $room_id );
})->then( sub {
matrix_join_room( $charlie, $room_id );
Expand Down Expand Up @@ -136,6 +141,11 @@
matrix_create_room_synced( $alice );
})->then( sub {
( $room_id ) = @_;
matrix_put_room_state( $alice, $room_id,
type => "m.room.name",
content => { name => "A room name" },
);
})->then( sub {
matrix_join_room( $bob, $room_id );
})->then( sub {
matrix_join_room( $charlie, $room_id );
Expand Down Expand Up @@ -200,6 +210,11 @@
matrix_create_room_synced( $alice );
})->then( sub {
( $room_id ) = @_;
matrix_put_room_state( $alice, $room_id,
type => "m.room.name",
content => { name => "A room name" },
);
})->then( sub {
matrix_join_room( $bob, $room_id );
})->then( sub {
matrix_join_room( $charlie, $room_id );
Expand Down Expand Up @@ -279,6 +294,11 @@
matrix_create_room_synced( $alice );
})->then( sub {
( $room_id ) = @_;
matrix_put_room_state( $alice, $room_id,
type => "m.room.name",
content => { name => "A room name" },
);
})->then( sub {
matrix_join_room( $bob, $room_id );
})->then( sub {
matrix_join_room( $charlie, $room_id );
Expand Down Expand Up @@ -358,6 +378,11 @@
matrix_create_room_synced( $alice );
})->then( sub {
( $room_id ) = @_;
matrix_put_room_state( $alice, $room_id,
type => "m.room.name",
content => { name => "A room name" },
);
})->then( sub {
matrix_join_room( $bob, $room_id );
})->then( sub {
matrix_join_room( $charlie, $room_id );
Expand Down
140 changes: 140 additions & 0 deletions tests/31sync/16room-summary.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
use Future::Utils qw( repeat );

test "Unnamed room comes with a name summary",
requires => [ local_user_fixtures( 3 ),
qw( can_sync ) ],

check => sub {
my ( $alice, $bob, $charlie ) = @_;

my ( $filter_id, $room_id );

matrix_create_filter( $alice, {
room => {
state => {
lazy_load_members => JSON::true
},
}
} )->then( sub {
( $filter_id ) = @_;

matrix_create_room_synced( $alice );
})->then( sub {
( $room_id ) = @_;
matrix_join_room_synced( $bob, $room_id );
})->then( sub {
matrix_join_room( $charlie, $room_id );
})->then( sub {
matrix_sync( $alice, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;
log_if_fail ( "sync response:", $body->{rooms}{join}{$room_id} );
my $summary = $body->{rooms}{join}{$room_id}{summary};
assert_deeply_eq( $summary, {
'm.joined_member_count' => 3,
'm.invited_member_count' => 0,
'm.heroes' => [
$bob->user_id,
$charlie->user_id,
]
});
Future->done(1);
});
};

test "Named room comes with just joined member count summary",
requires => [ local_user_fixtures( 3 ),
qw( can_sync ) ],

check => sub {
my ( $alice, $bob, $charlie ) = @_;

my ( $filter_id, $room_id );

matrix_create_filter( $alice, {
room => {
state => {
lazy_load_members => JSON::true
},
}
} )->then( sub {
( $filter_id ) = @_;

matrix_create_room_synced( $alice );
})->then( sub {
( $room_id ) = @_;
matrix_put_room_state( $alice, $room_id,
type => "m.room.name",
content => { name => "A room name" },
);
})->then( sub {
matrix_join_room_synced( $bob, $room_id );
})->then( sub {
matrix_join_room( $charlie, $room_id );
})->then( sub {
matrix_sync( $alice, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;
log_if_fail ( "sync response:", $body->{rooms}{join}{$room_id} );
my $summary = $body->{rooms}{join}{$room_id}{summary};
assert_deeply_eq($summary, {
'm.joined_member_count' => 3,
'm.invited_member_count' => 0,
});
Future->done(1);
});
};


test "Room summary only has 5 heroes",
requires => [ local_user_fixtures( 6 ),
qw( can_sync ) ],

check => sub {
my ( $alice, @users ) = @_;

my ( $filter_id, $room_id );

matrix_create_filter( $alice, {
room => {
state => {
lazy_load_members => JSON::true
},
}
} )->then( sub {
( $filter_id ) = @_;

matrix_create_room_synced( $alice );
})->then( sub {
( $room_id ) = @_;
repeat( sub {
matrix_join_room_synced( $_[0], $room_id );
}, foreach => [ @users ])
})->then( sub {
matrix_sync( $alice, filter => $filter_id );
})->then( sub {
my ( $body ) = @_;
log_if_fail ( "sync response:", $body->{rooms}{join}{$room_id} );
my $summary = $body->{rooms}{join}{$room_id}{summary};
my $expected_heroes = [
(sort(
$users[0]->user_id,
$users[1]->user_id,
$users[2]->user_id,
$users[3]->user_id,
$users[4]->user_id,
))[0..4]
];
log_if_fail( "expected_heroes:", $expected_heroes );
assert_deeply_eq($summary, {
'm.joined_member_count' => 6,
'm.invited_member_count' => 0,
'm.heroes' => $expected_heroes,
});
Future->done(1);
});
};

# TODO: test that parted users don't feature in room summaries, unless everyone has left
# TODO: check we receive room state for unknown hero mxids
# TODO: check that room summary changes whenever membership changes

0 comments on commit c3980aa

Please sign in to comment.