wolfiton

wolfiton

Phoenix inside out exercise stuck on test

Hi everyone,

I have a problem of understanding how this test should like on chapter 8 My order exercise here https://shankardevy.com/phoenix-inside-out-mpf/#chapter-8

Question

I created my test like so

test "get_order/1" do
    assert %Order{status: "Confirmed"} = Sales.get_order()
end

But I don’t understand how to get the order for the current user without using Repo or conn here?

Expected result:
To get the order history of the current user in this test.

Thanks in advance for any hints or directions.

Update I started to write something like this

test "create_order" do
    @valid_attrs %{
      "order_id" => 1
       "status" => "Confirmed"
    }
  end

Didn’t work because I don’t have a create order func in my schema can someone show me what i am doing wrong?

Thanks, because i really want to understand how to build this test correctly.

Most Liked

al2o3cr

al2o3cr

It’s hard to know for sure without more code, but I’ll take some guesses.

Sales.get_order is a context function - it likely uses your Repo under the hood.

That function can’t take zero args - which order is it getting? For what user? You’ll likely want to pass in the user.

The setup functions in your test file should be setting up things like the current user and orders then passing them into the tests like:

test "get_order/1", %{current_user: current_user} do
  assert %Order{status: "Confirmed"} = Sales.get_order(current_user)
end

I’m also not sure if get_order is the right name; chapter 8 talks about viewing the user’s order history, so the logical thing to return is a list of orders - something like Sales.get_orders(user)

I don’t understand what the intent of this code is, or how exactly it would fail. You’ll get more effective help if you show complete code examples (instead of fragments) and specific error messages (instead of “didn’t work”).

al2o3cr

al2o3cr

Looking at the commit history for that repo, I don’t see any code for this particular exercise - the “My Orders” link doesn’t appear, for instance. There also aren’t any tests for controller actions that need an authenticated user, or for context functions that expect a customer…

My reading of the style suggested in that tutorial suggests you’ll want to add a bunch of things:

  • code in the CRM context to find all orders given a customer, and a particular order given an ID and a customer

  • tests for the new CRM functions. If there were tests for CRM.get_customer_ticket!, I’d recommend that you follow those - but the generated tests were deleted without replacement.

  • a controller that handles showing an index of the user’s orders and individual ones, based on conn.assigns.current_customer. It will look a lot like TicketController.

  • an acceptance test that interacts with those controller actions. Again, there aren’t any examples in that repo of this kind of test. You’ll need to dig into the Hound docs to figure out how to set up the session correctly with customer_id, or simulate going through the login flow by hand.

Where Next?

Popular in Chat/Questions Top

roshan
Hi everyone, I’m looking for a book on Phoenix server hosting / deployment like the following books for Rails, Docker for Rails Develop...
New
armanm
I know zero downtime deployment can mean different things depending on your application and what your users can tolerate so expectations ...
New
xgilarb
Hi there, I’m interested in using Elixir because of the rumors about the reliability of the Phoenix framework, and surprisingly, Elixir’...
New
lc0815
hello from a real frustrated newbe… I’m reading this article Full-Stack React With Phoenix (Chapter 3 | Introduction to Phoenix) by mich...
New
shansiddiqui94
Hello all, I recently did my first app in Phoenix and Liveview, many thanks to all the users who assisted me. I found that the tutorial ...
New
imanuelgittens
Hey all! Just joined the forum and I’m very excited to learn the language. I just finished reading the documentation and I was wondering ...
New
Besto
I've been trying to start learning Elixir for a couple of weeks while I develop a tiny project I have on node.js, but every time I try to...
New
AstonJ
It’s been a while since we asked this - I’m sure others (especially newcomers to the language) will be interested to hear how you’ve all ...
New
marciol
Hey, I have very restricted resources and time so I’m trying to understand the best way to learn Liveview in terms of cost/time. The Pra...
New
yachnytskyi
Hello everyone. I am gonna start with Elixir/Phoenix, thinking to use Stephen Grider as a start point, then elixir school and other sourc...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
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
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement