From 9bb65c72c2636c4a85d72ebf61fb8828d7d7536f Mon Sep 17 00:00:00 2001 From: Jordan Moncharmont Date: Tue, 19 May 2020 16:02:51 -0700 Subject: [PATCH] UpdateOrderJob -> UpsertOrderJob I've noticed a large number of my update order jobs failing to complete because the order did not previously exist in mailchimp. While I would love to debug this further (i.e. better understand *why* these orders weren't there in the firssts place), a simple fix would be to use `#upsert` instead of `#update` to get the orders into mailchimp. --- .../{update_order_job.rb => upsert_order_job.rb} | 4 ++-- .../spree_mailchimp_ecommerce/spree/order_decorator.rb | 2 +- spec/features/order_notification_spec.rb | 8 ++++---- spec/models/order_spec.rb | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) rename app/jobs/spree_mailchimp_ecommerce/{update_order_job.rb => upsert_order_job.rb} (55%) diff --git a/app/jobs/spree_mailchimp_ecommerce/update_order_job.rb b/app/jobs/spree_mailchimp_ecommerce/upsert_order_job.rb similarity index 55% rename from app/jobs/spree_mailchimp_ecommerce/update_order_job.rb rename to app/jobs/spree_mailchimp_ecommerce/upsert_order_job.rb index 2b76dc6..61b9287 100644 --- a/app/jobs/spree_mailchimp_ecommerce/update_order_job.rb +++ b/app/jobs/spree_mailchimp_ecommerce/upsert_order_job.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true module SpreeMailchimpEcommerce - class UpdateOrderJob < ApplicationJob + class UpsertOrderJob < ApplicationJob def perform(mailchimp_order) - gibbon_store.orders(mailchimp_order["id"]).update(body: mailchimp_order) + gibbon_store.orders(mailchimp_order["id"]).upsert(body: mailchimp_order) end end end diff --git a/app/models/spree_mailchimp_ecommerce/spree/order_decorator.rb b/app/models/spree_mailchimp_ecommerce/spree/order_decorator.rb index 5cd1713..564a5c8 100644 --- a/app/models/spree_mailchimp_ecommerce/spree/order_decorator.rb +++ b/app/models/spree_mailchimp_ecommerce/spree/order_decorator.rb @@ -64,7 +64,7 @@ def create_mailchimp_order end def update_mailchimp_order - ::SpreeMailchimpEcommerce::UpdateOrderJob.perform_later(mailchimp_order) + ::SpreeMailchimpEcommerce::UpsertOrderJob.perform_later(mailchimp_order) end def new_order_notification diff --git a/spec/features/order_notification_spec.rb b/spec/features/order_notification_spec.rb index e7e2493..699496a 100644 --- a/spec/features/order_notification_spec.rb +++ b/spec/features/order_notification_spec.rb @@ -15,7 +15,7 @@ click_on "Cancel" page.driver.browser.switch_to.alert.accept expect(current_path).to eq("/admin/orders/#{order.number}/edit") - expect(SpreeMailchimpEcommerce::UpdateOrderJob).to have_been_enqueued.exactly(:once) + expect(SpreeMailchimpEcommerce::UpsertOrderJob).to have_been_enqueued.exactly(:once) end scenario "Ship order" do @@ -26,7 +26,7 @@ click_on "Ship" sleep(3) expect(current_path).to eq("/admin/orders/#{order.number}/edit") - expect(SpreeMailchimpEcommerce::UpdateOrderJob).to have_been_enqueued.exactly(:once) + expect(SpreeMailchimpEcommerce::UpsertOrderJob).to have_been_enqueued.exactly(:once) end scenario "Refund by reimbursement" do @@ -42,7 +42,7 @@ expect(current_path).to eq("/admin/orders/#{order.number}/customer_returns/1/edit") find(".action-edit").click click_on "Reimburse" - expect(SpreeMailchimpEcommerce::UpdateOrderJob).to have_been_enqueued.exactly(:once) + expect(SpreeMailchimpEcommerce::UpsertOrderJob).to have_been_enqueued.exactly(:once) end scenario "Refund payment" do @@ -58,6 +58,6 @@ expect(current_path).to eq("/admin/orders/#{order.number}/payments/#{payment.number}/refunds/new") select refund_reason.name.to_s, from: "refund_refund_reason_id" click_on "Refund" - expect(SpreeMailchimpEcommerce::UpdateOrderJob).to have_been_enqueued.exactly(:once) + expect(SpreeMailchimpEcommerce::UpsertOrderJob).to have_been_enqueued.exactly(:once) end end diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index b0c3365..3f92db4 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -76,7 +76,7 @@ order = create(:completed_order_with_totals) order.cancel - expect(SpreeMailchimpEcommerce::UpdateOrderJob).to have_been_enqueued.with(order.mailchimp_order) + expect(SpreeMailchimpEcommerce::UpsertOrderJob).to have_been_enqueued.with(order.mailchimp_order) expect(order.mailchimp_order["financial_status"]).to eq("cancelled") end @@ -84,7 +84,7 @@ order = create(:order_ready_to_ship) order.shipments.first.ship! - expect(SpreeMailchimpEcommerce::UpdateOrderJob).to have_been_enqueued.with(order.mailchimp_order) + expect(SpreeMailchimpEcommerce::UpsertOrderJob).to have_been_enqueued.with(order.mailchimp_order) expect(order.mailchimp_order["fulfillment_status"]).to eq("shipped") end @@ -92,7 +92,7 @@ order = create(:shipped_order) create(:refund, payment: order.payments.first) - expect(SpreeMailchimpEcommerce::UpdateOrderJob).to have_been_enqueued.with(order.mailchimp_order) + expect(SpreeMailchimpEcommerce::UpsertOrderJob).to have_been_enqueued.with(order.mailchimp_order) expect(order.mailchimp_order["financial_status"]).to eq("refunded") end end