Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates checkout tests to cover for out of stock variant #12423

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions spec/support/checkout_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@ def place_order
click_on "Complete order"
expect(page).to have_content "Back To Store"
end

def out_of_stock_check(step)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the method name ambiguous. Does it check that something is out of stock or that nothing is out of stock?

When a test helper is mainly asserting expectations, I use that in the name. What about expect_out_of_stock?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is indeed a whole science on its own. Thanks for that tip 馃檹

visit checkout_step_path(step)

expect(page).not_to have_selector 'closing', text: "Checkout now"
expect(page).to have_selector 'closing', text: "Your shopping cart"
expect(page).to have_content "An item in your cart has become unavailable"
end
end
26 changes: 26 additions & 0 deletions spec/system/consumer/checkout/guest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,30 @@
end
end
end

shared_examples "when a line item is out of stock" do |session, step|
context "as a #{session} user" do
let(:user) { create(:user) }
before do
variant.on_demand = false
variant.on_hand = 0
variant.save!

if session == "logged"
login_as(user)
end
Comment on lines +304 to +306
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this conditional, you could just do the login in a context block outside of the shared examples.

end
it "returns me to the cart with an error message" do
out_of_stock_check(step)
end
end
end

it_behaves_like "when a line item is out of stock", "guest", "details"
it_behaves_like "when a line item is out of stock", "guest", "payment"
it_behaves_like "when a line item is out of stock", "guest", "summary"

it_behaves_like "when a line item is out of stock", "logged", "details"
it_behaves_like "when a line item is out of stock", "logged", "payment"
it_behaves_like "when a line item is out of stock", "logged", "summary"
end