diff options
-rw-r--r-- | Changelog | 1 | ||||
-rw-r--r-- | lib/Matrix/Client.rakumod | 25 | ||||
-rw-r--r-- | lib/Matrix/Client/Room.rakumod | 6 | ||||
-rw-r--r-- | t/20-client.t | 45 | ||||
-rw-r--r-- | t/30-room.t | 31 |
5 files changed, 84 insertions, 24 deletions
@@ -1,6 +1,7 @@ current ======= +* Fix ban, unban, invite and kick methods caused by parameters with dash * Add `room` heper method * Add read-markers API support * Add typing api support diff --git a/lib/Matrix/Client.rakumod b/lib/Matrix/Client.rakumod index 5c5751f..0c801d6 100644 --- a/lib/Matrix/Client.rakumod +++ b/lib/Matrix/Client.rakumod @@ -235,46 +235,35 @@ method join-room($room-id!) { #| POST - /_matrix/client/r0/rooms/{roomId}/ban method ban(Str $room-id, Str $user-id, $reason = "") { - $.post( - "/rooms/$room-id/ban", - :$user-id, - :$reason - ); + $.room($room-id).ban($user-id, :$reason) } #| POST - /_matrix/client/r0/rooms/{roomId}/unban method unban(Str $room-id, Str $user-id) { - $.post( - "/rooms/$room-id/unban", - :$user-id - ); + $.room($room-id).unban($user-id) } #| POST - /_matrix/client/r0/rooms/{roomId}/invite method invite(Str $room-id, Str $user-id) { - $.post( - "/rooms/$room-id/invite", - :$user-id - ) + $.room($room-id).invite($user-id) } #| POST - /_matrix/client/r0/rooms/{roomId}/forget method forget(Str $room-id) { - $.post("/rooms/$room-id/forget") + $.room($room-id).forget() } #| POST - /_matrix/client/r0/rooms/{roomId}/kick method kick(Str $room-id, Str $user-id, $reason = "") { - $.post( - "/rooms/$room-id/kick", - :$user-id, + $.room($room-id).kick( + $user-id, :$reason ); } #| POST - /_matrix/client/r0/rooms/{roomId}/leave method leave-room($room-id) { - $.post("/rooms/$room-id/leave"); + $.room($room-id).leave } #| GET - /_matrix/client/r0/joined_rooms diff --git a/lib/Matrix/Client/Room.rakumod b/lib/Matrix/Client/Room.rakumod index 1a6908f..8b86108 100644 --- a/lib/Matrix/Client/Room.rakumod +++ b/lib/Matrix/Client/Room.rakumod @@ -191,19 +191,19 @@ method forget { #| POST - /_matrix/client/r0/rooms/{roomId}/kick method kick(Str $user-id, Str $reason = "") { - $.post('/kick', :$user-id, :$reason) + $.post('/kick', :user_id($user-id), :$reason) } ## Banning users #| POST - /_matrix/client/r0/rooms/{roomId}/ban method ban(Str $user-id, $reason = "") { - $.post('/ban', :$user-id, :$reason) + $.post('/ban', :user_id($user-id), :$reason) } #| POST - /_matrix/client/r0/rooms/{roomId}/unban method unban(Str $user-id) { - $.post('/unban', :$user-id) + $.post('/unban', :user_id($user-id)) } method Str(--> Str) { diff --git a/t/20-client.t b/t/20-client.t index c15d86f..5b46eb6 100644 --- a/t/20-client.t +++ b/t/20-client.t @@ -1,7 +1,7 @@ use lib 'lib'; use Test; use Matrix::Client; -plan 5; +plan 7; unless %*ENV<MATRIX_CLIENT_TEST_SERVER> { skip-rest 'No test server setted'; @@ -20,7 +20,20 @@ subtest 'creation' => { $client .= new(:$home-server, :$device-id); isnt $client.home-server, '', 'home server isnt empty'; isnt $client.device-id, '', 'device-id isnt empty'; - note $client.base-url; +} + +subtest 'register' => { + plan 2; + my Matrix::Client $new-user-client .= new(:$home-server, :$device-id); + my $new-username = ('a'..'z').pick(20).join; + lives-ok { + $new-user-client.register( + $new-username, + 'P4ssw0rd' + ); + }, 'can .register'; + + isnt $new-user-client.access-token, '', 'access-token setted'; } subtest 'login' => { @@ -95,3 +108,31 @@ subtest 'directory' => { message => /M_NOT_FOUND/, "Room not found after delete"; } + +subtest 'ban' => { + plan 2; + my Matrix::Client $new-user-client .= new(:$home-server); + my $new-username = ('a'..'z').pick(20).join; + $new-user-client.register($new-username, 'password'); + my $user-id = $new-user-client.whoami; + + my $room = $client.create-room( + :public, + :preset<public_chat>, + :name("The Grand Duke Pub"), + :topic("All about happy hour"), + :creation_content({ + "m.federate" => False + }) + ); + + $new-user-client.join-room($room.id); + + lives-ok { + $client.ban($room.id, $user-id, :reason<testing>) + }, 'can ban usernames'; + + lives-ok { + $client.unban($room.id, $user-id, :reason<testing>); + }, 'can unban'; +} diff --git a/t/30-room.t b/t/30-room.t index 7eb9dd7..f5b653e 100644 --- a/t/30-room.t +++ b/t/30-room.t @@ -1,7 +1,7 @@ use lib 'lib'; use Test; use Matrix::Client; -plan 12; +plan 14; use-ok 'Matrix::Client::Room'; @@ -107,3 +107,32 @@ subtest 'name' => { $test-room.leave; }; + +subtest 'ban' => { + plan 2; + my Matrix::Client $new-user-client .= new(:$home-server); + my $new-username = ('a'..'z').pick(20).join; + $new-user-client.register($new-username, 'password'); + $new-user-client.join-room($public-room-id); + my $user-id = $new-user-client.whoami; + + my $room = $client.create-room( + :public, + :preset<public_chat>, + :name("The Grand Duke Pub"), + :topic("All about happy hour"), + :creation_content({ + "m.federate" => False + }) + ); + + $new-user-client.join-room($room.id); + + lives-ok { + $room.ban($user-id, :reason<testing>) + }, 'can ban usernames'; + + lives-ok { + $room.unban($user-id, :reason<testing>); + }, 'can unban'; +} |