marcs

marcs

Programming Phoenix LiveView B11.0: Tests fail after adding login (Page 70)

Hi,
i followed the examples and generated the Catalog live ressource as described on page 67, added the /product routes in the corresponding /-Scope with the :require_authenticated_user plug. Now mix test fails as expected on page 69. Now, when i add the :register_and_log_in_user plug to the Index and Show test blocks, the tests should not fail anymore.
In my case, i get another 6 failures on running mix test:

  1) test Show displays product (PentoWeb.ProductLiveTest)
     test/pento_web/live/product_live_test.exs:88
     ** (UndefinedFunctionError) function PentoWeb.PentoWeb.ProductLive.Show.__live__/0 is undefined (module PentoWeb.PentoWeb.ProductLive.Show is not available)
     code: {:ok, _show_live, html} = live(conn, ~p"/products/#{product}")
     stacktrace:
       PentoWeb.PentoWeb.ProductLive.Show.__live__()
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/static.ex:299: Phoenix.LiveView.Static.load_live!/2
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/static.ex:128: Phoenix.LiveView.Static.do_render/4
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
       (phoenix 1.7.18) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
       (pento 0.1.0) lib/pento_web/endpoint.ex:1: PentoWeb.Endpoint.plug_builder_call/2
       (pento 0.1.0) lib/pento_web/endpoint.ex:1: PentoWeb.Endpoint.call/2
       (phoenix 1.7.18) lib/phoenix/test/conn_test.ex:225: Phoenix.ConnTest.dispatch/5
       test/pento_web/live/product_live_test.exs:89: (test)



  2) test Index lists all products (PentoWeb.ProductLiveTest)
     test/pento_web/live/product_live_test.exs:24
     ** (UndefinedFunctionError) function PentoWeb.PentoWeb.ProductLive.Index.__live__/0 is undefined (module PentoWeb.PentoWeb.ProductLive.Index is not available)
     code: {:ok, _index_live, html} = live(conn, ~p"/products")
     stacktrace:
       PentoWeb.PentoWeb.ProductLive.Index.__live__()
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/static.ex:299: Phoenix.LiveView.Static.load_live!/2
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/static.ex:128: Phoenix.LiveView.Static.do_render/4
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
       (phoenix 1.7.18) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
       (pento 0.1.0) lib/pento_web/endpoint.ex:1: PentoWeb.Endpoint.plug_builder_call/2
       (pento 0.1.0) lib/pento_web/endpoint.ex:1: PentoWeb.Endpoint.call/2
       (phoenix 1.7.18) lib/phoenix/test/conn_test.ex:225: Phoenix.ConnTest.dispatch/5
       test/pento_web/live/product_live_test.exs:25: (test)



  3) test Show updates product within modal (PentoWeb.ProductLiveTest)
     test/pento_web/live/product_live_test.exs:95
     ** (UndefinedFunctionError) function PentoWeb.PentoWeb.ProductLive.Show.__live__/0 is undefined (module PentoWeb.PentoWeb.ProductLive.Show is not available)
     code: {:ok, show_live, _html} = live(conn, ~p"/products/#{product}")
     stacktrace:
       PentoWeb.PentoWeb.ProductLive.Show.__live__()
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/static.ex:299: Phoenix.LiveView.Static.load_live!/2
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/static.ex:128: Phoenix.LiveView.Static.do_render/4
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
       (phoenix 1.7.18) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
       (pento 0.1.0) lib/pento_web/endpoint.ex:1: PentoWeb.Endpoint.plug_builder_call/2
       (pento 0.1.0) lib/pento_web/endpoint.ex:1: PentoWeb.Endpoint.call/2
       (phoenix 1.7.18) lib/phoenix/test/conn_test.ex:225: Phoenix.ConnTest.dispatch/5
       test/pento_web/live/product_live_test.exs:96: (test)



  4) test Index saves new product (PentoWeb.ProductLiveTest)
     test/pento_web/live/product_live_test.exs:31
     ** (UndefinedFunctionError) function PentoWeb.PentoWeb.ProductLive.Index.__live__/0 is undefined (module PentoWeb.PentoWeb.ProductLive.Index is not available)
     code: {:ok, index_live, _html} = live(conn, ~p"/products")
     stacktrace:
       PentoWeb.PentoWeb.ProductLive.Index.__live__()
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/static.ex:299: Phoenix.LiveView.Static.load_live!/2
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/static.ex:128: Phoenix.LiveView.Static.do_render/4
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
       (phoenix 1.7.18) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
       (pento 0.1.0) lib/pento_web/endpoint.ex:1: PentoWeb.Endpoint.plug_builder_call/2
       (pento 0.1.0) lib/pento_web/endpoint.ex:1: PentoWeb.Endpoint.call/2
       (phoenix 1.7.18) lib/phoenix/test/conn_test.ex:225: Phoenix.ConnTest.dispatch/5
       test/pento_web/live/product_live_test.exs:32: (test)



  5) test Index deletes product in listing (PentoWeb.ProductLiveTest)
     test/pento_web/live/product_live_test.exs:77
     ** (UndefinedFunctionError) function PentoWeb.PentoWeb.ProductLive.Index.__live__/0 is undefined (module PentoWeb.PentoWeb.ProductLive.Index is not available)
     code: {:ok, index_live, _html} = live(conn, ~p"/products")
     stacktrace:
       PentoWeb.PentoWeb.ProductLive.Index.__live__()
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/static.ex:299: Phoenix.LiveView.Static.load_live!/2
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/static.ex:128: Phoenix.LiveView.Static.do_render/4
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
       (phoenix 1.7.18) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
       (pento 0.1.0) lib/pento_web/endpoint.ex:1: PentoWeb.Endpoint.plug_builder_call/2
       (pento 0.1.0) lib/pento_web/endpoint.ex:1: PentoWeb.Endpoint.call/2
       (phoenix 1.7.18) lib/phoenix/test/conn_test.ex:225: Phoenix.ConnTest.dispatch/5
       test/pento_web/live/product_live_test.exs:78: (test)



  6) test Index updates product in listing (PentoWeb.ProductLiveTest)
     test/pento_web/live/product_live_test.exs:54
     ** (UndefinedFunctionError) function PentoWeb.PentoWeb.ProductLive.Index.__live__/0 is undefined (module PentoWeb.PentoWeb.ProductLive.Index is not available)
     code: {:ok, index_live, _html} = live(conn, ~p"/products")
     stacktrace:
       PentoWeb.PentoWeb.ProductLive.Index.__live__()
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/static.ex:299: Phoenix.LiveView.Static.load_live!/2
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/static.ex:128: Phoenix.LiveView.Static.do_render/4
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
       (phoenix 1.7.18) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
       (pento 0.1.0) lib/pento_web/endpoint.ex:1: PentoWeb.Endpoint.plug_builder_call/2
       (pento 0.1.0) lib/pento_web/endpoint.ex:1: PentoWeb.Endpoint.call/2
       (phoenix 1.7.18) lib/phoenix/test/conn_test.ex:225: Phoenix.ConnTest.dispatch/5
       test/pento_web/live/product_live_test.exs:55: (test)

