Skip to content

Commit

Permalink
fix hopefully last BOGO bug: when number of tickets of type available…
Browse files Browse the repository at this point in the history
… is less than min purchase, should just show zero
  • Loading branch information
armandofox committed Nov 30, 2023
1 parent a2f1130 commit c79dc52
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
14 changes: 9 additions & 5 deletions app/models/valid_voucher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ def max_sales_for_this_patron
# that respects min and max sales per txn as well as max of remaining seats etc.
# Make the menu contain at most max choices.
def min_and_max_sales_for_this_txn(max_choices = INFINITE)
max_sales = [self.max_sales_for_this_patron, self.max_sales_per_txn].min
min_sales = [self.min_sales_per_txn, max_sales].min # in case max_sales is zero too!
range = [max_sales - min_sales + 1, max_choices].min
if max_sales.zero?
max_sales = [self.max_sales_for_this_patron,
self.max_sales_per_txn,
self.seats_of_type_remaining].
min
min_sales = self.min_sales_per_txn
if (max_sales.zero? || # maybe no seats of this type remaining
max_sales < min_sales) # or just not enough
[0]
else
else # at this point, we know max_sales >= min_sales, and neither is zero
range = [max_sales - min_sales + 1, max_choices].min
[0] + (min_sales .. min_sales+range-1).to_a
end
end
Expand Down
12 changes: 9 additions & 3 deletions features/step_definitions/showdate_has_vouchers_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
Given /^a show "(.*)" with the following tickets available:$/ do |show_name, tickets|
tickets.hashes.each do |t|
steps %Q{Given a show "#{show_name}" with #{t[:qty]} "#{t[:type]}" tickets for #{t[:price]} on "#{t[:showdate]}"}
@showdate = Showdate.find_by!(:thedate => Time.parse(t[:showdate]))
# if sales cutoff time is specified, modify the valid-voucher once created
if (cutoff = t[:sales_cutoff])
sd = Showdate.find_by!(:thedate => Time.parse(t[:showdate]))
vv = ValidVoucher.find_by!(:showdate => sd, :vouchertype => Vouchertype.find_by!(:name => t[:type]))
vv.update_attributes(:end_sales => sd.thedate - cutoff.to_i.minutes)
vv = ValidVoucher.find_by!(:showdate => @showdate, :vouchertype => Vouchertype.find_by!(:name => t[:type]))
vv.update_attributes(:end_sales => @showdate.thedate - cutoff.to_i.minutes)
end
end
end
Expand All @@ -34,6 +34,12 @@
make_valid_tickets(@showdate, @vouchertype, n.to_i)
end

Given /"(.*)" tickets for that performance must be purchased at least (\d+) and at most (\d+) at a time/ do |vtype,min,max|
expect(@showdate).to be_a_kind_of Showdate
vv = ValidVoucher.find_by!(:showdate => @showdate, :vouchertype => Vouchertype.find_by!(:name => vtype))
vv.update_attributes!(:min_sales_per_txn => min.to_i, :max_sales_per_txn => max.to_i)
end

Given /^the "(.*)" tickets for "(.*)" require promo code "(.*)"$/ do |ticket_type,date,promo|
vouchertype = Vouchertype.find_by_name! ticket_type
showdate = Showdate.find_by_thedate! Time.zone.parse date
Expand Down
24 changes: 23 additions & 1 deletion features/store/min_and_max_sales_per_transaction.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ Feature: enforce minimum and maximum sales per transaction for a particular vouc

Background: performance with minimum and maximum purchase limits on a promotional ticket

Given a show "The Nerd" with 5 "General" tickets for $10.00 on "Oct 1, 2010, 7pm"
And "General" tickets for that performance must be purchased at least 3 and at most 4 at a time

Scenario: cannot add fewer than minimum tickets per transaction to cart

Scenario: cannot add more than maximum tickets per transaction to cart, even if seats available
Given 1 "General" tickets have been sold for "Oct 1, 2010, 7pm"
When I go to the store page
Then the "General - $10.00" menu should have options: 0;3;4
Then show me the page

Scenario: cannot add fewer than minimum tickets per transaction to cart, nor more than available

Given 2 "General" tickets have been sold for "Oct 1, 2010, 7pm"
When I go to the store page
Then the "General - $10.00" menu should have options: 0;3
Then show me the page

Scenario: when minimum purchase per txn exceeds number of tickets of that type remaining, should show as sold out

Given 3 "General" tickets have been sold for "Oct 1, 2010, 7pm"
When I go to the store page
Then the "General - $10.00" menu should have options: 0



0 comments on commit c79dc52

Please sign in to comment.