I have a simple GenServer making an HTTP request
defmodule GamePlay do
use GenServer
alias Wrapper
def start_link(_args) do
GenServer.start_link(__MODULE__, %{}, name: __MODULE__)
end
def init(state) do
{:ok, state, {:continue, :put_mapping}}
end
def handle_continue(:put_mapping, state) do
mapping = %{
"index_patterns" => ["game_play-*"],
}
}
}
config = Application.get_env(:search_flask, :elasticsearch_seeds, [])
if Keyword.get(config, :enabled?, true) do
Wrapper.create_template_mappings("game_play", mapping)
end
{:noreply, state}
end
end
and I am trying to put to test using Req, in Wrapper, I am sending an HTTP request using Req. but it only works once when I delete _build/test folder after that it stops working
defmodule GamePlayTest do
use ExUnit.Case, async: true
alias GamePlay
alias Wrapper
describe "GamePlay" do
setup do
on_exit(fn ->
Req.Test.verify_on_exit!()
end)
:ok
end
test "sends the correct request to Elasticsearch" do
Req.Test.stub(Wrapper, fn conn ->
Req.Test.json(
conn,
%{"acknowledged" => true}
)
end)
assert {:ok, pid} = GamePlay.start_link(%{})
assert %Req.Response{body: %{"acknowledged" => true}, status: 200} =
Req.get!(Application.get_env(:search_flask, :elasticsearch_req_options, []))
end
end
end
the test is simple as well but it only reaches to Wrapper.create_template_mappings
only once after that it just keep failing. Any guidance will be appreciated, I think I need to flush or clean some process but I am not getting to that somehow, that where it should be done. Thank you