mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #7432 from coopdevs/add-tests-to-customers
Add tests to customers
This commit is contained in:
@@ -733,7 +733,8 @@ module Spree
|
||||
end
|
||||
|
||||
def require_customer?
|
||||
return true unless new_record? || state == 'cart'
|
||||
return false if new_record? || state == 'cart'
|
||||
true
|
||||
end
|
||||
|
||||
def customer_is_valid?
|
||||
|
||||
@@ -915,8 +915,74 @@ describe Spree::Order do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#require_customer?" do
|
||||
context "when the record is new" do
|
||||
let(:order) { build(:order, state: state) }
|
||||
|
||||
context "and the state is not cart" do
|
||||
let(:state) { "complete" }
|
||||
|
||||
it "returns true" do
|
||||
expect(order.send(:require_customer?)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context "and the state is cart" do
|
||||
let(:state) { "cart" }
|
||||
|
||||
it "returns false" do
|
||||
expect(order.send(:require_customer?)).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when the record is not new" do
|
||||
let(:order) { create(:order, state: state) }
|
||||
|
||||
context "and the state is not cart" do
|
||||
let(:state) { "complete" }
|
||||
|
||||
it "returns true" do
|
||||
expect(order.send(:require_customer?)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
context "and the state is cart" do
|
||||
let(:state) { "cart" }
|
||||
|
||||
it "returns false" do
|
||||
expect(order.send(:require_customer?)).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "associating a customer" do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
|
||||
context "when creating an order" do
|
||||
it "does not create a customer" do
|
||||
order = create(:order, distributor: distributor)
|
||||
expect(order.customer).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "when updating the order" do
|
||||
let!(:order) { create(:order, distributor: distributor) }
|
||||
|
||||
before do
|
||||
order.state = "complete"
|
||||
order.save!
|
||||
end
|
||||
|
||||
it "creates a customer" do
|
||||
expect(order.customer).not_to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#associate_customer" do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let!(:order) { create(:order, distributor: distributor) }
|
||||
|
||||
context "when an email address is available for the order" do
|
||||
|
||||
Reference in New Issue
Block a user