From dd587bb1746247974e77b35cc6c81789e22634a5 Mon Sep 17 00:00:00 2001 From: Noah Silvera Date: Mon, 19 Jul 2021 15:49:31 -0700 Subject: Add an event that is fired when any shipment ships Transactions need to be reported to TaxJar when any of the shipment ships (some stores have partial shipping). To accomodate this, we add a new event which is fired whenever any shipment on an order ships. Co-authored-by: Nick Van Doorn --- .../spree/shipment/fire_shipment_shipped_event.rb | 18 ++++++++++++++++++ spec/models/spree/shipment_spec.rb | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 app/decorators/super_good/solidus_taxjar/spree/shipment/fire_shipment_shipped_event.rb create mode 100644 spec/models/spree/shipment_spec.rb diff --git a/app/decorators/super_good/solidus_taxjar/spree/shipment/fire_shipment_shipped_event.rb b/app/decorators/super_good/solidus_taxjar/spree/shipment/fire_shipment_shipped_event.rb new file mode 100644 index 0000000..a109745 --- /dev/null +++ b/app/decorators/super_good/solidus_taxjar/spree/shipment/fire_shipment_shipped_event.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module SuperGood + module SolidusTaxjar + module Spree + module Shipment + module FireShipmentShippedEvent + def after_ship + ::Spree::Event.fire 'shipment_shipped', shipment: self + super + end + + ::Spree::Shipment.prepend(self) + end + end + end + end +end diff --git a/spec/models/spree/shipment_spec.rb b/spec/models/spree/shipment_spec.rb new file mode 100644 index 0000000..27f213b --- /dev/null +++ b/spec/models/spree/shipment_spec.rb @@ -0,0 +1,16 @@ +RSpec.describe Spree::Shipment do + describe '#update' do + subject { shipment.ship } + + let(:shipment) { create(:shipment, state: 'ready', order: order) } + let(:order) { create :order_with_line_items } + + it 'fires the shipment_shipped event exactly once' do + stub_const('Spree::Event', class_spy(Spree::Event)) + + expect(Spree::Event).to receive(:fire).with('shipment_shipped', shipment: shipment).once + + subject + end + end +end -- cgit v1.2.3 From e38197d126137ae5f41fe22018e2fcbd19322037 Mon Sep 17 00:00:00 2001 From: Noah Silvera Date: Mon, 19 Jul 2021 15:54:29 -0700 Subject: Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b46ff0..db68775 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## master + +- [#88](https://github.com/SuperGoodSoft/solidus_taxjar/pull/88) Fire `shipment_shipped` event when any shipment on an order ships. + ## v0.18.2 - [#71](https://github.com/SuperGoodSoft/solidus_taxjar/pull/69) Unlock ExecJS version. This reverts the temporary fix introduced in #69 -- cgit v1.2.3