mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Adds unit tests for different attributes
This commit is contained in:
@@ -115,19 +115,217 @@ describe OrderInvoiceComparator do
|
||||
end
|
||||
end
|
||||
|
||||
context "a non-relevant associated model is updated" do
|
||||
let(:distributor){ order.distributor }
|
||||
it "returns false" do
|
||||
distributor.update!(name: 'THIS IS A NEW NAME', abn: 'This is a new ABN')
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
context "changes on an associated order object" do
|
||||
describe "detecting relevant associated object changes" do
|
||||
context "adjustment changes" do
|
||||
it "creating a new adjustment returns true" do
|
||||
create(:adjustment, order_id: order.id)
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
context "a relevant associated object is updated" do
|
||||
let(:line_item){ order.line_items.first }
|
||||
it "return true" do
|
||||
line_item.update!(quantity: line_item.quantity + 1)
|
||||
expect(subject).to be true
|
||||
context "with an existing adjustment" do
|
||||
let!(:adjustment) { create(:adjustment, order_id: order.id) }
|
||||
|
||||
it "editing the amount returns true" do
|
||||
adjustment.update!(amount: 123)
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "changing the adjustment type" do
|
||||
adjustment.update!(adjustable_type: "Spree::Payment")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "deleting the label" do
|
||||
order.all_adjustments.destroy_all
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "line item changes" do
|
||||
let(:line_item){ order.line_items.first }
|
||||
|
||||
context "on quantitity" do
|
||||
it "return true" do
|
||||
line_item.update!(quantity: line_item.quantity + 1)
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context "on variant id" do
|
||||
it "return true" do
|
||||
line_item.update!(variant_id: Spree::Variant.first.id)
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "bill address changes on" do
|
||||
let(:bill_address) { Spree::Address.where(id: order.bill_address_id) }
|
||||
it "first name" do
|
||||
bill_address.update!(firstname: "Jane")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "last name" do
|
||||
bill_address.update!(lastname: "Jones")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "address (1)" do
|
||||
bill_address.update!(address1: "Rue du Fromage 66")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "address (2)" do
|
||||
bill_address.update!(address2: "South by Southwest")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "city" do
|
||||
bill_address.update!(city: "Antibes")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "zipcode" do
|
||||
bill_address.update!(zipcode: "04229")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "phone" do
|
||||
bill_address.update!(phone: "111-222-333")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "company" do
|
||||
bill_address.update!(company: "A Company Name")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context "ship address changes on" do
|
||||
let(:ship_address) { Spree::Address.where(id: order.ship_address_id) }
|
||||
it "first name" do
|
||||
ship_address.update!(firstname: "Jane")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "last name" do
|
||||
ship_address.update!(lastname: "Jones")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "address (1)" do
|
||||
ship_address.update!(address1: "Rue du Fromage 66")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "address (2)" do
|
||||
ship_address.update!(address2: "South by Southwest")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "city" do
|
||||
ship_address.update!(city: "Antibes")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "zipcode" do
|
||||
ship_address.update!(zipcode: "04229")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "phone" do
|
||||
ship_address.update!(phone: "111-222-333")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
|
||||
it "company" do
|
||||
ship_address.update!(company: "A Company Name")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context "customer changes on" do
|
||||
let(:customer){ order.customer }
|
||||
|
||||
context "code" do
|
||||
it "return false" do
|
||||
customer.update!(code: 98_754)
|
||||
order.reload
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context "email" do
|
||||
it "return false" do
|
||||
customer.update!(email: "customer@email.org")
|
||||
order.reload
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "payment changes on" do
|
||||
let(:payment) { create(:payment, order_id: order.id) }
|
||||
context "amount" do
|
||||
it "returns true" do
|
||||
payment.update!(amount: 222)
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context "payment method" do
|
||||
let(:payment_method) { create(:payment_method) }
|
||||
|
||||
it "returns true" do
|
||||
payment.update!(payment_method_id: payment_method.id)
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "ignoring non-relevant associated object changes" do
|
||||
context "customer changes" do
|
||||
let(:customer){ create(:customer) }
|
||||
it "returns false" do
|
||||
order.update!(customer_id: customer.id)
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context "distributor changes" do
|
||||
let(:distributor){ order.distributor }
|
||||
it "returns false" do
|
||||
distributor.update!(name: 'THIS IS A NEW NAME', abn: 'This is a new ABN')
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -159,6 +357,20 @@ describe OrderInvoiceComparator do
|
||||
order.reload
|
||||
expect(subject).to be false
|
||||
end
|
||||
|
||||
context "payment changes on" do
|
||||
context "state" do
|
||||
let(:payment) { order.payments.first }
|
||||
it "returns true" do
|
||||
expect {
|
||||
payment.started_processing
|
||||
}.to change { payment.state }.from("checkout").to("processing")
|
||||
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a non-relevant associated model is updated" do
|
||||
@@ -170,11 +382,25 @@ describe OrderInvoiceComparator do
|
||||
end
|
||||
|
||||
context "a relevant associated object is updated" do
|
||||
let(:payment){ order.payments.first }
|
||||
it "return true" do
|
||||
expect(payment.state).to_not eq 'completed'
|
||||
payment.update!(state: 'completed')
|
||||
expect(subject).to be true
|
||||
describe "detecting relevant associated object changes" do
|
||||
context "adjustment changes" do
|
||||
context "with an existing adjustment" do
|
||||
let!(:adjustment) { create(:adjustment, order_id: order.id) }
|
||||
it "changing the label returns true" do
|
||||
adjustment.update!(label: "It's a new label")
|
||||
order.reload
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
context "payment changes" do
|
||||
let(:payment){ order.payments.first }
|
||||
it "return true" do
|
||||
expect(payment.state).to_not eq 'completed'
|
||||
payment.update!(state: 'completed')
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user