Allow blank referral code for google play signup

Stephen Paul Weber created

Change summary

lib/registration.rb       |  6 +++-
test/test_helper.rb       |  4 +++
test/test_registration.rb | 51 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 2 deletions(-)

Detailed changes

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

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)

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