diff --git a/lib/registration.rb b/lib/registration.rb index 78f28d10bf824cc37f343ce8283a321568d3bce8..0430606c830dac848a79ca4d79f10921872542fb 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -175,8 +175,10 @@ class Registration protected def use_referral_code(code) - @invites.claim_code(@customer.customer_id, code) { - @customer.extend_plan + EMPromise.resolve(nil).then { + @invites.claim_code(@customer.customer_id, code) { + @customer.extend_plan + } }.catch_only(InvitesRepo::Invalid) do @invites.stash_code(customer.customer_id, code) end diff --git a/test/test_helper.rb b/test/test_helper.rb index ad22083f42ae02adf2803a4854162579272ea215..6978753ce6f61ab9a9cb3b87106207ef632cf146 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -280,6 +280,10 @@ class FakeRedis @values[key]&.to_a || [] end + def sismember(key, value) + smembers(key).include?(value) + end + def expire(_, _); end def exists(*keys) diff --git a/test/test_registration.rb b/test/test_registration.rb index 29323813da1c9907959c7590f5f24fe5d304281b..c694d6911357ebc1f7ef3c6a6f3b55150161a8bc 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -317,6 +317,57 @@ class RegistrationTest < Minitest::Test em :test_write_credit_to_refercust end + class GooglePlayTest < Minitest::Test + CustomerPlan::DB = Minitest::Mock.new + Registration::Activation::GooglePlay::Finish = Minitest::Mock.new + + def setup + @customer = customer + @google_play = Registration::Activation::GooglePlay.new( + @customer, + "abcd", + "+15555550000" + ) + end + + def test_write + Command::COMMAND_MANAGER.expect( + :write, + EMPromise.resolve(Blather::Stanza::Iq::Command.new.tap { |iq| + iq.form.fields = [{ var: "plan_name", value: "test_usd" }] + }), + [Matching.new do |iq| + assert_equal :form, iq.form.type + assert_equal( + "You've selected +15555550000 as your JMP number.", + iq.form.instructions.lines.first.chomp + ) + end] + ) + CustomerPlan::DB.expect( + :exec, + OpenStruct.new(cmd_tuples: 1), + [String, ["test", "test_usd", nil]] + ) + CustomerPlan::DB.expect( + :exec, + OpenStruct.new(cmd_tuples: 0), + [String, ["test"]] + ) + Registration::Activation::GooglePlay::Finish.expect( + :new, + OpenStruct.new(write: EMPromise.reject(:test_result)), + [Customer, "+15555550000"] + ) + result = execute_command { @google_play.write.catch { |e| e } } + assert_equal :test_result, result + assert_mock Command::COMMAND_MANAGER + assert_mock CustomerPlan::DB + assert_mock Registration::Activation::GooglePlay::Finish + end + em :test_write + end + class PaymentTest < Minitest::Test CustomerFinancials::BRAINTREE = Minitest::Mock.new