Skip to content

Commit

Permalink
🥗🧹🥔✨ Marketplace: Show DeliveryArea in `Order::EmailReceiptCompon…
Browse files Browse the repository at this point in the history
…ent`

- #1325
- #1324
- #1326

I didn't use the `marketplace_order, :full` factory outside of the
`Order::PlacedMailerPreview` and `Order::ReceivedMailerPreview`; and
apparently had flubbed the implementation; so that was not working...

So I fixed it and used it in the `Order::EmailReceiptComponent` spec to
test the `Order#delivery_area`

I also noticed we didn't wire in associations between the
`Marketplace::DeliveryArea` into the `Marketplace::Cart` and
`Marketplace::Order` so I added some specs for those.
  • Loading branch information
zspencer committed Apr 9, 2023
1 parent 7b8b5f7 commit 48b23ea
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/furniture/marketplace/delivery_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class DeliveryArea < Record
location(parent: :marketplace)

belongs_to :marketplace, inverse_of: :delivery_areas
has_many :orders, inverse_of: :delivery_area
has_many :deliveries, inverse_of: :delivery_area

monetize :price_cents
end
Expand Down
2 changes: 2 additions & 0 deletions app/furniture/marketplace/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Order < Record
belongs_to :marketplace, inverse_of: :orders
delegate :space, :room, to: :marketplace

belongs_to :delivery_area, inverse_of: :orders, optional: true

belongs_to :shopper, inverse_of: :orders

has_many :ordered_products, inverse_of: :order, foreign_key: :cart_id, dependent: :destroy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
<td class="text-right">Delivery Schedule:</td>
<td><%= render(order.delivery_window) %></td>
</tr>
<%- if order.delivery_area.present? %>
<tr>
<td class="text-right">Delivering In:</td>
<td><%= order.delivery_area.label %></td>
</tr>
<%- end %>
<tr>
<td class="text-right">Buyer Email:</td>
<td colspan="2"><%= order.contact_email %></td>
Expand Down
6 changes: 3 additions & 3 deletions spec/factories/furniture/marketplace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@

trait :full do
with_taxed_products
with_delivery_areas

transient do
product_count { (1..5).to_a.sample }
end

marketplace { association(:marketplace, :with_tax_rates, :with_delivery_fees, :with_notify_emails) }
marketplace { association(:marketplace, :with_tax_rates, :with_delivery_areas, :with_delivery_fees, :with_notify_emails) }

delivery_window { Marketplace::Delivery::Window.new(1.hour.from_now) }
delivery_window { 1.hour.from_now }
delivery_area { marketplace.delivery_areas.sample }
placed_at { 5.minutes.ago }
delivery_address { Faker::Address.full_address }
contact_email { Faker::Internet.safe_email }
Expand Down
7 changes: 7 additions & 0 deletions spec/furniture/marketplace/delivery_area_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "rails_helper"

RSpec.describe Marketplace::DeliveryArea, type: :model do
it { is_expected.to belong_to(:marketplace).inverse_of(:delivery_areas) }
it { is_expected.to have_many(:orders).inverse_of(:delivery_area) }
it { is_expected.to have_many(:deliveries).inverse_of(:delivery_area) }
end
1 change: 1 addition & 0 deletions spec/furniture/marketplace/delivery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

it { is_expected.to belong_to(:marketplace) }
it { is_expected.to belong_to(:shopper) }
it { is_expected.to belong_to(:delivery_area) }

describe "#delivery_window" do
subject(:delivery_window) { delivery.delivery_window }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
subject(:content) { render_inline(component) }

let(:component) { described_class.new(order) }
let(:order) { build(:marketplace_order, :full) }

context "when the order has a particular time to be delivered" do
let(:order) { build(:marketplace_order, delivery_window: 3.hours.from_now) }
Expand All @@ -16,4 +17,6 @@

it { is_expected.to have_content("3pm on Sunday") }
end

it { is_expected.to have_content(/Delivering In:\s+ #{order.delivery_area.label}/) }
end
1 change: 1 addition & 0 deletions spec/furniture/marketplace/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
it { is_expected.to belong_to(:marketplace).class_name("Marketplace::Marketplace").inverse_of(:orders) }

it { is_expected.to belong_to(:shopper).inverse_of(:orders) }
it { is_expected.to belong_to(:delivery_area).inverse_of(:orders).optional }

describe "#price_total" do
subject(:price_total) { order.price_total }
Expand Down

0 comments on commit 48b23ea

Please sign in to comment.