Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect completed_at timestamp in order factories #4168

Merged
merged 2 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions core/lib/spree/testing_support/factories/order_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

factory :completed_order_with_promotion do
transient do
completed_at { Time.current }
promotion { nil }
end

Expand All @@ -79,7 +80,7 @@
order.order_promotions.create!(promotion: promotion, promotion_code: promotion_code)

# Complete the order after the promotion has been activated
order.update_column(:completed_at, Time.current)
order.update_column(:completed_at, evaluator.completed_at)
order.update_column(:state, "complete")
end
end
Expand All @@ -104,13 +105,16 @@
end

factory :completed_order_with_totals do
transient do
completed_at { Time.current }
end
state { 'complete' }

after(:create) do |order|
after(:create) do |order, evaluator|
order.shipments.each do |shipment|
shipment.inventory_units.update_all state: 'on_hand', pending: false
end
order.update_column(:completed_at, Time.current)
order.update_column(:completed_at, evaluator.completed_at)
end

factory :completed_order_with_pending_payment do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@
end
end
end

RSpec.shared_examples 'supplied completed_at is respected' do
context 'when passed a completed_at timestamp' do
let(:completed_at) { 2.days.ago }
let(:order) { create(factory, completed_at: completed_at) }

it 'respects the timestamp' do
expect(order.completed_at).to be_within(5.seconds).of(completed_at)
end
end

context 'when no completed_at timestamp is passed' do
let(:order) { create(factory) }

it 'defaults to the current time' do
expect(order.completed_at).to be_within(5.seconds).of(Time.current)
end
end
end

RSpec.describe 'order factory' do
let(:factory_class) { Spree::Order }

Expand Down Expand Up @@ -200,6 +220,7 @@
it_behaves_like 'a working factory'
it_behaves_like 'an order with line items factory', "complete", "on_hand"
it_behaves_like 'shipping methods are assigned'
it_behaves_like 'supplied completed_at is respected'

it "has the expected attributes" do
order = create(factory)
Expand Down Expand Up @@ -255,6 +276,7 @@
it_behaves_like 'a working factory'
it_behaves_like 'an order with line items factory', "complete", "on_hand"
it_behaves_like 'shipping methods are assigned'
it_behaves_like 'supplied completed_at is respected'

it "has the expected attributes" do
order = create(factory)
Expand All @@ -278,6 +300,7 @@
it_behaves_like 'a working factory'
it_behaves_like 'an order with line items factory', "complete", "on_hand"
it_behaves_like 'shipping methods are assigned'
it_behaves_like 'supplied completed_at is respected'

it "has the expected attributes" do
order = create(factory)
Expand All @@ -304,6 +327,7 @@
it_behaves_like 'a working factory'
it_behaves_like 'an order with line items factory', "complete", "on_hand"
it_behaves_like 'shipping methods are assigned'
it_behaves_like 'supplied completed_at is respected'

it "has the expected attributes" do
order = create(factory)
Expand Down Expand Up @@ -345,6 +369,7 @@
it_behaves_like 'a working factory'
it_behaves_like 'an order with line items factory', "complete", "shipped"
it_behaves_like 'shipping methods are assigned'
it_behaves_like 'supplied completed_at is respected'

it "has the expected attributes" do
order = create(factory)
Expand Down