Skip to content

Commit

Permalink
SharedDataPreview delivery_cycle improvement
Browse files Browse the repository at this point in the history
Use greatest delivery_cycle instead of a mock.
  • Loading branch information
thibaudgg committed Jan 27, 2025
1 parent 8453eb6 commit 827a5ee
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 40 deletions.
8 changes: 2 additions & 6 deletions app/mailer_previews/concerns/shared_data_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def ended_on
end

def deliveries
Delivery.between(started_on..ended_on)
@deliveries ||= delivery_cycle.deliveries(fiscal_year)
end

def basket
Expand All @@ -76,11 +76,7 @@ def depot
end

def delivery_cycle
wday = deliveries.first.date.wday
OpenStruct.new(
id: 1,
public_name: I18n.t("date.day_names")[wday].titleize.pluralize,
absences_included_annually: 0)
@delivery_cycle ||= DeliveryCycle.greatest
end

def memberships_basket_complements
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/api/v1/configurations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ def request(api_token: nil)
assert_includes response.content_type, "application/json"
assert_equal({
"basket_sizes" => [
{ "id" => basket_sizes(:small).id, "visible" => true, "names" => { "en" => "Small basket" } },
{ "id" => basket_sizes(:medium).id, "visible" => true, "names" => { "en" => "Medium basket" } },
{ "id" => small_id, "visible" => true, "names" => { "en" => "Small basket" } },
{ "id" => medium_id, "visible" => true, "names" => { "en" => "Medium basket" } },
{ "id" => basket_sizes(:large).id, "visible" => true, "names" => { "en" => "Large basket" } }
],
"depots" => [
{ "id" => depots(:bakery).id, "visible" => true, "names" => { "en" => "Bakery" } },
{ "id" => depots(:farm).id, "visible" => true, "names" => { "en" => "Our farm" } },
{ "id" => depots(:home).id, "visible" => true, "names" => { "en" => "Home" } }
{ "id" => home_id, "visible" => true, "names" => { "en" => "Home" } }
],
"basket_content_products" => [
{ "id" => basket_content_products(:carrots).id, "names" => { "en" => "Carrots" } },
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/api/v1/members_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def request(params: {}, api_token: nil)
country_code: "CH",
emails: "[email protected]",
phones: "+41 12 345 67 89",
waiting_basket_size_id: basket_sizes(:small).id,
waiting_basket_size_id: small_id,
waiting_depot_id: depots(:bakery).id,
members_basket_complements_attributes: [
{ basket_complement_id: basket_complements(:bread).id, quantity: 1 },
{ basket_complement_id: basket_complements(:eggs).id, quantity: 2 }
{ basket_complement_id: bread_id, quantity: 1 },
{ basket_complement_id: eggs_id, quantity: 2 }
]
}

Expand Down
2 changes: 1 addition & 1 deletion test/models/basket_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def build_basket(attrs)
test "calculate_price_extra with dynamic pricing based on basket_size" do
org(features: [ :basket_price_extra ])
org(basket_price_extra_dynamic_pricing: <<-LIQUID)
{% if basket_size_id == #{basket_sizes(:small).id} %}
{% if basket_size_id == #{small_id} %}
{{ 15 | minus: 10 | divided_by: 3.0 }}
{% else %}
2.5
Expand Down
54 changes: 27 additions & 27 deletions test/models/liquid/data_preview_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class Liquid::DataPreviewTest < ActiveSupport::TestCase
"date" => "1 April 2024"
},
"depot" => {
"id" => depots(:home).id,
"id" => home_id,
"member_note" => nil,
"name" => "Home"
},
"description" => "Small basket",
"quantity" => 1,
"size" => {
"id" => basket_sizes(:small).id,
"id" => small_id,
"name" => "Small basket"
}
},
Expand All @@ -48,33 +48,33 @@ class Liquid::DataPreviewTest < ActiveSupport::TestCase
"basket_complements" => [
{
"description" => "Eggs",
"id" => basket_complements(:eggs).id,
"id" => eggs_id,
"name" => "Eggs",
"quantity" => 1
},
{
"description" => "Bread",
"id" => basket_complements(:bread).id,
"id" => bread_id,
"name" => "Bread",
"quantity" => 1
}
],
"basket_complements_description" => "Bread and Eggs",
"basket_quantity" => 1,
"basket_size" => {
"id" => basket_sizes(:medium).id,
"id" => medium_id,
"name" => "Medium basket"
},
"delivery_cycle" => {
"id" => all_id,
"name" => "All",
"absences_included_annually" => 0
},
"depot" => {
"id" => depots(:home).id,
"id" => home_id,
"member_note" => nil,
"name" => "Home"
},
"delivery_cycle" => {
"id" => 1,
"name" => "Mondays",
"absences_included_annually" => 0
},
"end_date" => "31 December 2024",
"first_delivery" => {
"date" => "1 April 2024"
Expand Down Expand Up @@ -121,16 +121,16 @@ class Liquid::DataPreviewTest < ActiveSupport::TestCase
"url" => "https://www.acme.test"
},
"waiting_basket_size" => {
"id" => basket_sizes(:medium).id,
"id" => medium_id,
"name" => "Medium basket"
},
"waiting_basket_size_id" => basket_sizes(:medium).id,
"waiting_basket_size_id" => medium_id,
"waiting_delivery_cycle" => {
"absences_included_annually" => 0,
"id" => 1,
"name" => "Mondays"
"id" => all_id,
"name" => "All"
},
"waiting_delivery_cycle_id" => 1,
"waiting_delivery_cycle_id" => all_id,
"waiting_depot" => {
"id" => depots(:farm).id,
"member_note" => nil,
Expand All @@ -155,14 +155,14 @@ class Liquid::DataPreviewTest < ActiveSupport::TestCase
"date" => "1 April 2024"
},
"depot" => {
"id" => depots(:home).id,
"id" => home_id,
"member_note" => nil,
"name" => "Home"
},
"description" => "Small basket",
"quantity" => 1,
"size" => {
"id" => basket_sizes(:small).id,
"id" => small_id,
"name" => "Small basket"
}
},
Expand All @@ -181,33 +181,33 @@ class Liquid::DataPreviewTest < ActiveSupport::TestCase
"basket_complements" => [
{
"description" => "Eggs",
"id" => basket_complements(:eggs).id,
"id" => eggs_id,
"name" => "Eggs",
"quantity" => 1
},
{
"description" => "Bread",
"id" => basket_complements(:bread).id,
"id" => bread_id,
"name" => "Bread",
"quantity" => 1
}
],
"basket_complements_description" => "Bread and Eggs",
"basket_quantity" => 1,
"basket_size" => {
"id" => basket_sizes(:medium).id,
"id" => medium_id,
"name" => "Medium basket"
},
"delivery_cycle" => {
"id" => all_id,
"name" => "All",
"absences_included_annually" => 0
},
"depot" => {
"id" => depots(:home).id,
"id" => home_id,
"member_note" => nil,
"name" => "Home"
},
"delivery_cycle" => {
"id" => 1,
"name" => "Mondays",
"absences_included_annually" => 0
},
"end_date" => "31 December 2024",
"first_delivery" => {
"date" => "1 April 2024"
Expand Down

0 comments on commit 827a5ee

Please sign in to comment.