Discussion
Loading...

#Tag

  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Keila
@keila@fosstodon.org  ·  activity timestamp last week

Here is a neat little trick when you need to test a verification flow in #PhoenixFramework: https://gist.github.com/wmnnd/cb80d4eae79d5d35b8229d6eec188ee5

It's a common pattern to pass a URL generator to a context function. But you can pass a function that captures the token with an Agent instead.

#elixirlang #myelixirstatus

test "verify something from a token", %{conn: conn} do
  {:ok, agent_pid} = Agent.start_link(fn -> nil end)
  capture_token = fn token ->
    Agent.update(agent_pid, fn _ -> token end)
  end

  MyApp.SomeContext.send_verification_email(&capture_token.(&1))
  token = Agent.get(token_agent, & &1)

  assert something(token)
end
test "verify something from a token", %{conn: conn} do {:ok, agent_pid} = Agent.start_link(fn -> nil end) capture_token = fn token -> Agent.update(agent_pid, fn _ -> token end) end MyApp.SomeContext.send_verification_email(&capture_token.(&1)) token = Agent.get(token_agent, & &1) assert something(token) end
test "verify something from a token", %{conn: conn} do {:ok, agent_pid} = Agent.start_link(fn -> nil end) capture_token = fn token -> Agent.update(agent_pid, fn _ -> token end) end MyApp.SomeContext.send_verification_email(&capture_token.(&1)) token = Agent.get(token_agent, & &1) assert something(token) end
  • Copy link
  • Flag this post
  • Block
Log in

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.0 no JS en
Automatic federation enabled
  • Explore
  • About
  • Members
  • Code of Conduct
Home
Login