summaryrefslogtreecommitdiff
path: root/test/polyjuice
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2019-10-07 22:38:48 -0400
committerHubert Chathi <hubert@uhoreg.ca>2019-10-07 22:38:48 -0400
commit040ac4289cf94c903445c96b378976b6a64bd54d (patch)
treec22132305f1f4b52f16fedfd7d3be750c93055a7 /test/polyjuice
parentmake sync more robust, and send messages with connection status (diff)
send more information to listeners and add support for joining
Diffstat (limited to 'test/polyjuice')
-rw-r--r--test/polyjuice/client/endpoint/post_join_test.exs87
1 files changed, 87 insertions, 0 deletions
diff --git a/test/polyjuice/client/endpoint/post_join_test.exs b/test/polyjuice/client/endpoint/post_join_test.exs
new file mode 100644
index 0000000..71010bf
--- /dev/null
+++ b/test/polyjuice/client/endpoint/post_join_test.exs
@@ -0,0 +1,87 @@
+# Copyright 2019 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.PostJoinTest do
+ use ExUnit.Case
+
+ test "POST join/{roomIdOrAlias}" do
+ with endpoint = %Polyjuice.Client.Endpoint.PostJoin{
+ room: "!room",
+ third_party_signed: %{
+ "sender" => "@alice:example.org",
+ "mxid" => "@bob:example.org",
+ "token" => "random8nonce",
+ "signatures" => %{
+ "example.org" => %{
+ "ed25519:0" => "some9signature"
+ }
+ }
+ }
+ } do
+
+ http_spec = Polyjuice.Client.Endpoint.Proto.http_spec(endpoint, "https://example.com")
+
+ assert %{http_spec | transform: nil, body: nil} == %Polyjuice.Client.Endpoint.HttpSpec{
+ auth_required: true,
+ body: nil,
+ headers: [
+ {"Accept", "application/json"},
+ {"Content-Type", "application/json"}
+ ],
+ method: :post,
+ transform: nil,
+ url: "https://example.com/_matrix/client/r0/join/%21room"
+ }
+
+ assert Poison.decode!(http_spec.body) == %{
+ "third_party_signed" => %{
+ "sender" => "@alice:example.org",
+ "mxid" => "@bob:example.org",
+ "token" => "random8nonce",
+ "signatures" => %{
+ "example.org" => %{
+ "ed25519:0" => "some9signature"
+ }
+ }
+ }
+ }
+
+ assert http_spec.transform.(200, [], ~s({"room_id":"!room"})) == {:ok, "!room"}
+
+ assert http_spec.transform.(500, [], "Aaah!") == {:error, 500, "Aaah!"}
+ end
+
+ with endpoint = %Polyjuice.Client.Endpoint.PostJoin{
+ room: "!room",
+ servers: ["example.com", "example.org"]
+ } do
+
+ 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/join/%21room?server_name=example.com&server_name=example.org"
+ }
+
+ assert http_spec.transform.(200, [], ~s({"room_id":"!room"})) == {:ok, "!room"}
+ end
+ end
+end