Korbin73

Korbin73

How do you set the headers in a Phoenix.ConnTest unit test?

I’m trying to set the header with an addition value in a phoenix unit (integration) test:

 @tag integration: true
  test "should record the incoming request made to forwarding service" do
    conn_with_api_header = build_conn()
      |> Plug.Conn.put_req_header("x-mashape-key", "some_test_key" )

    conn = post(conn_with_api_header, "/api/cards")
  end

When I run the test I’m getting the following error:
** (ArgumentError) argument error
code: conn = post(conn_with_api_header, “/api/cards”)
stacktrace:
:erlang.iolist_to_binary([{“x-mashape-key”, “some_test_key”}])

Does anyone know how to set or add entries to the header when testing endpoints? I didn’t see anything in the docs that allows this option.

Most Liked

idi527

idi527

:waving_hand:

I don’t see any errors with your posted code … Can you post the full stacktrace? Maybe the error comes from your application code.

Korbin73

Korbin73

Wow, you nailed it without even seeing the code! My test was actually doing the correct thing and I was assuming my test was wrong shakes head. After looking at the rest of the call stack I realize I was looking in the wrong place:

(httpoison) lib/httpoison/base.ex:787: HTTPoison.Base.request/6
(proxy_host) lib/proxy_host_web/controllers/proxy_controller.ex:65: ProxyHostWeb.ProxyController.make_http_call/3
(proxy_host) lib/proxy_host_web/controllers/proxy_controller.ex:101: ProxyHostWeb.ProxyController.respond_by_mode/4
(proxy_host) lib/proxy_host_web/controllers/proxy_controller.ex:123: ProxyHostWeb.ProxyController.index/4
(proxy_host) lib/proxy_host_web/controllers/proxy_controller.ex:1: ProxyHostWeb.ProxyController.action/2
(proxy_host) lib/proxy_host_web/controllers/proxy_controller.ex:1: ProxyHostWeb.ProxyController.phoenix_controller_pipeline/2
(proxy_host) lib/proxy_host_web/endpoint.ex:1: ProxyHostWeb.Endpoint.instrument/4
(phoenix) lib/phoenix/router.ex:275: Phoenix.Router.call/1
(proxy_host) lib/proxy_host_web/endpoint.ex:1: ProxyHostWeb.Endpoint.plug_builder_call/2
(proxy_host) lib/proxy_host_web/endpoint.ex:1: ProxyHostWeb.Endpoint.call/2
(phoenix) lib/phoenix/test/conn_test.ex:235: Phoenix.ConnTest.dispatch/5
test/integration_test.exs:23: (test)

I guess I was looking at it myopically when I saw the argument error.

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Other popular topics Top

New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement