Skip to content

Commit

Permalink
Dont display Cancel Order when order already paid
Browse files Browse the repository at this point in the history
Is there some nice way of testing that a button with specific text is not shown?
I tested via the number of visible buttons, which is not great.

Overall the problem here is quite deep.
In the views we have a "state machine" which resembles the one in Ordering::Order.
We need it to know which buttons to display.
The problem is similar to HATEOAS and rendering the possible links.
How to do it without exposing aggregate internals?
We can send new params with the state-changing events, but this leads to fatter events - maybe that's ok.

Another problem here is that the test is integration level. This is wrong. Ideally, rendering the html would be part of the read model component.

I don't know how to move the views to read model directories.
I also don't know how to then call ERB rendering directly in the read model code.

Hints welcome!
  • Loading branch information
andrzejkrzywda committed Jan 25, 2023
1 parent d472003 commit ecf30a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rails_application/app/views/orders/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<%= button_to("Pay", pay_order_path(@order.uid), class: "mr-3 ml-3 inline-flex items-center px-4 py-2 border rounded-md shadow-sm text-sm font-medium focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 border-transparent text-white bg-blue-600 hover:bg-blue-700") %>
<% end %>

<% unless @order.state == "Cancelled" %>
<% if (@order.state != "Cancelled" && @order.state != "Paid") %>
<%= button_to("Cancel Order", cancel_order_path(@order.uid), class: "inline-flex items-center px-4 py-2 border rounded-md shadow-sm text-sm font-medium focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-50 border-gray-300 text-gray-700 bg-white hover:bg-gray-50") %>
<% end %>
<% end %>
Expand Down
26 changes: 26 additions & 0 deletions rails_application/test/integration/orders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,32 @@ def test_cancel
assert_select("dd", "Cancelled")
end

def test_confirmed_order_doesnt_show_cancel_button
shopify_id = register_customer("Shopify")

order_id = SecureRandom.uuid
async_remote_id = register_product("Async Remote", 39, 10)

Sidekiq::Job.drain_all

get "/"
get "/orders/new"
post "/orders/#{order_id}/add_item?product_id=#{async_remote_id}"
post "/orders",
params: {
"authenticity_token" => "[FILTERED]",
"order_id" => order_id,
"customer_id" => shopify_id,
"commit" => "Submit order"
}
post "/orders/#{order_id}/pay"
Shipments::MarkOrderSubmitted.drain
follow_redirect!
assert_select("td", text: "Paid")
get "/orders/#{order_id}"
assert_select("button", 2)
end

private

def assert_res_browser_order_history
Expand Down

0 comments on commit ecf30a6

Please sign in to comment.