summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/polyjuice/client.ex12
-rw-r--r--lib/polyjuice/client/sync.ex11
-rw-r--r--test/polyjuice/client/sync_test.exs7
3 files changed, 18 insertions, 12 deletions
diff --git a/lib/polyjuice/client.ex b/lib/polyjuice/client.ex
index bdf1fde..8ab0e49 100644
--- a/lib/polyjuice/client.ex
+++ b/lib/polyjuice/client.ex
@@ -47,7 +47,8 @@ defmodule Polyjuice.Client do
base_url: String.t(),
access_token: String.t(),
user_id: String.t(),
- storage: Polyjuice.Client.Storage.t()
+ storage: Polyjuice.Client.Storage.t(),
+ test: boolean
}
@enforce_keys [:base_url]
@@ -55,7 +56,8 @@ defmodule Polyjuice.Client do
:base_url,
:access_token,
:user_id,
- :storage
+ :storage,
+ test: false
]
@doc "The r0 client URL prefix"
@@ -114,7 +116,7 @@ defmodule Polyjuice.Client do
end
defimpl Polyjuice.Client.API do
- def call(%{base_url: base_url, access_token: access_token}, endpoint) do
+ def call(%{base_url: base_url, access_token: access_token, test: test}, endpoint) do
%Polyjuice.Client.Endpoint.HttpSpec{
method: method,
headers: headers,
@@ -129,7 +131,9 @@ defmodule Polyjuice.Client do
{:error, :auth_required}
else
case :hackney.request(
- method,
+ # mod_esi doesn't like POST requests to a sub-path, so change POST
+ # to PUT when running tests
+ if(method == :post and test, do: :put, else: method),
url,
if access_token do
[{"Authorization", "Bearer #{access_token}"} | headers]
diff --git a/lib/polyjuice/client/sync.ex b/lib/polyjuice/client/sync.ex
index 47f9555..d56099b 100644
--- a/lib/polyjuice/client/sync.ex
+++ b/lib/polyjuice/client/sync.ex
@@ -40,7 +40,8 @@ defmodule Polyjuice.Client.Sync do
query_params: "",
backoff: nil,
set_filter: nil,
- initial_done: false
+ initial_done: false,
+ test: false
]
@sync_path "_matrix/client/r0/sync"
@@ -53,7 +54,8 @@ defmodule Polyjuice.Client.Sync do
access_token: access_token,
base_url: homeserver_url,
user_id: user_id,
- storage: storage
+ storage: storage,
+ test: test
},
listener,
opts
@@ -108,7 +110,8 @@ defmodule Polyjuice.Client.Sync do
query_params: query_params,
storage: storage,
since: Polyjuice.Client.Storage.get_sync_token(storage),
- set_filter: set_filter
+ set_filter: set_filter,
+ test: test
})
end
@@ -162,7 +165,7 @@ defmodule Polyjuice.Client.Sync do
case :hackney.send_request(
state.conn_ref,
- {:post, path, headers, Jason.encode!(state.set_filter)}
+ {if(state.test, do: :put, else: :post), path, headers, Jason.encode!(state.set_filter)}
) do
{:ok, status_code, _resp_headers, client_ref} ->
case status_code do
diff --git a/test/polyjuice/client/sync_test.exs b/test/polyjuice/client/sync_test.exs
index 8f0f12c..f42e135 100644
--- a/test/polyjuice/client/sync_test.exs
+++ b/test/polyjuice/client/sync_test.exs
@@ -40,8 +40,6 @@ defmodule Polyjuice.Client.SyncTest do
end
defp handle_filter(session_id, _env, _input) do
- # FIXME: can't actually test the filter, because mod_esi doesn't seem to
- # like processing POST requests that also have extra path components
:mod_esi.deliver(
session_id,
'Content-Type: application/json\r\n\r\n{"filter_id":"1"}'
@@ -219,11 +217,12 @@ defmodule Polyjuice.Client.SyncTest do
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
+ storage: storage,
+ test: true
}
{:ok, sync_pid} =
- Polyjuice.Client.API.sync_child_spec(client, self())
+ Polyjuice.Client.API.sync_child_spec(client, self(), filter: %{})
|> (fn %{start: {module, func, args}} -> apply(module, func, args) end).()
assert_receive({:connected})