From 288f8964d08e322f6c3b97152c3fa9de8a215400 Mon Sep 17 00:00:00 2001 From: Kurt Roeckx Date: Sun, 18 Jul 2021 15:49:18 +0200 Subject: [PATCH] Fix usage of typing API - Timeout is a required parameter when starting typing. - The typing parameter takes a bool not an integer. Signed-off-by: Kurt Roeckx --- tests/10apidoc/35room-typing.pl | 54 ++++++++++++++++++++++++++++++++- tests/30rooms/20typing.pl | 2 +- tests/50federation/43typing.pl | 2 ++ tests/90jira/SYN-516.pl | 2 +- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/tests/10apidoc/35room-typing.pl b/tests/10apidoc/35room-typing.pl index 53c6d8c59..b48e30bdf 100644 --- a/tests/10apidoc/35room-typing.pl +++ b/tests/10apidoc/35room-typing.pl @@ -1,3 +1,5 @@ +use JSON qw( decode_json ); + test "PUT /rooms/:room_id/typing/:user_id sets typing notification", requires => [ local_user_and_room_fixtures() ], @@ -10,7 +12,10 @@ method => "PUT", uri => "/r0/rooms/$room_id/typing/:user_id", - content => { typing => JSON::true }, + content => { + typing => JSON::true, + timeout => 30000, + }, )->then( sub { my ( $body ) = @_; @@ -19,3 +24,50 @@ Future->done(1); }); }; + +test "PUT /rooms/:room_id/typing/:user_id without timeout fails", + requires => [ local_user_and_room_fixtures() ], + + proves => [qw( can_set_room_typing )], + + do => sub { + my ( $user, $room_id ) = @_; + + do_request_json_for( $user, + method => "PUT", + uri => "/r0/rooms/$room_id/typing/:user_id", + + content => { typing => JSON::true }, + )->main::expect_http_400() + ->then( sub { + my ( $response ) = @_; + my $body = decode_json( $response->content ); + assert_eq( $body->{errcode}, "M_BAD_JSON", 'responsecode' ); + Future->done( 1 ); + }); + }; + +test "PUT /rooms/:room_id/typing/:user_id with invalid json fails", + requires => [ local_user_and_room_fixtures() ], + + proves => [qw( can_set_room_typing )], + + do => sub { + my ( $user, $room_id ) = @_; + + do_request_json_for( $user, + method => "PUT", + uri => "/r0/rooms/$room_id/typing/:user_id", + + content => { + typing => 1, + timeout => 30000, + }, + )->main::expect_http_400() + ->then( sub { + my ( $response ) = @_; + my $body = decode_json( $response->content ); + assert_eq( $body->{errcode}, "M_BAD_JSON", 'responsecode' ); + Future->done( 1 ); + }); + }; diff --git a/tests/30rooms/20typing.pl b/tests/30rooms/20typing.pl index d61ac8c90..2fc6dcadf 100644 --- a/tests/30rooms/20typing.pl +++ b/tests/30rooms/20typing.pl @@ -4,7 +4,7 @@ =head1 matrix_typing - matrix_typing($user, $room_id, typing => 1, timeout => 30000)->get; + matrix_typing($user, $room_id, typing => JSON::true, timeout => 30000)->get; Mark the user as typing. diff --git a/tests/50federation/43typing.pl b/tests/50federation/43typing.pl index 1cf5e0c38..4fb6b288c 100644 --- a/tests/50federation/43typing.pl +++ b/tests/50federation/43typing.pl @@ -25,6 +25,7 @@ room_id => $room_id, user_id => $creator->user_id, typing => JSON::true, + timeout => 30000, }, ); })->then( sub { @@ -36,6 +37,7 @@ room_id => $room_id, user_id => $user_id, typing => JSON::true, + timeout => 30000, }, ); })->then( sub { diff --git a/tests/90jira/SYN-516.pl b/tests/90jira/SYN-516.pl index 5323a425a..94760478e 100644 --- a/tests/90jira/SYN-516.pl +++ b/tests/90jira/SYN-516.pl @@ -23,7 +23,7 @@ })->then( sub { ( $room_id ) = @_; - matrix_typing( $user, $room_id, typing => 1, timeout => 30000 ) + matrix_typing( $user, $room_id, typing => JSON::true, timeout => 30000 ) ->SyTest::pass_on_done( "Sent typing notification" ); })->then( sub { matrix_send_room_message( $user, $room_id,