30 lines
929 B
Elixir
30 lines
929 B
Elixir
defmodule Towerops.HTTPTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
alias Towerops.HTTP
|
|
alias Towerops.HTTPTest.ExplicitStub
|
|
|
|
test "returns an error when no test stub is configured" do
|
|
assert {:error, :no_test_stub} = HTTP.get(__MODULE__, "https://example.com")
|
|
end
|
|
|
|
test "uses Req.Test stubs in test mode" do
|
|
Req.Test.stub(__MODULE__, fn conn ->
|
|
conn
|
|
|> Plug.Conn.put_resp_content_type("application/json")
|
|
|> Plug.Conn.send_resp(200, Jason.encode!(%{"ok" => true}))
|
|
end)
|
|
|
|
assert {:ok, %Req.Response{status: 200, body: %{"ok" => true}}} =
|
|
HTTP.get(__MODULE__, "https://example.com")
|
|
end
|
|
|
|
test "respects an explicit plug override" do
|
|
Req.Test.stub(ExplicitStub, fn conn ->
|
|
Plug.Conn.send_resp(conn, 204, "")
|
|
end)
|
|
|
|
assert {:ok, %Req.Response{status: 204}} =
|
|
HTTP.get(__MODULE__, "https://example.com", plug: {Req.Test, ExplicitStub})
|
|
end
|
|
end
|