Skip to content

Commit

Permalink
Merge pull request #100 from kulikulifoods/upsert-order
Browse files Browse the repository at this point in the history
UpdateOrderJob -> UpsertOrderJob
  • Loading branch information
damianlegawiec authored May 20, 2020
2 parents 593b921 + 9bb65c7 commit 7f73e37
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/features/order_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions spec/models/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,23 @@
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

it "schedules mailchimp Shipping Confirmation notification on order shipped" do
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

it "schedules mailchimp Refund Confirmation notification on order refund" do
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
Expand Down

0 comments on commit 7f73e37

Please sign in to comment.