Skip to content

Commit

Permalink
Merge pull request #224 from matrix-org/dbkr/push_badges
Browse files Browse the repository at this point in the history
Test unread counts in pushes
  • Loading branch information
dbkr committed Apr 11, 2016
2 parents 6f4c61e + 9b47abe commit ad85515
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions tests/61push/01message-pushed.pl
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,22 @@
})->SyTest::pass_on_done( "Bob received invite" ),

matrix_invite_user_to_room( $alice, $bob, $room_id ),
flush_events_for( $alice ),
)
})->then( sub {
# Bob accepts the invite by joining the room
matrix_join_room( $bob, $room_id )
})->then( sub {
await_event_for( $alice, filter => sub {
my ( $event ) = @_;
return unless $event->{type} eq "m.room.member";
return 1;
})->then( sub {
my ( $event ) = @_;
matrix_advance_room_receipt( $alice, $room_id,
"m.read" => $event->{event_id}
);
});
})->then( sub {
# Now that Bob has joined the room, we will create a pusher for
# Alice. This may race with Bob joining the room. So the first
Expand Down Expand Up @@ -81,7 +93,7 @@
})->then( sub {
my ( $request ) = @_;

$request->respond( HTTP::Response->new( 200, "OK", [], "" ) );
$request->respond_json( {} );
Future->done( $request );
}),

Expand All @@ -93,14 +105,15 @@
my ( $request ) = @_;
my $body = $request->body_from_json;

log_if_fail "Request body", $body;
log_if_fail "Message push request body", $body;

assert_json_keys( my $notification = $body->{notification}, qw(
id room_id type sender content devices counts
));
assert_json_keys( $notification->{counts}, qw(
unread
));
assert_eq( $notification->{counts}->{unread}, 1, "unread count");
assert_json_keys( $notification->{devices}[0], qw(
app_id pushkey pushkey_ts data tweaks
));
Expand All @@ -112,6 +125,40 @@
die "Unexpected message body";

pass "Alice was pushed"; # Alice has gone down the stairs

Future->needs_all(
await_http_request( "/alice_push", sub {
my ( $request ) = @_;
my $body = $request->body_from_json;

return unless $body->{notification}{counts};
return 1;
})->then( sub {
my ( $request ) = @_;

$request->respond_json( {} );
Future->done( $request );
}),

# Now send a read receipt for that message
matrix_advance_room_receipt( $alice, $notification->{room_id},
"m.read" => $notification->{event_id}
)->SyTest::pass_on_done( "Receipt sent" ),
)
})->then( sub {
my ( $request ) = @_;
my $body = $request->body_from_json;
my $notification = $body->{notification};

log_if_fail "Zero badge push request body", $body;

assert_json_keys( $notification->{counts}, qw(
unread
));
assert_eq( $notification->{counts}{unread}, 0, "unread count");

pass "Zero badge push received";

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

0 comments on commit ad85515

Please sign in to comment.