Improve customer tests

This commit is contained in:
Matt-Yorkley
2023-06-07 00:28:43 +01:00
parent 6daf29400f
commit 7a7ab17db4

View File

@@ -113,33 +113,49 @@ describe '
end
context "when creating an order with a customer-only" do
let!(:order) { create(:order, distributor: distributor, order_cycle: order_cycle) }
let(:customer2) { create(:customer, enterprise: distributor) }
let(:customer3) { create(:customer, enterprise: distributor) }
before do
login_as_admin
visit spree.new_admin_order_path
select2_select distributor.name, from: 'order_distributor_id'
select2_select order_cycle.name, from: 'order_order_cycle_id'
click_button 'Next'
expect(Spree::Order.last.customer_id).to be_nil
visit spree.admin_order_customer_path(order)
end
it "sets the customer on the order" do
expect(order.customer_id).to be_nil
tomselect_search_and_select customer2.email, from: 'customer_search_override'
check 'order_use_billing'
click_button 'Update'
expect(page).to have_content 'Customer Details updated'
expect(order.reload.customer).to eq customer2
end
it "set the right customer attached to the order" do
expect(Spree::Order.last.reload.customer).to eq customer2
end
context "when changing the attached customer" do
before do
order.update(
customer: customer2,
email: customer2.email,
ship_address: customer2.ship_address,
bill_address: customer2.bill_address
)
visit spree.admin_order_customer_path(order)
end
it "should update the order customer (not only its details)" do
expect(page).to have_field 'order_email', with: customer2.email
tomselect_search_and_select customer3.email, from: 'customer_search_override'
check 'order_use_billing'
it "when changing the attached customer,"\
"it should update the order customer (not only its details)" do
tomselect_search_and_select customer3.email, from: 'customer_search_override'
expect do
click_button 'Update'
expect(page).to have_field 'order_email', with: customer3.email
end.to change { Spree::Order.last.reload.customer }.from(customer2).to(customer3)
expect do
click_button 'Update'
expect(page).to have_content 'Customer Details updated'
end.to change { order.reload.customer }.from(customer2).to(customer3)
end
end
end