diff --git a/app/commands/user/bootstrap.rb b/app/commands/user/bootstrap.rb index f20d0b3aef..028673a14a 100644 --- a/app/commands/user/bootstrap.rb +++ b/app/commands/user/bootstrap.rb @@ -15,6 +15,7 @@ def call private def link_bootcamp_user! ubd = User::BootcampData.find_by(access_code: bootcamp_access_code) if bootcamp_access_code.present? + ubd ||= User::BootcampData.paid.find_by(email: user.email) ubd ||= User::BootcampData.find_by(email: user.email) return unless ubd diff --git a/test/commands/user/bootstrap_test.rb b/test/commands/user/bootstrap_test.rb index 67cf0f48c7..fbc6e16740 100644 --- a/test/commands/user/bootstrap_test.rb +++ b/test/commands/user/bootstrap_test.rb @@ -85,4 +85,19 @@ class User::BootstrapTest < ActiveSupport::TestCase refute user.reload.bootcamp_attendee? assert_equal user.id, ubd.reload.user_id end + + test "finds paid bootcamp data first" do + email = "something@someone.com" + create(:user_bootcamp_data, email:) + ubd = create :user_bootcamp_data, email:, paid_at: Time.current + create(:user_bootcamp_data, email:) + user = create(:user, email:) + + # Always does this once by default anyway + User::Bootcamp::SubscribeToOnboardingEmails.expects(:defer).with(ubd).twice + + User::Bootstrap.(user, bootcamp_access_code: ubd.access_code) + assert user.reload.bootcamp_attendee? + assert_equal user.id, ubd.reload.user_id + end end