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

Test unread counts in pushes #224

Merged
merged 5 commits into from
Apr 11, 2016
Merged
Changes from 3 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
47 changes: 46 additions & 1 deletion tests/61push/01message-pushed.pl
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,20 @@
})->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 {
return 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably don't want to wait for any possible event, because that leads to fragile tests that get upset about things like spurious m.presence updates. Consider looking for just m.room.receipt events maybe?

})->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 @@ -93,14 +103,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 +123,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( HTTP::Response->new( 200, "OK", [], "" ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be an actually-empty body? You didn't supply a Content-Length or connection close or chunked encoding, so bad things will happen. Probably easiest if you don't need the actually-empty response is to

$request->respond_json( {} );

to have it fill in the content length at least.

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);
});
};