Skip to content

Commit

Permalink
Test for sending to_device messages to multiple recipients at once (#856
Browse files Browse the repository at this point in the history
)

I thought we had a bug here, but it turns out we don't. Still, may as well keep
the test.
  • Loading branch information
richvdh authored Apr 30, 2020
1 parent 15e2e73 commit 9eea0ad
Showing 1 changed file with 63 additions and 1 deletion.
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);
});
};

0 comments on commit 9eea0ad

Please sign in to comment.