diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2020-04-21 19:22:56 -0400 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2020-04-21 19:24:43 -0400 |
commit | e54a74a76eed8de5a052da72bb21f6fd13c5cf4b (patch) | |
tree | 53aca70302bfbfe3275a29798e48fe314f5febdd /test/polyjuice | |
parent | fix login endpoint add logout endpoint, and add functions for logging in/out (diff) |
add some tests and some cleanups
Diffstat (limited to 'test/polyjuice')
-rw-r--r-- | test/polyjuice/client/endpoint/post_logout_test.exs | 43 | ||||
-rw-r--r-- | test/polyjuice/client/room_test.exs | 38 | ||||
-rw-r--r-- | test/polyjuice/client_test.exs | 105 |
3 files changed, 185 insertions, 1 deletions
diff --git a/test/polyjuice/client/endpoint/post_logout_test.exs b/test/polyjuice/client/endpoint/post_logout_test.exs new file mode 100644 index 0000000..a7a10f5 --- /dev/null +++ b/test/polyjuice/client/endpoint/post_logout_test.exs @@ -0,0 +1,43 @@ +# 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.PostLogoutTest do + use ExUnit.Case + + test "POST logout" do + endpoint = %Polyjuice.Client.Endpoint.PostLogout{} + + http_spec = Polyjuice.Client.Endpoint.Proto.http_spec(endpoint, "https://example.com") + + assert %{http_spec | transform: nil} == %Polyjuice.Client.Endpoint.HttpSpec{ + auth_required: true, + body: "{}", + headers: [ + {"Accept", "application/json"}, + {"Content-Type", "application/json"} + ], + method: :post, + transform: nil, + url: "https://example.com/_matrix/client/r0/logout" + } + + assert http_spec.transform.( + 200, + [], + "{}" + ) == :ok + + assert http_spec.transform.(500, [], "Aaah!") == {:error, 500, "Aaah!"} + end +end diff --git a/test/polyjuice/client/room_test.exs b/test/polyjuice/client/room_test.exs index 83885cb..bb86be1 100644 --- a/test/polyjuice/client/room_test.exs +++ b/test/polyjuice/client/room_test.exs @@ -1,4 +1,4 @@ -# Copyright 2019 Hubert Chathi <hubert@uhoreg.ca> +# Copyright 2019-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. @@ -143,6 +143,14 @@ defmodule Polyjuice.Client.RoomTest do ) assert event_id == "$foo1" + + {:ok, ^event_id} = + Polyjuice.Client.Room.send_state_event( + client, + "!bar", + "m.room.name", + %{"name" => "foo"} + ) end end @@ -161,4 +169,32 @@ defmodule Polyjuice.Client.RoomTest do {:ok} = Polyjuice.Client.Room.update_read_receipt(client, "!room", "$event") end end + + test "join room" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.PostJoin{ + room: "!room", + servers: [], + third_party_signed: nil + }, + {:ok, "!room"} + } + } do + {:ok, "!room"} = Polyjuice.Client.Room.join(client, "!room") + end + + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.PostJoin{ + room: "!room", + servers: ["example.org"], + third_party_signed: %{} + }, + {:ok, "!room"} + } + } do + {:ok, "!room"} = Polyjuice.Client.Room.join(client, "!room", ["example.org"], %{}) + end + end end diff --git a/test/polyjuice/client_test.exs b/test/polyjuice/client_test.exs new file mode 100644 index 0000000..d8274af --- /dev/null +++ b/test/polyjuice/client_test.exs @@ -0,0 +1,105 @@ +# 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.ClientTest do + use ExUnit.Case + + test "log in" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.PostLogin{ + type: "m.login.password", + identifier: %{ + "type" => "m.id.user", + "user" => "user" + }, + password: "password" + }, + {:ok, %{}} + } + } do + {:ok, %{}} = Polyjuice.Client.log_in_with_password(client, "user", "password") + end + + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.PostLogin{ + type: "m.login.password", + identifier: %{ + "type" => "m.id.thirdparty", + "medium" => "email", + "address" => "user@example.com" + }, + password: "password", + device_id: "device_id", + initial_device_display_name: "Device name" + }, + {:ok, %{}} + } + } do + {:ok, %{}} = + Polyjuice.Client.log_in_with_password( + client, + {:email, "user@example.com"}, + "password", + device_id: "device_id", + initial_device_display_name: "Device name" + ) + end + + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.PostLogin{ + type: "m.login.password", + identifier: %{ + "type" => "m.id.phone", + "country" => "CA", + "phone" => "1234567890" + }, + password: "password" + }, + {:ok, %{}} + } + } do + {:ok, %{}} = + Polyjuice.Client.log_in_with_password( + client, + {:phone, "CA", "1234567890"}, + "password" + ) + + {:ok, %{}} = + Polyjuice.Client.log_in_with_password( + client, + %{ + "type" => "m.id.phone", + "country" => "CA", + "phone" => "1234567890" + }, + "password" + ) + end + end + + test "log out" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.PostLogout{}, + :ok + } + } do + :ok = Polyjuice.Client.log_out(client) + end + end +end |