Skip to content

Commit

Permalink
Merge pull request #1135 from internetee/autottests-for-slipping-time…
Browse files Browse the repository at this point in the history
…-by-autobider

Autottests for slipping time by autobider
  • Loading branch information
vohmar authored Sep 20, 2023
2 parents 0ba9aa8 + a95eafd commit ca796db
Show file tree
Hide file tree
Showing 2 changed files with 364 additions and 215 deletions.
135 changes: 135 additions & 0 deletions test/models/offer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ def setup

@expired_auction = auctions(:expired)
@valid_auction = auctions(:valid_with_offers)
@english_auction = auctions(:english)
@billing_profile = billing_profiles(:company)
@user = users(:participant)
@second_user = users(:second_place_participant)
@offer = offers(:expired_offer)

BillingProfile.create_default_for_user(@second_user.id)
@second_user.reload

travel_to Time.parse('2010-07-05 10:30 +0000').in_time_zone
end

Expand Down Expand Up @@ -241,4 +246,134 @@ def test_if_next_bid_higher_or_equal_that_min_bid_then_no_any_errors

assert_equal([], offer.errors[:price])
end

def test_if_blind_auction_has_5_last_for_end_minute_slipping_end_don_not_added
assert @valid_auction.blind? || @valid_auction.platform.blank?

@valid_auction.update(ends_at: Time.zone.now + 3.minute)
@valid_auction.reload

ends_at = @valid_auction.ends_at

offer = Offer.new
offer.auction = @valid_auction
offer.user = @second_user
offer.cents = @valid_auction.currently_winning_offer.cents + 1_000
offer.billing_profile = @second_user.billing_profiles.first
offer.save

offer.reload && @valid_auction.reload

assert_equal ends_at, @valid_auction.ends_at
end

def test_if_blind_auction_has_more_than_5_last_minute_to_end_slipping_end_not_added
assert @valid_auction.blind? || @valid_auction.platform.blank?

@valid_auction.update(ends_at: Time.zone.now + 20.minute)
@valid_auction.reload

ends_at = @valid_auction.ends_at

offer = Offer.new
offer.auction = @valid_auction
offer.user = @second_user
offer.cents = @valid_auction.currently_winning_offer.cents + 1_000
offer.billing_profile = @second_user.billing_profiles.first
offer.save

offer.reload && @valid_auction.reload

assert_equal ends_at, @valid_auction.ends_at
end

def test_if_english_auction_has_5_last_for_end_minute_slipping_end_is_added
assert @english_auction.english?

@english_auction.update(slipping_end: 15, ends_at: Time.zone.now + 3.minute)
@english_auction.reload

offer = Offer.new
offer.auction = @english_auction
offer.user = @second_user
offer.cents = 10_000
offer.billing_profile = @second_user.billing_profiles.first
offer.save

offer.reload && @english_auction.reload

assert_equal Time.zone.now + 15.minute, @english_auction.ends_at
end

def test_if_english_auction_has_more_than_5_last_minute_to_end_slipping_end_is_added
assert @english_auction.english?

@english_auction.update(slipping_end: 15, ends_at: Time.zone.now + 20.minute)
@english_auction.reload

ends_at = @english_auction.ends_at

offer = Offer.new
offer.auction = @english_auction
offer.user = @second_user
offer.cents = 10_000
offer.billing_profile = @second_user.billing_profiles.first
offer.save

offer.reload && @english_auction.reload

assert_equal ends_at, @english_auction.ends_at
end

def test_slipping_time_added_to_english_auction_if_outbided
assert @english_auction.english?

offer = Offer.new
offer.auction = @english_auction
offer.user = @user
offer.cents = 10_000
offer.billing_profile = @user.billing_profiles.first
offer.save

@english_auction.update(slipping_end: 15, ends_at: Time.zone.now + 3.minute)
@english_auction.reload

offer = Offer.new
offer.auction = @english_auction
offer.user = @second_user
offer.cents = 20_000
offer.billing_profile = @second_user.billing_profiles.first
offer.save

offer.reload && @english_auction.reload

assert_equal Time.zone.now + 15.minute, @english_auction.ends_at
end

def test_slipping_time_no_added_to_blind_auction_if_outbided
assert @valid_auction.blind? || @valid_auction.platform.blank?

offer = Offer.new
offer.auction = @valid_auction
offer.user = @user
offer.cents = @valid_auction.currently_winning_offer.cents + 1_000
offer.billing_profile = @user.billing_profiles.first
offer.save

@valid_auction.update(ends_at: Time.zone.now + 3.minute)
@valid_auction.reload

ends_at = @valid_auction.ends_at

offer = Offer.new
offer.auction = @valid_auction
offer.user = @second_user
offer.cents = @valid_auction.currently_winning_offer.cents + 1_000
offer.billing_profile = @second_user.billing_profiles.first
offer.save

offer.reload && @valid_auction.reload

assert_equal ends_at, @valid_auction.ends_at
end
end
Loading

0 comments on commit ca796db

Please sign in to comment.