-
-
Notifications
You must be signed in to change notification settings - Fork 707
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,18 @@ | |
visit checkout_path | ||
end | ||
|
||
context "when a line item is out of stock" do | ||
before do | ||
variant.on_demand = false | ||
variant.on_hand = 0 | ||
variant.save! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you try |
||
end | ||
|
||
it "returns me to the cart with an error message" do | ||
out_of_stock_check(:details) | ||
end | ||
end | ||
|
||
context "when no selecting a shipping method" do | ||
before do | ||
fill_out_details | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ | |
ship_address_id: nil, state: "cart", | ||
line_items: [create(:line_item, variant:)]) | ||
} | ||
|
||
let(:fee_tax_rate) { create(:tax_rate, amount: 0.10, zone:, included_in_price: true) } | ||
let(:fee_tax_category) { create(:tax_category, tax_rates: [fee_tax_rate]) } | ||
let(:enterprise_fee) { create(:enterprise_fee, amount: 1.23, tax_category: fee_tax_category) } | ||
|
@@ -58,6 +57,18 @@ | |
visit checkout_path | ||
end | ||
|
||
context "when a line item is out of stock" do | ||
before do | ||
variant.on_demand = false | ||
variant.on_hand = 0 | ||
variant.save! | ||
end | ||
|
||
it "returns me to the cart with an error message" do | ||
out_of_stock_check(:payment) | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that you follow this context pattern quite strictly. It's seen as good style by many people. I personally find that it's good for larger tests but find it much easier to write short tests in a simple it "alerts me about out of stock items" do
clear_stock_for_variant
visit step
expect_out_of_stock_message
end Some people follow this clear three part structure for tests: setup, action, expectation. Just FYI, you don't have to change anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, that makes sense as well. I understand having the setup within the context block is more code lines - I feel it made my reading easier, when set up in this way. But I totally see the redundancy, for more experienced people. I'll try to keep this in mind for next time. Thanks again 馃檹 |
||
|
||
context "payment step" do | ||
let(:order) { create(:order_ready_for_payment, distributor:) } | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -35,6 +35,11 @@ | |||
create(:shipping_method, require_ship_address: true, | ||||
name: "A Free Shipping with required address") | ||||
} | ||||
let!(:payment_with_fee) { | ||||
create(:payment_method, distributors: [distributor], | ||||
name: "Payment with Fee", description: "Payment with fee", | ||||
calculator: Calculator::FlatRate.new(preferred_amount: 1.23)) | ||||
} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this missing before ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is missing in master. The payment method used for this order currently comes from line 16, when the distributor is created:
Thank you for validating this approach @rioug |
||||
|
||||
before do | ||||
add_enterprise_fee enterprise_fee | ||||
|
@@ -51,6 +56,18 @@ | |||
visit checkout_path | ||||
end | ||||
|
||||
context "when a line item is out of stock" do | ||||
before do | ||||
variant.on_demand = false | ||||
variant.on_hand = 0 | ||||
variant.save! | ||||
end | ||||
|
||||
it "returns me to the cart with an error message" do | ||||
out_of_stock_check(:summary) | ||||
end | ||||
end | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting that we first visit the checkout, then something goes out of stock and then we visit another page. Visits are often expensive in specs. Could the first visit be skipped to save time? |
||||
|
||||
context "summary step" do | ||||
let(:order) { | ||||
create(:order_ready_for_confirmation, distributor:) | ||||
|
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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 馃檹