silverdr
While continuing my getting used to Elixir testing approaches venture I encountered a “scratch-my-head” type of issue when upon testing a piece of code that calls render(conn, ...) I began receiving the
** (KeyError) key :phoenix_endpoint not found in: %{phoenix_recycled: true, plug_skip_ [...]
The test module does use MyAppWeb.ConnCase, async: true. The ConnCase is unmodified vanilla Phoenix one, which sets @endpoint and builds conn, just like in other test modules.
I can work the error around with
conn = conn |> put_private(:phoenix_endpoint, MyAppWeb.Endpoint)
but this smells to me. Any hints why do I have to do this? And/or what should I do instead?
An example of test giving this error:
test "clears ip address", %{conn: conn, user: user} do
# GIVEN an inactive user and an IP address of the connection stored in the database
assert IpAddress |> where([ipa], ipa.ip_address == ^conn.remote_ip) |> Repo.aggregate(:count) == 1
# WHEN calling user_login_success/2
conn = Session.user_login_success(conn, user)
# EXPECT the ip address record to be removed from the database
assert IpAddress |> where([ipa], ipa.ip_address == ^conn.remote_ip) |> Repo.aggregate(:count) == 0
end
The offending (triggering error) render() is located in:
defp user_not_activated(conn, user) do
conn
|> put_session(:email, user.email)
|> put_view(MyAppWeb.UserView)
|> render(:not_activated, [conn: conn, activation_resent_at: user.last_activation_sent_at])
|> halt()
end
Setup for this block:
setup %{conn: conn} do
# No idea why the `put_private` is needed. IMHO shouldn't be
# as the @endpoint is set in the ConnCase, but without it
# I get: "** (KeyError) key :phoenix_endpoint not found in: %{phoenix_recycled: true, plug_skip_ [...]"
conn = conn
|> put_format("html")
|> put_private(:phoenix_endpoint, NvoiceWeb.Endpoint)
SecurityFixtures.fixture(conn.remote_ip)
%{user: AccountsFixtures.fixture(:user), conn: conn}
end
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 2 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
silverdr
Yessir! Updated the post. And also dug through more documentation to eventually find this one:
which seems to be much further away from the smelly side, while doing at least as good job of dealing with the error.
LostKobrakai
Can you show the test producing that error?