forked from openfoodfoundation/openfoodnetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fec2ca2
commit 1c9bd90
Showing
2 changed files
with
89 additions
and
17 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
spec/services/order_invoice_comparator_shared_examples_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
shared_examples "attribute changes - payment total" do |boolean, type| | ||
before do | ||
Spree::Order.where(id: order.id).update_all(payment_total: order.payment_total + 10) | ||
end | ||
|
||
it "returns #{boolean} if a #{type} attribute changes" do | ||
order.reload | ||
expect(subject).to be boolean | ||
end | ||
end | ||
|
||
shared_examples "attribute changes - order total" do |boolean, type| | ||
before do | ||
Spree::Order.where(id: order.id).update_all(total: order.total + 10) | ||
end | ||
|
||
it "returns #{boolean} if a #{type} attribute changes" do | ||
order.reload | ||
expect(subject).to be boolean | ||
end | ||
end | ||
|
||
shared_examples "attribute changes - order state: cancelled" do |boolean, type| | ||
before do | ||
order.cancel! | ||
end | ||
|
||
it "returns #{boolean} if a #{type} attribute changes" do | ||
order.reload | ||
expect(subject).to be boolean | ||
end | ||
end | ||
|
||
describe OrderInvoiceComparator do | ||
describe '#can_generate_new_invoice?' do | ||
# this passes 'order' as argument to the invoice comparator | ||
let(:order) { create(:completed_order_with_fees) } | ||
let!(:invoice_data_generator){ InvoiceDataGenerator.new(order) } | ||
let!(:invoice){ | ||
create(:invoice, | ||
order:, | ||
data: invoice_data_generator.serialize_for_invoice) | ||
} | ||
let(:subject) { | ||
OrderInvoiceComparator.new(order).can_generate_new_invoice? | ||
} | ||
|
||
context "changes on the order object" do | ||
describe "detecting relevant" do | ||
it_behaves_like "attribute changes - payment total", true, "relevant" | ||
it_behaves_like "attribute changes - order total", true, "relevant" | ||
end | ||
|
||
describe "detecting non-relevant" do | ||
pending('A new invoice should not be generated upon order state change') do | ||
it_behaves_like "attribute changes - order state: cancelled", false, "non-relevant" | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '#can_update_latest_invoice?' do | ||
let!(:order) { create(:completed_order_with_fees) } | ||
let!(:invoice_data_generator){ InvoiceDataGenerator.new(order) } | ||
let!(:invoice){ | ||
create(:invoice, | ||
order:, | ||
data: invoice_data_generator.serialize_for_invoice) | ||
} | ||
let(:subject) { | ||
OrderInvoiceComparator.new(order).can_update_latest_invoice? | ||
} | ||
|
||
context "changes on the order object" do | ||
describe "detecting relevant" do | ||
it_behaves_like "attribute changes - order state: cancelled", true, "relevant" | ||
end | ||
|
||
describe "detecting non-relevant" do | ||
it_behaves_like "attribute changes - payment total", false, "non-relevant" | ||
it_behaves_like "attribute changes - order total", false, "non-relevant" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters