Skip to content

Commit

Permalink
πŸžπŸ”¨Marketplace: Buying Products with one unarchived DeliveryArea
Browse files Browse the repository at this point in the history
- #2198

When we added [archiving delivery areas], I didn't take into account
that `Marketplace#cart_for_shopper` was checking against all the
delivery areas.

This fixes that and adds a system spec to make sure we can still
checkout after!

[archiving delivery areas]: #2024
  • Loading branch information
zspencer committed Feb 10, 2024
1 parent 83db1ff commit 65b61bc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/furniture/marketplace/carts/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<%= render "marketplace/carts/total", cart: cart %>
</td>
</tr>

<%- if cart.ready_for_checkout? %>
<tr>
<td class="text-right py-3.5" colspan="8">
Expand Down
2 changes: 1 addition & 1 deletion app/furniture/marketplace/marketplace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def square_order_notifications_enabled?
end

def default_delivery_area
(delivery_areas.size == 1) ? delivery_areas.first : nil
(delivery_areas.unarchived.size == 1) ? delivery_areas.unarchived.first : nil
end
end
end
13 changes: 13 additions & 0 deletions spec/furniture/marketplace/buying_products_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ def url_options
end
end

describe "when the `Marketplace` has one active `DeliveryArea`" do
it "allows Checkout" do
archived_delivery_area = create(:marketplace_delivery_area,
marketplace: marketplace, label: "Oakland", price_cents: 10_00)
archived_delivery_area.archive
visit(polymorphic_path(marketplace.room.location))

add_product_to_cart(marketplace.products.first)

expect { click_link("Checkout") }.not_to raise_error
end
end

it "Doesn't offer archived Products for sale" do
archived_product = create(:marketplace_product, :archived, marketplace:)

Expand Down
9 changes: 9 additions & 0 deletions spec/furniture/marketplace/marketplace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@
cart = marketplace.cart_for_shopper(shopper:)
expect(cart.delivery_area).to be_nil
end

context "when only one of them is unarchived" do
before { marketplace.delivery_areas.first.archive }

it "sets the default delivery area to the single unarchived one" do
cart = marketplace.cart_for_shopper(shopper:)
expect(cart.delivery_area).to eq(marketplace.delivery_areas.unarchived.first)
end
end
end
end

Expand Down

0 comments on commit 65b61bc

Please sign in to comment.