Rearranges relevant and non-relevant test cases

This commit is contained in:
filipefurtad0
2023-09-04 19:03:05 +01:00
parent 32c0b5a3e2
commit 4e54279b05

View File

@@ -17,94 +17,98 @@ describe OrderInvoiceComparator do
}
context "changes on the order object" do
it "returns false if the order didn't change" do
expect(subject).to be false
end
describe "detecting relevant attribute changes" do
it "returns true if a relevant attribute changes" do
Spree::Order.where(id: order.id).update_all(payment_total: order.payment_total + 10)
order.reload
expect(subject).to be true
end
it "returns true if a relevant attribute changes" do
Spree::Order.where(id: order.id).update_all(payment_total: order.payment_total + 10)
order.reload
expect(subject).to be true
end
it "returns true if a relevant attribute changes" do
Spree::Order.where(id: order.id).update_all(total: order.total + 10)
order.reload
expect(subject).to be true
end
it "returns true if a relevant attribute changes" do
Spree::Order.where(id: order.id).update_all(total: order.total + 10)
order.reload
expect(subject).to be true
end
it "returns true if a relevant attribute changes - order state: cancelled" do
order.cancel!
expect(subject).to be true
end
it "returns false if an attribute which should not change, changes" do
Spree::Order.where(id: order.id).update_all(number: 'R631504404')
order.reload
expect(subject).to be false
end
it "returns true if a relevant attribute changes - order state: resumed" do
order.cancel!
order.resume!
expect(subject).to be true
end
it "returns false if an attribute which should not change, changes" do
Spree::Order.where(id: order.id).update_all(currency: 'EUR')
order.reload
expect(subject).to be false
end
context "additional tax total changes" do
let(:order) do
create(:order_with_taxes, product_price: 110, tax_rate_amount: 0.1,
included_in_price: false)
.tap do |order|
order.create_tax_charge!
order.update_shipping_fees!
end
end
it "returns true if a relevant attribute changes - order state: cancelled" do
order.cancel!
expect(subject).to be true
end
it "returns true if a relevant attribute changes - order state: resumed" do
order.cancel!
order.resume!
expect(subject).to be true
end
it "returns false if a non-relevant attribute changes" do
order.update!(special_instructions: "A very special insctruction.")
expect(subject).to be false
end
it "returns false if a non-relevant attribute changes" do
order.update!(note: "THIS IS A NEW NOTE")
expect(subject).to be false
end
context "additional tax total changes" do
let(:order) do
create(:order_with_taxes, product_price: 110, tax_rate_amount: 0.1,
included_in_price: false)
.tap do |order|
order.create_tax_charge!
order.update_shipping_fees!
it "returns returns true" do
Spree::TaxRate.first.update!(amount: 0.15)
order.create_tax_charge! && order.save
expect(subject).to be true
end
end
it "returns returns true" do
Spree::TaxRate.first.update!(amount: 0.15)
order.create_tax_charge! && order.save
expect(subject).to be true
end
end
context "included tax total changes" do
let(:order) do
create(:order_with_taxes, product_price: 110, tax_rate_amount: 0.1,
included_in_price: true)
.tap do |order|
order.create_tax_charge!
order.update_shipping_fees!
end
end
context "included tax total changes" do
let(:order) do
create(:order_with_taxes, product_price: 110, tax_rate_amount: 0.1,
included_in_price: true)
.tap do |order|
order.create_tax_charge!
order.update_shipping_fees!
it "returns returns true" do
Spree::TaxRate.first.update!(amount: 0.15)
order.create_tax_charge! && order.save
expect(subject).to be true
end
end
it "returns returns true" do
Spree::TaxRate.first.update!(amount: 0.15)
order.create_tax_charge! && order.save
expect(subject).to be true
context "shipping method changes" do
let(:shipping_method) { create(:shipping_method) }
it "returns returns true" do
Spree::ShippingRate.first.update(shipping_method_id: shipping_method.id)
expect(subject).to be true
end
end
end
context "shipping method changes" do
let(:shipping_method) { create(:shipping_method) }
it "returns returns true" do
Spree::ShippingRate.first.update(shipping_method_id: shipping_method.id)
expect(subject).to be true
describe "ignoring non-relevant attribute changes" do
it "returns false if the order didn't change" do
expect(subject).to be false
end
it "returns false if an attribute which should not change, changes" do
Spree::Order.where(id: order.id).update_all(number: 'R631504404')
order.reload
expect(subject).to be false
end
it "returns false if an attribute which should not change, changes" do
Spree::Order.where(id: order.id).update_all(currency: 'EUR')
order.reload
expect(subject).to be false
end
it "returns false if a non-relevant attribute changes" do
order.update!(special_instructions: "A very special insctruction.")
expect(subject).to be false
end
it "returns false if a non-relevant attribute changes" do
order.update!(note: "THIS IS A NEW NOTE")
expect(subject).to be false
end
end
end