Skip to content

Commit

Permalink
[TEC-4931] Adding some specs for OrderUpdater#upsert_data method
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiandl committed Mar 31, 2021
1 parent de57edb commit 5cbf96c
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions spec/services/flowcommerce_spree/order_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
RSpec.describe FlowcommerceSpree::OrderUpdater do
subject { FlowcommerceSpree::OrderUpdater }

let(:zone) { create(:germany_zone, :with_flow_data) }
let(:order) { create(:order_with_line_items, :with_flow_data) }
context 'when no order is passed' do
it 'raises exception' do
expect { subject.new }.to raise_error(ArgumentError, 'missing keyword: order')
end
end

context 'when order is not present' do
it 'raises exception' do
Expand All @@ -21,4 +24,50 @@
expect { subject.new(order: order) }.to raise_error(ArgumentError, 'Experience not defined or not active')
end
end

context 'when the order has a flow experience defined' do
let(:zone) { create(:germany_zone, :with_flow_data) }
let(:order) { create(:order_with_line_items, :with_flow_data, zone: zone) }
let(:flowcommerce_client) { FlowcommerceSpree.client }

before { allow(FlowcommerceSpree).to receive(:client).and_return(flowcommerce_client) }

it 'initalizes successfully' do
instance = subject.new(order: order)

expect(instance.instance_variable_get(:@experience)).to eql(order.flow_io_experience_key)
expect(instance.instance_variable_get(:@order)).to eql(order)
expect(instance.instance_variable_get(:@client)).to eql(flowcommerce_client)
end

describe '#upsert_data' do
context 'if order status is `complete`' do
it 'does nothing' do
order.state = 'complete'
expect(order).not_to(receive(:create_proposed_shipments))
expect(order).not_to(receive(:charge_taxes))

subject.new(order: order).upsert_data
expect(order.complete?).to(be_truthy)
end
end

context 'if order status is not `complete`' do
before do
allow_any_instance_of(Io::Flow::V0::Clients::Orders)
.to(receive(:get_by_number)
.and_return({ submitted_at: Time.current, customer: { email: 'test@mejuri.com' } }))
end

it 'updates order to state `payment` and calls several methods to update the order related records' do
expect(order).to(receive(:create_proposed_shipments))
expect_any_instance_of(Spree::LineItem).to(receive(:store_ets))
expect(order).to(receive(:charge_taxes))

subject.new(order: order).upsert_data
expect(order.payment?).to(be_truthy)
end
end
end
end
end

0 comments on commit 5cbf96c

Please sign in to comment.