summaryrefslogtreecommitdiff
path: root/test/polyjuice
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2020-08-21 19:03:00 -0400
committerHubert Chathi <hubert@uhoreg.ca>2020-08-21 19:03:00 -0400
commit062b89962018f88c9390d7ba0822a99c68756c94 (patch)
tree982cbd9b21194284110c367a65f76890e9a072cc /test/polyjuice
parentadd lower-level client, acting like the old client (diff)
automatically start sync process
Diffstat (limited to 'test/polyjuice')
-rw-r--r--test/polyjuice/client/media_test.exs3
-rw-r--r--test/polyjuice/client/sync_test.exs121
-rw-r--r--test/polyjuice/client_test.exs97
3 files changed, 115 insertions, 106 deletions
diff --git a/test/polyjuice/client/media_test.exs b/test/polyjuice/client/media_test.exs
index b4899ca..4c545ac 100644
--- a/test/polyjuice/client/media_test.exs
+++ b/test/polyjuice/client/media_test.exs
@@ -87,10 +87,11 @@ defmodule Polyjuice.Client.MediaTest do
port = :httpd.info(httpd_pid) |> Keyword.fetch!(:port)
client =
- Polyjuice.Client.start(
+ Polyjuice.Client.start_link(
"http://127.0.0.1:#{port}/Elixir.Polyjuice.Client.MediaTest.Httpd",
access_token: "an_access_token",
user_id: "@alice:example.org",
+ sync: false,
test: true
)
diff --git a/test/polyjuice/client/sync_test.exs b/test/polyjuice/client/sync_test.exs
index c1b4f64..a910c14 100644
--- a/test/polyjuice/client/sync_test.exs
+++ b/test/polyjuice/client/sync_test.exs
@@ -214,100 +214,99 @@ defmodule Polyjuice.Client.SyncTest do
port = :httpd.info(httpd_pid) |> Keyword.fetch!(:port)
client =
- Polyjuice.Client.start(
+ Polyjuice.Client.start_link(
"http://127.0.0.1:#{port}/Elixir.Polyjuice.Client.SyncTest.Httpd",
access_token: "an_access_token",
user_id: "@alice:example.org",
+ handler: self(),
storage: storage,
+ sync_filter: %{},
test: true
)
- {:ok, sync_pid} =
- Polyjuice.Client.API.sync_child_spec(client, self(), filter: %{})
- |> (fn %{start: {module, func, args}} -> apply(module, func, args) end).()
-
- assert_receive({:connected})
+ assert_receive({:polyjuice_client, :sync_connected})
assert_receive(
- {:invite, "!room_id", "@bob:example.org",
- %{
- "m.room.member" => %{
- "@alice:example.org" => %{
- "content" => %{
- "membership" => "invite"
- },
- "type" => "m.room.member",
- "state_key" => "@alice:example.org",
- "event_id" => "$invite_event",
- "room_id" => "!room_id",
- "sender" => "@bob:example.org"
- }
- }
- }},
+ {:polyjuice_client, :invite,
+ {"!room_id", "@bob:example.org",
+ %{
+ "m.room.member" => %{
+ "@alice:example.org" => %{
+ "content" => %{
+ "membership" => "invite"
+ },
+ "type" => "m.room.member",
+ "state_key" => "@alice:example.org",
+ "event_id" => "$invite_event",
+ "room_id" => "!room_id",
+ "sender" => "@bob:example.org"
+ }
+ }
+ }}},
1000
)
- assert_receive({:initial_sync_completed})
+ assert_receive({:polyjuice_client, :initial_sync_completed})
assert_receive(
- {:limited, "!room_id", "p1"},
+ {:polyjuice_client, :limited, {"!room_id", "p1"}},
1000
)
assert_receive(
- {:state, "!room_id",
- %{
- "content" => %{
- "membership" => "join"
- },
- "type" => "m.room.member",
- "state_key" => "@alice:example.org",
- "event_id" => "$join_event",
- "room_id" => "!room_id",
- "sender" => "@alice:example.org"
- }},
+ {:polyjuice_client, :state,
+ {"!room_id",
+ %{
+ "content" => %{
+ "membership" => "join"
+ },
+ "type" => "m.room.member",
+ "state_key" => "@alice:example.org",
+ "event_id" => "$join_event",
+ "room_id" => "!room_id",
+ "sender" => "@alice:example.org"
+ }}},
1000
)
assert_receive(
- {:message, "!room_id",
- %{
- "content" => %{
- "msgtype" => "m.text",
- "body" => "Hello World!"
- },
- "type" => "m.room.message",
- "event_id" => "$message_event",
- "room_id" => "!room_id",
- "sender" => "@alice:example.org"
- }},
+ {:polyjuice_client, :message,
+ {"!room_id",
+ %{
+ "content" => %{
+ "msgtype" => "m.text",
+ "body" => "Hello World!"
+ },
+ "type" => "m.room.message",
+ "event_id" => "$message_event",
+ "room_id" => "!room_id",
+ "sender" => "@alice:example.org"
+ }}},
1000
)
assert_receive(
- {:state, "!room_id",
- %{
- "content" => %{
- "membership" => "leave",
- "reason" => "Goodbye Cruel World!"
- },
- "type" => "m.room.member",
- "state_key" => "@alice:example.org",
- "event_id" => "$leave_event",
- "room_id" => "!room_id",
- "sender" => "@alice:example.org"
- }},
+ {:polyjuice_client, :state,
+ {"!room_id",
+ %{
+ "content" => %{
+ "membership" => "leave",
+ "reason" => "Goodbye Cruel World!"
+ },
+ "type" => "m.room.member",
+ "state_key" => "@alice:example.org",
+ "event_id" => "$leave_event",
+ "room_id" => "!room_id",
+ "sender" => "@alice:example.org"
+ }}},
1000
)
assert_receive(
- {:left, "!room_id"},
+ {:polyjuice_client, :left, {"!room_id"}},
1000
)
- Process.unlink(sync_pid)
- Process.exit(sync_pid, :kill)
-
Polyjuice.Client.stop(client)
:inets.stop(:httpd, httpd_pid)
diff --git a/test/polyjuice/client_test.exs b/test/polyjuice/client_test.exs
index 0c880c1..a0e53ec 100644
--- a/test/polyjuice/client_test.exs
+++ b/test/polyjuice/client_test.exs
@@ -75,7 +75,7 @@ defmodule Polyjuice.ClientTest do
test "transaction_id is unique" do
client = %Polyjuice.Client{
base_url: "http://localhost:8008",
- pid: nil
+ id: nil
}
# the best that we can do is test that two calls to transaction_id return
@@ -84,18 +84,6 @@ defmodule Polyjuice.ClientTest do
Polyjuice.Client.API.transaction_id(client)
end
- test "sync child spec" do
- client = %Polyjuice.Client{
- base_url: "http://localhost:8008",
- pid: nil
- }
-
- %{id: Polyjuice.Client.Sync, restart: :permanent, start: start} =
- Polyjuice.Client.API.sync_child_spec(client, "listener")
-
- assert start == {Polyjuice.Client.Sync, :start_link, [[client, "listener"]]}
- end
-
test "sync" do
with client = %DummyClient{
response: {
@@ -153,10 +141,11 @@ defmodule Polyjuice.ClientTest do
port = :httpd.info(httpd_pid) |> Keyword.fetch!(:port)
client =
- Polyjuice.Client.start(
+ Polyjuice.Client.start_link(
"http://127.0.0.1:#{port}/Elixir.Polyjuice.ClientTest.Httpd/",
access_token: "an_access_token",
user_id: "@alice:example.org",
+ sync: false,
test: true
)
@@ -219,25 +208,36 @@ defmodule Polyjuice.ClientTest do
port = :httpd.info(httpd_pid) |> Keyword.fetch!(:port)
client =
- Polyjuice.Client.start(
+ Polyjuice.Client.start_link(
"http://127.0.0.1:#{port}/Elixir.Polyjuice.ClientTest.Httpd/",
access_token: nil,
+ sync: false,
test: true
)
Polyjuice.Client.log_in_with_password(client, "@alice:example.org", "password")
- assert Agent.get(client.pid, fn %{
- access_token: access_token,
- user_id: user_id,
- device_id: device_id
- } ->
- {access_token, user_id, device_id}
- end) == {"m.id.user_login", "@alice:example.org", "foo"}
+ assert Agent.get(
+ Polyjuice.Client.process_name(client.id, :state),
+ fn %{
+ access_token: access_token,
+ user_id: user_id,
+ device_id: device_id
+ } ->
+ {access_token, user_id, device_id}
+ end
+ ) == {"m.id.user_login", "@alice:example.org", "foo"}
Polyjuice.Client.log_out(client)
- assert Agent.get(client.pid, fn %{access_token: access_token} -> access_token end) == nil
+ assert Agent.get(
+ Polyjuice.Client.process_name(client.id, :state),
+ fn %{
+ access_token: access_token
+ } ->
+ access_token
+ end
+ ) == nil
Polyjuice.Client.log_in_with_password(
client,
@@ -245,13 +245,16 @@ defmodule Polyjuice.ClientTest do
"password"
)
- assert Agent.get(client.pid, fn %{
- access_token: access_token,
- user_id: user_id,
- device_id: device_id
- } ->
- {access_token, user_id, device_id}
- end) == {"m.id.thirdparty_login", "@alice:example.org", "foo"}
+ assert Agent.get(
+ Polyjuice.Client.process_name(client.id, :state),
+ fn %{
+ access_token: access_token,
+ user_id: user_id,
+ device_id: device_id
+ } ->
+ {access_token, user_id, device_id}
+ end
+ ) == {"m.id.thirdparty_login", "@alice:example.org", "foo"}
Polyjuice.Client.log_in_with_password(
client,
@@ -259,13 +262,16 @@ defmodule Polyjuice.ClientTest do
"password"
)
- assert Agent.get(client.pid, fn %{
- access_token: access_token,
- user_id: user_id,
- device_id: device_id
- } ->
- {access_token, user_id, device_id}
- end) == {"m.id.phone_login", "@alice:example.org", "foo"}
+ assert Agent.get(
+ Polyjuice.Client.process_name(client.id, :state),
+ fn %{
+ access_token: access_token,
+ user_id: user_id,
+ device_id: device_id
+ } ->
+ {access_token, user_id, device_id}
+ end
+ ) == {"m.id.phone_login", "@alice:example.org", "foo"}
Polyjuice.Client.log_in_with_password(
client,
@@ -275,13 +281,16 @@ defmodule Polyjuice.ClientTest do
"password"
)
- assert Agent.get(client.pid, fn %{
- access_token: access_token,
- user_id: user_id,
- device_id: device_id
- } ->
- {access_token, user_id, device_id}
- end) == {"ca.uhoreg.foo_login", "@alice:example.org", "foo"}
+ assert Agent.get(
+ Polyjuice.Client.process_name(client.id, :state),
+ fn %{
+ access_token: access_token,
+ user_id: user_id,
+ device_id: device_id
+ } ->
+ {access_token, user_id, device_id}
+ end
+ ) == {"ca.uhoreg.foo_login", "@alice:example.org", "foo"}
Polyjuice.Client.stop(client)