diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2020-04-24 22:50:08 -0400 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2020-04-24 22:50:08 -0400 |
commit | cb38dd8062350fd7ca9e56e91c24785780036538 (patch) | |
tree | ea76ea0a168fbe90db149e9aa8e1d03671b5c7f9 | |
parent | use a protocol for transforming HTTP responses (diff) |
more tests
-rw-r--r-- | test/polyjuice/client/endpoint/get_rooms_messages_test.exs | 74 | ||||
-rw-r--r-- | test/polyjuice/client/endpoint/get_sync_test.exs | 86 |
2 files changed, 160 insertions, 0 deletions
diff --git a/test/polyjuice/client/endpoint/get_rooms_messages_test.exs b/test/polyjuice/client/endpoint/get_rooms_messages_test.exs new file mode 100644 index 0000000..f38a8ac --- /dev/null +++ b/test/polyjuice/client/endpoint/get_rooms_messages_test.exs @@ -0,0 +1,74 @@ +# 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.GetRoomsMessagesTest do + use ExUnit.Case + + test "GET rooms/{roomId}/messages" do + with endpoint = %Polyjuice.Client.Endpoint.GetRoomsMessages{ + room: "!roomid", + from: "token", + dir: :forward + } do + 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/%21roomid/messages?from=token&dir=f" + } + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 200, + [], + "{}" + ) == {:ok, %{}} + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 500, + [], + "Aaah!" + ) == {:error, 500, "Aaah!"} + end + + with endpoint = %Polyjuice.Client.Endpoint.GetRoomsMessages{ + room: "!roomid", + from: "token", + to: "endtoken", + dir: :backward, + limit: 20, + filter: %{} + } do + 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/%21roomid/messages?from=token&dir=b&to=endtoken&limit=20&filter=%7B%7D" + } + end + end +end diff --git a/test/polyjuice/client/endpoint/get_sync_test.exs b/test/polyjuice/client/endpoint/get_sync_test.exs new file mode 100644 index 0000000..babc0d3 --- /dev/null +++ b/test/polyjuice/client/endpoint/get_sync_test.exs @@ -0,0 +1,86 @@ +# 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.GetSyncTest do + use ExUnit.Case + + test "GET sync" do + with endpoint = %Polyjuice.Client.Endpoint.GetSync{} do + 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/sync?timeout=0" + } + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 200, + [], + "{}" + ) == {:ok, %{}} + + assert Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + 500, + [], + "Aaah!" + ) == {:error, 500, "Aaah!"} + end + + with endpoint = %Polyjuice.Client.Endpoint.GetSync{ + filter: "1", + since: "token", + full_state: true, + set_presence: :offline, + timeout: 120 + } do + 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/sync?timeout=120&since=token&full_state=true&filter=1&set_presence=offline" + } + end + + with endpoint = %Polyjuice.Client.Endpoint.GetSync{ + filter: %{}, + set_presence: :unavailable + } do + 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/sync?timeout=0&filter=%7B%7D&set_presence=unavailable" + } + end + end +end |