Skip to content

Commit

Permalink
fixed issue with succesful results
Browse files Browse the repository at this point in the history
  • Loading branch information
olegphenomenon committed Oct 26, 2022
1 parent 37c6239 commit e3a8d9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions app/interactions/actions/email_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,24 @@ def calculate_check_level
end

def filtering_old_failed_records(result, contact)
if @check_level == "mx" && !result.success && contact.validation_events.count > 3
contact.validation_events.order!(created_at: :asc)
while contact.validation_events.count > 3
contact.validation_events.first.destroy
end
ValidationEvent::INVALID_EVENTS_COUNT_BY_LEVEL.each do |level, limit|
handle_failed_records(contact: contact, check_level: level, limit: limit, success: result.success)
end
end

if @check_level == "regex" && result.success && contact.validation_events.count > 1
def handle_failed_records(contact:, check_level:, limit:, success:)
if @check_level.to_sym == check_level && !success && contact.validation_events.count > limit
contact.validation_events.order!(created_at: :asc)
while contact.validation_events.count > 1
while contact.validation_events.count > limit
contact.validation_events.first.destroy
end
end
end

if @check_level == "smtp" && contact.validation_events.count > 1
contact.validation_events.order!(created_at: :asc)
while contact.validation_events.count > 1
contact.validation_events.first.destroy
end
end
def filtering_old_records(contact:, success:)
return unless success

contact.validation_events.destroy_all
end

def save_result(result)
Expand All @@ -62,6 +60,8 @@ def save_result(result)

contacts.find_in_batches(batch_size: 500) do |contact_batches|
contact_batches.each do |contact|
# methods should be in this order!
filtering_old_records(contact: contact, success: result.success)
contact.validation_events.create(validation_event_attrs(result))
filtering_old_failed_records(result, contact)
end
Expand Down
2 changes: 1 addition & 1 deletion test/interactions/email_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_should_remove_valid_validation_record_if_there_count_more_than_one
action.call
end

assert_equal @contact.validation_events.count, 3
assert_equal @contact.validation_events.count, 1
assert @contact.validation_events.last.success
end

Expand Down

0 comments on commit e3a8d9a

Please sign in to comment.