diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2020-08-16 11:50:29 -0400 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2020-08-16 11:50:29 -0400 |
commit | 81734318fd677fe7061183457c39e09b0763773c (patch) | |
tree | cc72fcbf5e33dda5e2b77fa8725299d7e9995e5e /test/polyjuice/client | |
parent | allow body to be iolist or a filename, and add media upload/download (diff) |
move some client state to an Agent, and make http_spec take a URI struct
Diffstat (limited to 'test/polyjuice/client')
-rw-r--r-- | test/polyjuice/client/media_test.exs | 15 | ||||
-rw-r--r-- | test/polyjuice/client/sync_test.exs | 19 | ||||
-rw-r--r-- | test/polyjuice/client/user_test.exs | 105 |
3 files changed, 20 insertions, 119 deletions
diff --git a/test/polyjuice/client/media_test.exs b/test/polyjuice/client/media_test.exs index c9d8df9..b4899ca 100644 --- a/test/polyjuice/client/media_test.exs +++ b/test/polyjuice/client/media_test.exs @@ -86,12 +86,13 @@ defmodule Polyjuice.Client.MediaTest do port = :httpd.info(httpd_pid) |> Keyword.fetch!(:port) - client = %Polyjuice.Client{ - base_url: "http://127.0.0.1:#{port}/Elixir.Polyjuice.Client.MediaTest.Httpd/", - access_token: "an_access_token", - user_id: "@alice:example.org", - test: true - } + client = + Polyjuice.Client.start( + "http://127.0.0.1:#{port}/Elixir.Polyjuice.Client.MediaTest.Httpd", + access_token: "an_access_token", + user_id: "@alice:example.org", + test: true + ) {:ok, url} = Polyjuice.Client.Media.upload(client, {:file, "mix.exs"}) @@ -104,6 +105,8 @@ defmodule Polyjuice.Client.MediaTest do assert content_type == "text/plain" assert Enum.join(body) == "foo" + Polyjuice.Client.stop(client) + :inets.stop(:httpd, httpd_pid) after File.rm_rf(tmpdir) diff --git a/test/polyjuice/client/sync_test.exs b/test/polyjuice/client/sync_test.exs index b1f2752..c1b4f64 100644 --- a/test/polyjuice/client/sync_test.exs +++ b/test/polyjuice/client/sync_test.exs @@ -17,7 +17,7 @@ defmodule Polyjuice.Client.SyncTest do defmodule Httpd do def _matrix(session_id, env, input) do - # FIXME: check authorization header + assert Keyword.get(env, :http_authorization) == 'Bearer an_access_token' # FIXME: check method [path | _] = Keyword.get(env, :path_info) @@ -213,13 +213,14 @@ defmodule Polyjuice.Client.SyncTest do port = :httpd.info(httpd_pid) |> Keyword.fetch!(:port) - client = %Polyjuice.Client{ - base_url: "http://127.0.0.1:#{port}/Elixir.Polyjuice.Client.SyncTest.Httpd", - access_token: "an_access_token", - user_id: "@alice:example.org", - storage: storage, - test: true - } + client = + Polyjuice.Client.start( + "http://127.0.0.1:#{port}/Elixir.Polyjuice.Client.SyncTest.Httpd", + access_token: "an_access_token", + user_id: "@alice:example.org", + storage: storage, + test: true + ) {:ok, sync_pid} = Polyjuice.Client.API.sync_child_spec(client, self(), filter: %{}) @@ -307,6 +308,8 @@ defmodule Polyjuice.Client.SyncTest do Process.unlink(sync_pid) Process.exit(sync_pid, :kill) + Polyjuice.Client.stop(client) + :inets.stop(:httpd, httpd_pid) after Polyjuice.Client.Storage.close(storage) diff --git a/test/polyjuice/client/user_test.exs b/test/polyjuice/client/user_test.exs deleted file mode 100644 index 06b95bd..0000000 --- a/test/polyjuice/client/user_test.exs +++ /dev/null @@ -1,105 +0,0 @@ -# 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.UserTest 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.User.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.User.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.User.log_in_with_password( - client, - {:phone, "CA", "1234567890"}, - "password" - ) - - {:ok, %{}} = - Polyjuice.Client.User.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.User.log_out(client) - end - end -end |