diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2020-09-21 19:07:54 -0400 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2020-09-21 19:07:54 -0400 |
commit | 0cd322d20b34eb4141327daedb19e15fe2f07e83 (patch) | |
tree | c8f3a8ce585fad2c2e284b3b0c073b00e6add660 /test/polyjuice | |
parent | return :ok instead of {:ok} (diff) |
add functions for leaving/forgetting rooms
Diffstat (limited to 'test/polyjuice')
-rw-r--r-- | test/polyjuice/client/endpoint/post_rooms_forget_test.exs | 48 | ||||
-rw-r--r-- | test/polyjuice/client/endpoint/post_rooms_leave_test.exs | 48 | ||||
-rw-r--r-- | test/polyjuice/client/room_test.exs | 22 |
3 files changed, 118 insertions, 0 deletions
diff --git a/test/polyjuice/client/endpoint/post_rooms_forget_test.exs b/test/polyjuice/client/endpoint/post_rooms_forget_test.exs new file mode 100644 index 0000000..a2ce841 --- /dev/null +++ b/test/polyjuice/client/endpoint/post_rooms_forget_test.exs @@ -0,0 +1,48 @@ +# Copyright 2020 Hubert Chathi <hubert@uhoreg.ca> +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +defmodule Polyjuice.Client.Endpoint.PostRoomsForgetTest do + use ExUnit.Case + + test "POST rooms/{roomId}/forget" do + endpoint = %Polyjuice.Client.Endpoint.PostRoomsForget{room: "!room"} + http_spec = Polyjuice.Client.Endpoint.Proto.http_spec(endpoint) + + assert http_spec == %Polyjuice.Client.Endpoint.HttpSpec{ + auth_required: true, + body: "{}", + headers: [ + {"Accept", "application/json"}, + {"Content-Type", "application/json"} + ], + method: :post, + path: "_matrix/client/r0/rooms/%21room/forget" + } + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 200, + [{"Content-Type", "application/json"}], + "{}" + ) == :ok + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 500, + [], + "Aaah!" + ) == + {:error, 500, %{"body" => "Aaah!", "errcode" => "CA_UHOREG_POLYJUICE_BAD_RESPONSE"}} + end +end diff --git a/test/polyjuice/client/endpoint/post_rooms_leave_test.exs b/test/polyjuice/client/endpoint/post_rooms_leave_test.exs new file mode 100644 index 0000000..d3448ef --- /dev/null +++ b/test/polyjuice/client/endpoint/post_rooms_leave_test.exs @@ -0,0 +1,48 @@ +# Copyright 2020 Hubert Chathi <hubert@uhoreg.ca> +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +defmodule Polyjuice.Client.Endpoint.PostRoomsLeaveTest do + use ExUnit.Case + + test "POST rooms/{roomId}/leave" do + endpoint = %Polyjuice.Client.Endpoint.PostRoomsLeave{room: "!room"} + http_spec = Polyjuice.Client.Endpoint.Proto.http_spec(endpoint) + + assert http_spec == %Polyjuice.Client.Endpoint.HttpSpec{ + auth_required: true, + body: "{}", + headers: [ + {"Accept", "application/json"}, + {"Content-Type", "application/json"} + ], + method: :post, + path: "_matrix/client/r0/rooms/%21room/leave" + } + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 200, + [{"Content-Type", "application/json"}], + "{}" + ) == :ok + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 500, + [], + "Aaah!" + ) == + {:error, 500, %{"body" => "Aaah!", "errcode" => "CA_UHOREG_POLYJUICE_BAD_RESPONSE"}} + end +end diff --git a/test/polyjuice/client/room_test.exs b/test/polyjuice/client/room_test.exs index b45f607..a1e0dfa 100644 --- a/test/polyjuice/client/room_test.exs +++ b/test/polyjuice/client/room_test.exs @@ -244,6 +244,28 @@ defmodule Polyjuice.Client.RoomTest do end end + test "leave room" do + client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.PostRoomsLeave{room: "!room"}, + :ok + } + } + + :ok = Polyjuice.Client.Room.leave(client, "!room") + end + + test "forget room" do + client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.PostRoomsForget{room: "!room"}, + :ok + } + } + + :ok = Polyjuice.Client.Room.forget(client, "!room") + end + test "get messages" do with client = %DummyClient{ response: { |