Skip to content

Commit

Permalink
Display "cancel" button only for submitted orders
Browse files Browse the repository at this point in the history
We have a duplication of state machine between the Ordering
aggregate and this view file (which is more error prone)
  • Loading branch information
andrzejkrzywda committed Nov 28, 2023
1 parent cf03a5c commit 961da0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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 %>

<% if (@order.state != "Cancelled" && @order.state != "Paid") %>
<% if (@order.state == "Submitted") %>
<%= 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
16 changes: 15 additions & 1 deletion rails_application/test/integration/orders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,33 @@ def test_confirmed_order_doesnt_show_cancel_button
get "/"
get "/orders/new"
post "/orders/#{order_id}/add_item?product_id=#{async_remote_id}"
Sidekiq::Job.drain_all

get "/orders/#{order_id}"

assert_select("button", text: "Cancel Order", count: 0)

post "/orders",
params: {
"authenticity_token" => "[FILTERED]",
"order_id" => order_id,
"customer_id" => shopify_id,
"commit" => "Submit order"
}
Sidekiq::Job.drain_all

get "/orders/#{order_id}"
assert_select("button", text: "History")
#assert_select("button", text: "Cancel Order", count: 1)


post "/orders/#{order_id}/pay"
Shipments::MarkOrderSubmitted.drain
follow_redirect!
assert_select("td", text: "Paid")
get "/orders/#{order_id}"
assert_select("button", 2)
assert_select("button", text: "History")
assert_select("button", text: "Cancel Order", count: 0)
end

def test_order_value_doesnt_change_after_changing_price
Expand Down

0 comments on commit 961da0c

Please sign in to comment.