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 for sending to_device messages to multiple recipients at once #856

Merged
merged 2 commits into from
Apr 30, 2020
Merged
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
64 changes: 63 additions & 1 deletion tests/46direct/01directmessage.pl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ sub matrix_recv_device_message
} until => sub {
my ( $f ) = @_;
return 1 if $f->failure;
scalar @{ $f->get->{to_device}{events} };
my $resp = $f->get;
log_if_fail "Sync response", $resp;
return scalar @{ $resp->{to_device}{events} };
};

$f->then( sub {
Expand Down Expand Up @@ -153,3 +155,63 @@ sub matrix_recv_and_ack_device_message
Future->done(1);
});
};

test "Can send a to-device message to two users which both receive it using /sync",
requires => [ local_user_fixture(), local_user_fixture(), local_user_fixture(), qw( can_recv_device_message ) ],

check => sub {
my ( $sender, $recip1, $recip2 ) = @_;

# do initial syncs for each recipient
matrix_sync( $recip1 )
->then( sub {
my ( $body ) = @_;
$recip1->device_message_next_batch = $body->{next_batch};

matrix_sync( $recip2 );
})->then( sub {
my ( $body ) = @_;
$recip2->device_message_next_batch = $body->{next_batch};

# send the message
matrix_send_device_message(
$sender,
type => "my.test.type",
messages => {
$recip1->user_id => {
$recip1->device_id => {
my_key => "r1",
},
},
$recip2->user_id => {
$recip2->device_id => {
my_key => "r2",
},
},
},
);
})->then( sub {
log_if_fail "sent to-device messages";
matrix_recv_and_ack_device_message( $recip1 );
})->then( sub {
my ( $messages ) = @_;

assert_deeply_eq( $messages, [{
sender => $sender->user_id,
type => "my.test.type",
content => { my_key => "r1" },
}]);

matrix_recv_and_ack_device_message( $recip2 );
})->then( sub {
my ( $messages ) = @_;

assert_deeply_eq( $messages, [{
sender => $sender->user_id,
type => "my.test.type",
content => { my_key => "r2" },
}]);

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