From 1911c71317706727426f864ece7b4bc9135ac62f Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Sat, 8 Aug 2020 09:39:54 -0400 Subject: add test mode which changes post requests to put, so that mod_esi will accept it --- lib/polyjuice/client.ex | 12 ++++++++---- lib/polyjuice/client/sync.ex | 11 +++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3