diff options
Diffstat (limited to 'test/polyjuice/client/endpoint/put_room_alias.exs')
-rw-r--r-- | test/polyjuice/client/endpoint/put_room_alias.exs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/polyjuice/client/endpoint/put_room_alias.exs b/test/polyjuice/client/endpoint/put_room_alias.exs new file mode 100644 index 0000000..203a7ab --- /dev/null +++ b/test/polyjuice/client/endpoint/put_room_alias.exs @@ -0,0 +1,52 @@ +# Copyright 2020 Multi Prise <multiestunhappydev@gmail.com> +# +# 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.PutRoomAliasTest do + use ExUnit.Case + + test "PUT room/{room_alias}" do + endpoint = %Polyjuice.Client.Endpoint.PutRoomsSend{ + room: "!room_id", + room_alias: "!room_alias" + } + + http_spec = Polyjuice.Client.Endpoint.Proto.http_spec(endpoint) + + assert TestUtil.http_spec_body_to_binary(http_spec) == %Polyjuice.Client.Endpoint.HttpSpec{ + auth_required: true, + body: ~s({"body":"Hello World!"}), + headers: [ + {"Accept", "application/json"}, + {"Content-Type", "application/json"} + ], + method: :put, + url: "https://example.com/_matrix/client/r0/room/%21room_alias" + } + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 200, + [{"Content-Type", "application/json"}], + "{\"room_id\": \"$foo1\", \"room_alias\": \"$bar\"}" + ) == {:ok, "$bar:exampke.com"} + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 500, + [], + "Aaah!" + ) == + {:error, 500, %{"body" => "Aaah!", "errcode" => "CA_UHOREG_POLYJUICE_BAD_RESPONSE"}} + end +end |