diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2021-02-06 01:03:34 +0000 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2021-02-06 01:03:34 +0000 |
commit | 8a6f5650dec2e43b6dc81c8f7f2fa5baf3be9161 (patch) | |
tree | 38d89654b5b66c70c7e0aab5adcdf4b9508e284b /test | |
parent | Merge branch 'user_impersonation' into 'master' (diff) | |
parent | rename display_name_test and remove get_acount_test (diff) |
Merge branch 'profile_function' into 'master'
Profile function
See merge request uhoreg/polyjuice_client!7
Diffstat (limited to 'test')
6 files changed, 423 insertions, 0 deletions
diff --git a/test/polyjuice/client/endpoint/get_profile_avatar_url_test.exs b/test/polyjuice/client/endpoint/get_profile_avatar_url_test.exs new file mode 100644 index 0000000..e0b756b --- /dev/null +++ b/test/polyjuice/client/endpoint/get_profile_avatar_url_test.exs @@ -0,0 +1,50 @@ +# 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.GetProfileAvatarUrlTest do + use ExUnit.Case + + test "GET /_matrix/client/r0/user/{userId}/avatar_url" do + with endpoint = %Polyjuice.Client.Endpoint.GetProfileAvatarUrl{ + user_id: "@alice:kazarma.local" + } do + http_spec = Polyjuice.Client.Endpoint.Proto.http_spec(endpoint) + + assert http_spec == %Polyjuice.Client.Endpoint.HttpSpec{ + auth_required: true, + headers: [ + {"Accept", "application/json"} + ], + method: :get, + path: "_matrix/client/r0/profile/%40alice%3Akazarma.local/avatar_url" + } + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 200, + [{"Content-Type", "application/json"}], + "{\"avatar_url\": \"mxc://matrix.org/wefh34uihSDRGhw34\"}" + ) == {:ok, "mxc://matrix.org/wefh34uihSDRGhw34"} + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 500, + [], + "Aaah!" + ) == + {:error, 500, + %{"body" => "Aaah!", "errcode" => "CA_UHOREG_POLYJUICE_BAD_RESPONSE"}} + end + end +end diff --git a/test/polyjuice/client/endpoint/get_profile_displayname_test.exs b/test/polyjuice/client/endpoint/get_profile_displayname_test.exs new file mode 100644 index 0000000..8c39a17 --- /dev/null +++ b/test/polyjuice/client/endpoint/get_profile_displayname_test.exs @@ -0,0 +1,50 @@ +# 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.GetProfileDisplaynameTest do + use ExUnit.Case + + test "GET /_matrix/client/r0/profile/{userId}/displayname" do + with endpoint = %Polyjuice.Client.Endpoint.GetProfileDisplayname{ + user_id: "@alice:kazarma.local" + } do + http_spec = Polyjuice.Client.Endpoint.Proto.http_spec(endpoint) + + assert http_spec == %Polyjuice.Client.Endpoint.HttpSpec{ + auth_required: true, + headers: [ + {"Accept", "application/json"} + ], + method: :get, + path: "_matrix/client/r0/profile/%40alice%3Akazarma.local/displayname" + } + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 200, + [{"Content-Type", "application/json"}], + "{\"displayname\": \"alice\"}" + ) == {:ok, "alice"} + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 500, + [], + "Aaah!" + ) == + {:error, 500, + %{"body" => "Aaah!", "errcode" => "CA_UHOREG_POLYJUICE_BAD_RESPONSE"}} + end + end +end diff --git a/test/polyjuice/client/endpoint/get_profile_test.exs b/test/polyjuice/client/endpoint/get_profile_test.exs new file mode 100644 index 0000000..4f2624b --- /dev/null +++ b/test/polyjuice/client/endpoint/get_profile_test.exs @@ -0,0 +1,50 @@ +# 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.GetProfileTest do + use ExUnit.Case + + test "GET profile/{user_id}" do + endpoint = %Polyjuice.Client.Endpoint.GetProfile{ + user_id: "@alice:kazarma.local" + } + + http_spec = Polyjuice.Client.Endpoint.Proto.http_spec(endpoint) + + assert http_spec == %Polyjuice.Client.Endpoint.HttpSpec{ + auth_required: true, + body: "", + headers: [ + {"Accept", "application/json"} + ], + method: :get, + path: "_matrix/client/r0/profile/%40alice%3Akazarma.local" + } + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 200, + [{"Content-Type", "application/json"}], + "[{\"avatar_url\": \"yoyo\", \"displayname\": \"polo\"}]" + ) == {:ok, [%{"avatar_url" => "yoyo", "displayname" => "polo"}]} + + 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/put_profile_avatar_url_test.exs b/test/polyjuice/client/endpoint/put_profile_avatar_url_test.exs new file mode 100644 index 0000000..5caf235 --- /dev/null +++ b/test/polyjuice/client/endpoint/put_profile_avatar_url_test.exs @@ -0,0 +1,52 @@ +# Copyright 2020 Multi Prise <multipriseestunhappydev@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.PutProfileAvatarUrlTest do + use ExUnit.Case + + test "PUT /_matrix/client/r0/profile/{userId}/avatar_url" do + endpoint = %Polyjuice.Client.Endpoint.PutProfileAvatarUrl{ + user_id: "@alice:homeserver.local", + avatar_url: "mxc://matrix.org/wefh34uihSDRGhw34" + } + + http_spec = Polyjuice.Client.Endpoint.Proto.http_spec(endpoint) + + assert http_spec == %Polyjuice.Client.Endpoint.HttpSpec{ + auth_required: true, + body: "{\"avatar_url\":\"mxc://matrix.org/wefh34uihSDRGhw34\"}", + headers: [ + {"Accept", "application/json"}, + {"Content-Type", "application/json"} + ], + method: :put, + path: "_matrix/client/r0/profile/%40alice%3Ahomeserver.local/avatar_url" + } + + 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/put_profile_displayname_test.exs b/test/polyjuice/client/endpoint/put_profile_displayname_test.exs new file mode 100644 index 0000000..10f2ae1 --- /dev/null +++ b/test/polyjuice/client/endpoint/put_profile_displayname_test.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.PutProfileDisplaynameTest do + use ExUnit.Case + + test "PUT /_matrix/client/r0/profile/{userId}/displayname" do + endpoint = %Polyjuice.Client.Endpoint.PutProfileDisplayname{ + user_id: "@alice:kazarma.local", + displayname: "alicecapique" + } + + http_spec = Polyjuice.Client.Endpoint.Proto.http_spec(endpoint) + + assert http_spec == %Polyjuice.Client.Endpoint.HttpSpec{ + auth_required: true, + body: "{\"displayname\":\"alicecapique\"}", + headers: [ + {"Accept", "application/json"}, + {"Content-Type", "application/json"} + ], + method: :put, + path: "_matrix/client/r0/profile/%40alice%3Akazarma.local/displayname" + } + + 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/profile_test.exs b/test/polyjuice/client/profile_test.exs new file mode 100644 index 0000000..cf08a5b --- /dev/null +++ b/test/polyjuice/client/profile_test.exs @@ -0,0 +1,169 @@ +# 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.ProfileTest do + use ExUnit.Case + doctest Polyjuice.Client.Profile + + test "get_profile" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.GetProfile{ + user_id: "@amelie:example.org" + }, + {:ok, %{avatar_url: "mxc://matrix.org/SDGdghriugerRg", displayname: "poulain"}} + } + } do + {:ok, data} = Polyjuice.Client.Profile.get_profile(client, "@amelie:example.org") + assert data[:displayname] == "poulain" + assert data[:avatar_url] == "mxc://matrix.org/SDGdghriugerRg" + end + end + + test "get_profile without user_id" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.GetProfile{ + user_id: "@alice:example.org" + }, + {:ok, %{avatar_url: "mxc://matrix.org/SDGdghriugerRg", displayname: "poulain"}} + } + } do + {:ok, data} = Polyjuice.Client.Profile.get_profile(client) + assert data[:displayname] == "poulain" + assert data[:avatar_url] == "mxc://matrix.org/SDGdghriugerRg" + end + end + + test "get avatar url" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.GetProfileAvatarUrl{ + user_id: "@alice:example.org" + }, + {:ok, "mxc://matrix.org/wefh34uihSDRGhw34"} + } + } do + {:ok, avatar_url} = Polyjuice.Client.Profile.get_avatar_url(client, "@alice:example.org") + assert avatar_url == "mxc://matrix.org/wefh34uihSDRGhw34" + end + end + + test "get avatar url without user_id" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.GetProfileAvatarUrl{ + user_id: "@alice:example.org" + }, + {:ok, "mxc://matrix.org/wefh34uihSDRGhw34"} + } + } do + {:ok, avatar_url} = Polyjuice.Client.Profile.get_avatar_url(client) + assert avatar_url == "mxc://matrix.org/wefh34uihSDRGhw34" + end + end + + test "modify avatar url" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.PutProfileAvatarUrl{ + user_id: "@alice:example.org", + avatar_url: "mxc://matrix.org/wefh34uihSDRGhw34" + }, + {:ok} + } + } do + {:ok} = + Polyjuice.Client.Profile.put_avatar_url( + client, + "@alice:example.org", + "mxc://matrix.org/wefh34uihSDRGhw34" + ) + end + end + + test "modify avatar url without user_id" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.PutProfileAvatarUrl{ + user_id: "@alice:example.org", + avatar_url: "mxc://matrix.org/wefh34uihSDRGhw34" + }, + {:ok} + } + } do + {:ok} = + Polyjuice.Client.Profile.put_avatar_url( + client, + "mxc://matrix.org/wefh34uihSDRGhw34" + ) + end + end + + test "get displayname" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.GetProfileDisplayname{ + user_id: "@alice:example.org" + }, + {:ok, "alice"} + } + } do + {:ok, displayname} = Polyjuice.Client.Profile.get_displayname(client, "@alice:example.org") + assert displayname == "alice" + end + end + + test "get displayname wihout user_id" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.GetProfileDisplayname{ + user_id: "@alice:example.org" + }, + {:ok, "alice"} + } + } do + {:ok, displayname} = Polyjuice.Client.Profile.get_displayname(client) + assert displayname == "alice" + end + end + + test "modify displayname" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.PutProfileDisplayname{ + user_id: "@alice:example.org", + displayname: "marie" + }, + {:ok} + } + } do + {:ok} = Polyjuice.Client.Profile.put_displayname(client, "@alice:example.org", "marie") + end + end + + test "modify displayname without user_id" do + with client = %DummyClient{ + response: { + %Polyjuice.Client.Endpoint.PutProfileDisplayname{ + user_id: "@alice:example.org", + displayname: "marie" + }, + {:ok} + } + } do + {:ok} = Polyjuice.Client.Profile.put_displayname(client, "marie") + end + end +end |