Skip to content

Commit

Permalink
Fix touviere with no extra basket size extra options
Browse files Browse the repository at this point in the history
Default to mini (découverte) size.
  • Loading branch information
thibaudgg committed Sep 27, 2024
1 parent 39e6f82 commit dfdb80f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
4 changes: 3 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ class App < Sinatra::Base

begin
member_params = Webhook.handle!(payload)
rescue Webhook::UnkownStoreError, Webhook::IgnoredStatusError => e
logger.info "#{e.class} - #{e.message}"
rescue Webhook::MemberCreationError => e
logger.info payload
logger.info member_params
rescue Webhook::Error => e
logger.info "#{e.class} - #{e.message}"
end

Expand Down
1 change: 1 addition & 0 deletions config/mapping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ touviere:
store_id: 34
api_endpoint: https://admin.touviere.ch/api/v1/members
basket_sizes:
34120: 2 # Panier mini (découverte)
34834: 1 # Panier Couple
34835: 3 # Panier Famille
basket_complements:
Expand Down
7 changes: 3 additions & 4 deletions lib/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ def basket_complements
end

def mapping_id_for(type)
mapping.last[type]&.each { |product_id, id|
return id if product_id.in?(product_ids)
}
nil
mapping.last[type]&.map { |product_id, id|
id if product_id.in?(product_ids)
}.compact.last
end

def mapping_ids_for(type)
Expand Down
2 changes: 1 addition & 1 deletion test/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_valid_webhook_request_touviere
zip: "1205",
country_code: "CH",
note: "Commande locali-ge.ch #35715",
waiting_basket_size_id: 1,
waiting_basket_size_id: 2,
waiting_depot_id: 3,
members_basket_complements_attributes: [
{ basket_complement_id: 2, quantity: 1 },
Expand Down
5 changes: 0 additions & 5 deletions test/fixtures/order_completed_touviere.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@
"value": "34131",
"field_type": "drop_down"
},
"34833": {
"field_id": 34833,
"value": "34834",
"field_type": "drop_down"
},
"34134": {
"field_id": 34134,
"value": [
Expand Down

0 comments on commit dfdb80f

Please sign in to comment.