...........................................................
Finished in 0.5 seconds (0.3s async, 0.2s sync)
142 tests, 6 failures

My guess is the PentoWeb.PentoWeb.ProductLive.Index part has one “PentoWeb” too much. But i cannot see where this should be defined.

Any ideas how to trace this down and fix it?

Marked As Solved

marcs

marcs

I already found the issue. There was an unnecessary Alias added to my routers.ex
Don‘t know if it was the generator or more likely the language server in conjunction with neovim. But now, after removing it, everything works as expected

Where Next?

Popular Pragmatic Bookshelf topics Top

johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
New
brianokken
Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
New
simonpeter
When I try the command to create a pair of migration files I get an error. user=> (create-migration "guestbook") Execution error (Ill...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
New
jgchristopher
“The ProductLive.Index template calls a helper function, live_component/3, that in turn calls on the modal component. ” Excerpt From: Br...
New
hazardco
On page 78 the following code appears: <%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New
taguniversalmachine
It seems the second code snippet is missing the code to set the current_user: current_user: Accounts.get_user_by_session_token(session["...
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
mert
AWDWR 7, page 152, page 153: Hello everyone, I’m a little bit lost on the hotwire part. I didn’t fully understand it. On page 152 @rub...
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
New
PragmaticBookshelf
Author Spotlight Mike Riley @mriley This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
New
First poster: AstonJ
Jan | Rethink the Computer. Jan turns your computer into an AI machine by running LLMs locally on your computer. It’s a privacy-focus, l...
New
AnfaengerAlex
Hello, I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New
RobertRichards
Hair Salon Games for Girls Fun Girls Hair Saloon game is mainly developed for kids. This game allows users to select virtual avatars to ...
New

Sub Categories: