Skip to content

Commit

Permalink
Marketplace: Checkout is prevented without a DeliveryArea
Browse files Browse the repository at this point in the history
- #1983

Prevents `Shoppers` from visiting the `Checkout` screen until a
`DeliveryArea` has been selected.
  • Loading branch information
zspencer committed Dec 4, 2023
1 parent 9036d4e commit 914869c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/furniture/marketplace/cart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def price_total
end

def ready_for_checkout?
delivery.details_filled_in? && cart_products.present? && cart_products.all?(&:valid?)
delivery_area.present? && cart_products.present? && cart_products.all?(&:valid?)
end
end
end
2 changes: 1 addition & 1 deletion app/furniture/marketplace/carts/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</tr>
<tr>
<td class="text-right py-3.5" colspan="8">
<%= render ButtonComponent.new(label: "Checkout", href: cart.location(child: :checkout), scheme: :primary, method: :get) %>
<%= render ButtonComponent.new(label: "Checkout", href: cart.location(child: :checkout), scheme: :primary, method: :get, disabled: !cart.ready_for_checkout?) %>
</td>
</tr>
</tfoot>
12 changes: 12 additions & 0 deletions spec/furniture/marketplace/buying_products_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ def url_options
{host: server_uri.host, port: server_uri.port}
end

context "when there is not a DeliveryArea selected" do
it "Prevents Checkout unless a DeliveryArea is selected" do
create(:marketplace_delivery_area, marketplace: marketplace)

visit(polymorphic_path(marketplace.room.location))

add_product_to_cart(marketplace.products.first)

expect { click_link("Checkout") }.to raise_error(Capybara::ElementNotFound)
end
end

it "Works for Guests" do # rubocop:disable RSpec/ExampleLength
visit(polymorphic_path(marketplace.room.location))

Expand Down

0 comments on commit 914869c

Please sign in to comment.