diff options
author | Pierre de Lacroix <pierre@pdelacroix.com> | 2020-05-09 16:44:13 +0200 |
---|---|---|
committer | Pierre de Lacroix <pierre@pdelacroix.com> | 2020-05-25 23:29:17 +0200 |
commit | 98e40cb578ecec91a1c0842a4e2376cd9953dcfb (patch) | |
tree | 7d63815f6046ec46045e81c05619934b14374312 /test/polyjuice | |
parent | add some more filtering methods and reduce duplicate code (diff) |
add endpoint for getting room state
Diffstat (limited to 'test/polyjuice')
-rw-r--r-- | test/polyjuice/client/endpoint/get_rooms_state_test.exs | 87 | ||||
-rw-r--r-- | test/polyjuice/client/room_test.exs | 46 |
2 files changed, 133 insertions, 0 deletions
diff --git a/test/polyjuice/client/endpoint/get_rooms_state_test.exs b/test/polyjuice/client/endpoint/get_rooms_state_test.exs new file mode 100644 index 0000000..f6e0596 --- /dev/null +++ b/test/polyjuice/client/endpoint/get_rooms_state_test.exs @@ -0,0 +1,87 @@ +# 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.GetRoomsStateTest do + use ExUnit.Case + + test "GET rooms/{room_id}/state" do + endpoint = %Polyjuice.Client.Endpoint.GetRoomsState{ + room: "!room_id", + event_type: nil, + state_key: "" + } + + http_spec = Polyjuice.Client.Endpoint.Proto.http_spec(endpoint, "https://example.com") + + assert http_spec == %Polyjuice.Client.Endpoint.HttpSpec{ + auth_required: true, + body: "", + headers: [ + {"Accept", "application/json"} + ], + method: :get, + url: "https://example.com/_matrix/client/r0/rooms/%21room_id/state" + } + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 200, + [], + "[{\"type\": \"m.room.name\", \"content\": {\"name\": \"foo1\"}}]" + ) == {:ok, [%{"type" => "m.room.name", "content" => %{"name" => "foo1"}}]} + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 500, + [], + "Aaah!" + ) == + {:error, 500, %{"body" => "Aaah!", "errcode" => "CA_UHOREG_POLYJUICE_BAD_RESPONSE"}} + end + + test "GET rooms/{room_id}/state/{event_type}/{state_key}" do + endpoint = %Polyjuice.Client.Endpoint.GetRoomsState{ + room: "!room_id", + event_type: "m.room.name", + state_key: "" + } + + http_spec = Polyjuice.Client.Endpoint.Proto.http_spec(endpoint, "https://example.com") + + assert http_spec == %Polyjuice.Client.Endpoint.HttpSpec{ + auth_required: true, + body: "", + headers: [ + {"Accept", "application/json"} + ], + method: :get, + url: "https://example.com/_matrix/client/r0/rooms/%21room_id/state/m.room.name/" + } + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 200, + [], + "{\"name\": \"foo1\"}" + ) == {:ok, %{"name" => "foo1"}} + + 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 f5470bc..97180b0 100644 --- a/test/polyjuice/client/room_test.exs +++ b/test/polyjuice/client/room_test.exs @@ -154,6 +154,52 @@ defmodule Polyjuice.Client.RoomTest do end end + test "get all state events" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.GetRoomsState{ + room: "!bar", + event_type: nil, + state_key: "" + }, + {:ok, [%{"type" => "m.room.name", "content" => %{"name" => "foo1"}}]} + } + } do + {:ok, events_list} = + Polyjuice.Client.Room.get_state( + client, + "!bar", + nil, + "" + ) + + assert events_list == [%{"type" => "m.room.name", "content" => %{"name" => "foo1"}}] + end + end + + test "get one state event" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.GetRoomsState{ + room: "!bar", + event_type: "m.room.name", + state_key: "" + }, + {:ok, %{"name" => "foo1"}} + } + } do + {:ok, event_content} = + Polyjuice.Client.Room.get_state( + client, + "!bar", + "m.room.name", + "" + ) + + assert event_content == %{"name" => "foo1"} + end + end + test "update read receipt" do with client = %DummyClient{ response: { |