From 3e8c957bd723e6154c47a57db50c516facb8c7b0 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 20 Sep 2023 08:39:35 +0300 Subject: [PATCH 1/2] autotests for autobider --- test/services/autobider_service_test.rb | 430 ++++++++++++------------ 1 file changed, 215 insertions(+), 215 deletions(-) diff --git a/test/services/autobider_service_test.rb b/test/services/autobider_service_test.rb index d85a93468..c667d16ba 100644 --- a/test/services/autobider_service_test.rb +++ b/test/services/autobider_service_test.rb @@ -27,60 +27,60 @@ def teardown travel_back end - # def test_if_offer_of_another_user_is_exist_autobidder_should_outbid - # offer = Offer.new - # offer.auction = @english_auction - # offer.user = @user_two - # offer.cents = 500 - # offer.billing_profile = @user_two.billing_profiles.first - # offer.save! - # @english_auction.update_minimum_bid_step(5.1) + def test_if_offer_of_another_user_is_exist_autobidder_should_outbid + offer = Offer.new + offer.auction = @english_auction + offer.user = @user_two + offer.cents = 500 + offer.billing_profile = @user_two.billing_profiles.first + offer.save! + @english_auction.update_minimum_bid_step(5.1) - # @english_auction.reload + @english_auction.reload - # AutobiderService.autobid(@english_auction) + AutobiderService.autobid(@english_auction) - # assert_equal @english_auction.highest_price.to_f, 5.2 - # assert_equal @english_auction.min_bids_step, 5.3 - # assert_equal @autobider.user, @user - # assert_equal @english_auction.currently_winning_offer.user, @user - # end + assert_equal @english_auction.highest_price.to_f, 5.2 + assert_equal @english_auction.min_bids_step, 5.3 + assert_equal @autobider.user, @user + assert_equal @english_auction.currently_winning_offer.user, @user + end - # def test_user_cannot_to_outbid_him_self_if_previous_highest_offer_is_him - # bid_in_cents = 500 + def test_user_cannot_to_outbid_him_self_if_previous_highest_offer_is_him + bid_in_cents = 500 - # offer = Offer.new - # offer.auction = @english_auction - # offer.user = @user - # offer.cents = bid_in_cents - # offer.billing_profile = @user_two.billing_profiles.first - # offer.save! + offer = Offer.new + offer.auction = @english_auction + offer.user = @user + offer.cents = bid_in_cents + offer.billing_profile = @user_two.billing_profiles.first + offer.save! - # @english_auction.update_minimum_bid_step(5.0) - # @english_auction.reload + @english_auction.update_minimum_bid_step(5.0) + @english_auction.reload - # assert_equal offer.user, @user - # AutobiderService.autobid(@english_auction) - # @english_auction.reload + assert_equal offer.user, @user + AutobiderService.autobid(@english_auction) + @english_auction.reload - # assert_equal @english_auction.highest_price.to_f, 5.0 - # assert_equal @english_auction.min_bids_step, 5.1 - # assert_equal @english_auction.currently_winning_offer.user, @user - # end + assert_equal @english_auction.highest_price.to_f, 5.0 + assert_equal @english_auction.min_bids_step, 5.1 + assert_equal @english_auction.currently_winning_offer.user, @user + end - # def test_create_first_bid_as_starting_price_if_no_any_offers - # @english_auction.offers.destroy_all - # @english_auction.reload + def test_create_first_bid_as_starting_price_if_no_any_offers + @english_auction.offers.destroy_all + @english_auction.reload - # assert_equal @english_auction.offers.count, 0 + assert_equal @english_auction.offers.count, 0 - # AutobiderService.autobid(@english_auction) - # @english_auction.reload + AutobiderService.autobid(@english_auction) + @english_auction.reload - # assert_equal @english_auction.offers.count, 1 - # assert_equal @english_auction.highest_price.to_f, @english_auction.starting_price - # assert_equal @english_auction.offers.first.user, @user - # end + assert_equal @english_auction.offers.count, 1 + assert_equal @english_auction.highest_price.to_f, @english_auction.starting_price + assert_equal @english_auction.offers.first.user, @user + end def test_no_new_offer_if_starting_price_more_than_autobider_value @english_auction.offers.destroy_all @@ -98,69 +98,69 @@ def test_no_new_offer_if_starting_price_more_than_autobider_value assert_equal @english_auction.offers.count, 0 end - # def test_if_two_participants_have_autobiders_should_be_sets_penultimate_value - # autobider_two = Autobider.create(user: @user_two, domain_name: @english_auction.domain_name, cents: 15_000) + def test_if_two_participants_have_autobiders_should_be_sets_penultimate_value + autobider_two = Autobider.create(user: @user_two, domain_name: @english_auction.domain_name, cents: 15_000) - # offer = Offer.new - # offer.auction = @english_auction - # offer.user = @user - # offer.cents = 500 - # offer.billing_profile = @user_two.billing_profiles.first - # offer.save! + offer = Offer.new + offer.auction = @english_auction + offer.user = @user + offer.cents = 500 + offer.billing_profile = @user_two.billing_profiles.first + offer.save! - # assert_equal @english_auction.highest_price.to_f, 5.0 - # assert_equal @autobider.cents, 20_000 # 200.0 - # assert_equal autobider_two.cents, 15_000 # 150.0 + assert_equal @english_auction.highest_price.to_f, 5.0 + assert_equal @autobider.cents, 20_000 # 200.0 + assert_equal autobider_two.cents, 15_000 # 150.0 - # AutobiderService.autobid(@english_auction) - # @english_auction.reload + AutobiderService.autobid(@english_auction) + @english_auction.reload - # assert_equal @english_auction.highest_price.to_f, 160.0 - # assert_equal @english_auction.min_bids_step, 170.0 - # end + assert_equal @english_auction.highest_price.to_f, 160.0 + assert_equal @english_auction.min_bids_step, 170.0 + end - # def test_if_two_participants_have_same_values_should_be_apply_for_early_record - # offer = Offer.new - # offer.auction = @english_auction - # offer.user = @user - # offer.cents = 500 - # offer.billing_profile = @user_two.billing_profiles.first - # offer.save! + def test_if_two_participants_have_same_values_should_be_apply_for_early_record + offer = Offer.new + offer.auction = @english_auction + offer.user = @user + offer.cents = 500 + offer.billing_profile = @user_two.billing_profiles.first + offer.save! - # autobider_two = Autobider.create(user: @user_two, domain_name: @english_auction.domain_name, cents: 20_000) - # assert_equal @autobider.cents, autobider_two.cents + autobider_two = Autobider.create(user: @user_two, domain_name: @english_auction.domain_name, cents: 20_000) + assert_equal @autobider.cents, autobider_two.cents - # @autobider.update(updated_at: Time.zone.now - 20.minutes) - # @autobider.reload - # autobider_two.update(updated_at: Time.zone.now - 10.minutes) - # autobider_two.reload + @autobider.update(created_at: Time.zone.now - 20.minutes) + @autobider.reload + autobider_two.update(created_at: Time.zone.now - 10.minutes) + autobider_two.reload - # AutobiderService.autobid(@english_auction) - # @english_auction.reload + AutobiderService.autobid(@english_auction) + @english_auction.reload - # assert_equal @english_auction.currently_winning_offer.user, @autobider.user - # end + assert_equal @english_auction.currently_winning_offer.user, @autobider.user + end - # def test_highest_autobider_should_outbid_penultimate_autobider_value - # @english_auction.reload + def test_highest_autobider_should_outbid_penultimate_autobider_value + @english_auction.reload - # offer = Offer.new - # offer.auction = @english_auction - # offer.user = @user_two - # offer.cents = 500 - # offer.billing_profile = @user_two.billing_profiles.first - # offer.save! + offer = Offer.new + offer.auction = @english_auction + offer.user = @user_two + offer.cents = 500 + offer.billing_profile = @user_two.billing_profiles.first + offer.save! - # Autobider.create(user: @user_two, domain_name: @english_auction.domain_name, cents: 15_000) - # # @autobider.update(created_at: autobider_two.created_at - 1.day) # because travel_to in setup method - # @autobider.reload + Autobider.create(user: @user_two, domain_name: @english_auction.domain_name, cents: 15_000) + # @autobider.update(created_at: autobider_two.created_at - 1.day) # because travel_to in setup method + @autobider.reload - # AutobiderService.autobid(@english_auction) - # @english_auction.reload + AutobiderService.autobid(@english_auction) + @english_auction.reload - # assert_equal @english_auction.currently_winning_offer.cents, 16_000 - # assert_equal @english_auction.currently_winning_offer.user, @autobider.user - # end + assert_equal @english_auction.currently_winning_offer.cents, 16_000 + assert_equal @english_auction.currently_winning_offer.user, @autobider.user + end def test_no_apply_for_blind_auction autobider_two = Autobider.create(user: @user_two, domain_name: @auction.domain_name, cents: 20_000) @@ -176,128 +176,128 @@ def test_no_apply_for_blind_auction assert_equal @auction.offers.count, 0 end - # def test_autobidder_should_set_higher_bid - # # set autobidder to 4 with user1 and 3,99 with user2. current price was 2,99, next min price 3,09. - # #Price was raised to 3,19 for the user1. Correct results is current price of 4 for the U1 as they had set their autobidder value higher - - # Autobider.destroy_all - # @english_auction.offers.destroy_all - # @english_auction.update(min_bids_step: 1.0) - # @english_auction.update(starting_price: 1.0) - # @english_auction.reload - # offer = Offer.new - # offer.auction = @english_auction - # offer.user = @user - # offer.cents = 299 - # offer.billing_profile = @user.billing_profiles.first - # offer.save! - # offer.reload - - # @english_auction.update(min_bids_step: 3.09) - # @english_auction.reload - - # assert_equal @english_auction.currently_winning_offer.cents, 299 - # assert_equal @english_auction.min_bids_step, 3.09 - - # Autobider.create(user: @user_two, domain_name: @english_auction.domain_name, cents: 399) - # AutobiderService.autobid(@english_auction) - # @english_auction.reload - - # Autobider.create(user: @user, domain_name: @english_auction.domain_name, cents: 400) - # AutobiderService.autobid(@english_auction) - # @english_auction.reload - - # assert_equal @english_auction.currently_winning_offer.cents, 400 - # end - - # def test_with_equal_bid_offer_should_be_who_set_first - # # set autobidder to 4 with user1 and did the same with user2. Current price 3,19, next min price 3,29. User1 had the highest bid. Nothing changed when U2 set its autobidder to 4 - current price was not changed. Whilst the correct result would have been 4.0 highest offer for U1 as they set their autobidder first at 4 - # Autobider.destroy_all - # @english_auction.offers.destroy_all - # @english_auction.update(min_bids_step: 1.0) - # @english_auction.update(starting_price: 1.0) - # @english_auction.reload - - # offer = Offer.new - # offer.auction = @english_auction - # offer.user = @user - # offer.cents = 319 - # offer.billing_profile = @user.billing_profiles.first - # offer.save! - # offer.reload - # offer.update(updated_at: Time.zone.now - 2.minute) - # offer.reload - - # @english_auction.update(min_bids_step: 3.29) - # @english_auction.reload - - # assert_equal @english_auction.currently_winning_offer.cents, 319 - # assert_equal @english_auction.min_bids_step, 3.29 - - # Autobider.create(user: @user_two, domain_name: @english_auction.domain_name, cents: 400) - # AutobiderService.autobid(@english_auction) - # @english_auction.reload - - # Autobider.create(user: @user, domain_name: @english_auction.domain_name, cents: 400) - # AutobiderService.autobid(@english_auction) - # @english_auction.reload - - # assert_equal @english_auction.currently_winning_offer.user, @user_two - # assert_equal @english_auction.currently_winning_offer.cents, 400 - # end - - # def test_should_be_set_actual_highest_value_from_autobidder - # # still not OK. set autobidder on one user to 2.0 current price1,8. Another user made a bid for 1,99 - internal error! going back revealed that the autobid failed and the 2nd users 1,99 was set as the new highest bid. - # Autobider.destroy_all - # @english_auction.offers.destroy_all - # @english_auction.update(min_bids_step: 1.0) - # @english_auction.update(starting_price: 1.0) - # @english_auction.reload - - # offer = Offer.new - # offer.auction = @english_auction - # offer.user = @user - # offer.cents = 180 - # offer.billing_profile = @user.billing_profiles.first - # offer.save! - # offer.reload - # offer.update(updated_at: Time.zone.now - 2.minute) - # offer.reload - - # @english_auction.update_minimum_bid_step(1.8) - # @english_auction.reload - - # Autobider.create(user: @user, domain_name: @english_auction.domain_name, cents: 200) - - # offer = Offer.new - # offer.auction = @english_auction - # offer.user = @user_two - # offer.cents = 199 - # offer.billing_profile = @user.billing_profiles.last - # offer.save! - # offer.reload - # offer.update(updated_at: Time.zone.now - 1.minute) - # offer.reload - - # @english_auction.update_minimum_bid_step(offer.cents) - # @english_auction.reload - - # AutobiderService.autobid(@english_auction) - # @english_auction.reload - # @english_auction.offers.first.reload - # @english_auction.offers.last.reload - - # assert_equal @english_auction.currently_winning_offer.cents, 200 - # end - - # def test_autobider_should_change_ends_at_if_bid_set_in_slipping_time - # @english_auction.update(ends_at: Time.zone.now + 3.minute) - # @english_auction.reload - - # assert_equal @english_auction.ends_at, Time.zone.now + 3.minute - # assert_equal @english_auction.slipping_end, 5 - - # AutobiderService.autobid(@english_auction) - # assert_equal @english_auction.ends_at, Time.zone.now + 5.minute - # end + def test_autobidder_should_set_higher_bid + # set autobidder to 4 with user1 and 3,99 with user2. current price was 2,99, next min price 3,09. + #Price was raised to 3,19 for the user1. Correct results is current price of 4 for the U1 as they had set their autobidder value higher + + Autobider.destroy_all + @english_auction.offers.destroy_all + @english_auction.update(min_bids_step: 1.0) + @english_auction.update(starting_price: 1.0) + @english_auction.reload + offer = Offer.new + offer.auction = @english_auction + offer.user = @user + offer.cents = 299 + offer.billing_profile = @user.billing_profiles.first + offer.save! + offer.reload + + @english_auction.update(min_bids_step: 3.09) + @english_auction.reload + + assert_equal @english_auction.currently_winning_offer.cents, 299 + assert_equal @english_auction.min_bids_step, 3.09 + + Autobider.create(user: @user_two, domain_name: @english_auction.domain_name, cents: 399) + AutobiderService.autobid(@english_auction) + @english_auction.reload + + Autobider.create(user: @user, domain_name: @english_auction.domain_name, cents: 400) + AutobiderService.autobid(@english_auction) + @english_auction.reload + + assert_equal @english_auction.currently_winning_offer.cents, 400 + end + + def test_with_equal_bid_offer_should_be_who_set_first + # set autobidder to 4 with user1 and did the same with user2. Current price 3,19, next min price 3,29. User1 had the highest bid. Nothing changed when U2 set its autobidder to 4 - current price was not changed. Whilst the correct result would have been 4.0 highest offer for U1 as they set their autobidder first at 4 + Autobider.destroy_all + @english_auction.offers.destroy_all + @english_auction.update(min_bids_step: 1.0) + @english_auction.update(starting_price: 1.0) + @english_auction.reload + + offer = Offer.new + offer.auction = @english_auction + offer.user = @user + offer.cents = 319 + offer.billing_profile = @user.billing_profiles.first + offer.save! + offer.reload + offer.update(updated_at: Time.zone.now - 2.minute) + offer.reload + + @english_auction.update(min_bids_step: 3.29) + @english_auction.reload + + assert_equal @english_auction.currently_winning_offer.cents, 319 + assert_equal @english_auction.min_bids_step, 3.29 + + Autobider.create(user: @user_two, domain_name: @english_auction.domain_name, cents: 400) + AutobiderService.autobid(@english_auction) + @english_auction.reload + + Autobider.create(user: @user, domain_name: @english_auction.domain_name, cents: 400) + AutobiderService.autobid(@english_auction) + @english_auction.reload + + assert_equal @english_auction.currently_winning_offer.user, @user_two + assert_equal @english_auction.currently_winning_offer.cents, 400 + end + + def test_should_be_set_actual_highest_value_from_autobidder + # still not OK. set autobidder on one user to 2.0 current price1,8. Another user made a bid for 1,99 - internal error! going back revealed that the autobid failed and the 2nd users 1,99 was set as the new highest bid. + Autobider.destroy_all + @english_auction.offers.destroy_all + @english_auction.update(min_bids_step: 1.0) + @english_auction.update(starting_price: 1.0) + @english_auction.reload + + offer = Offer.new + offer.auction = @english_auction + offer.user = @user + offer.cents = 180 + offer.billing_profile = @user.billing_profiles.first + offer.save! + offer.reload + offer.update(updated_at: Time.zone.now - 2.minute) + offer.reload + + @english_auction.update_minimum_bid_step(1.8) + @english_auction.reload + + Autobider.create(user: @user, domain_name: @english_auction.domain_name, cents: 200) + + offer = Offer.new + offer.auction = @english_auction + offer.user = @user_two + offer.cents = 199 + offer.billing_profile = @user.billing_profiles.last + offer.save! + offer.reload + offer.update(updated_at: Time.zone.now - 1.minute) + offer.reload + + @english_auction.update_minimum_bid_step(offer.cents) + @english_auction.reload + + AutobiderService.autobid(@english_auction) + @english_auction.reload + @english_auction.offers.first.reload + @english_auction.offers.last.reload + + assert_equal @english_auction.currently_winning_offer.cents, 200 + end + + def test_autobider_should_change_ends_at_if_bid_set_in_slipping_time + @english_auction.update(ends_at: Time.zone.now + 3.minute) + @english_auction.reload + + assert_equal @english_auction.ends_at, Time.zone.now + 3.minute + assert_equal @english_auction.slipping_end, 5 + + AutobiderService.autobid(@english_auction) + assert_equal @english_auction.ends_at, Time.zone.now + 5.minute + end end From a95eafd5f8c0aad7bbe46e8ed9794f5c3a084ec8 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 20 Sep 2023 09:09:52 +0300 Subject: [PATCH 2/2] added slipping end tests for offer --- test/models/offer_test.rb | 135 ++++++++++++++++++++++++ test/services/autobider_service_test.rb | 14 +++ 2 files changed, 149 insertions(+) diff --git a/test/models/offer_test.rb b/test/models/offer_test.rb index 148172bb7..360e82576 100644 --- a/test/models/offer_test.rb +++ b/test/models/offer_test.rb @@ -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 @@ -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 diff --git a/test/services/autobider_service_test.rb b/test/services/autobider_service_test.rb index c667d16ba..7ce77b412 100644 --- a/test/services/autobider_service_test.rb +++ b/test/services/autobider_service_test.rb @@ -300,4 +300,18 @@ def test_autobider_should_change_ends_at_if_bid_set_in_slipping_time AutobiderService.autobid(@english_auction) assert_equal @english_auction.ends_at, Time.zone.now + 5.minute end + + def test_slipping_time_should_be_change_when_autobider_is_created + Autobider.destroy_all + + @english_auction.update(ends_at: Time.zone.now + 3.minute) + @english_auction.reload + + assert_equal @english_auction.ends_at, Time.zone.now + 3.minute + assert_equal @english_auction.slipping_end, 5 + + Autobider.create(user: @user_two, domain_name: @english_auction.domain_name, cents: 99_999) + AutobiderService.autobid(@english_auction) + assert_equal @english_auction.ends_at, Time.zone.now + 5.minute + end end