Already activated user goes straight to finish

Stephen Paul Weber created

If not registered, but activated, they must have paid but failed to get their
number setup. Maybe the number was already taken. Maybe they paid manually. In
any case we can skip all intervening steps and go straight to buying and
configuring their number for them.

Change summary

lib/registration.rb       | 14 ++++++++------
test/test_registration.rb | 16 ++++++++++++++--
2 files changed, 22 insertions(+), 8 deletions(-)

Detailed changes

lib/registration.rb 🔗

@@ -4,8 +4,6 @@ require_relative "./oob"
 
 class Registration
 	def self.for(iq, customer, web_register_manager)
-		raise "TODO" if customer&.active?
-
 		EMPromise.resolve(customer&.registered?).then do |registered|
 			if registered
 				Registered.new(iq, registered.phone)
@@ -36,10 +34,14 @@ class Registration
 
 	class Activation
 		def self.for(iq, customer, tel)
-			return EMPromise.resolve(new(iq, customer, tel)) if customer
-
-			# Create customer_id
-			raise "TODO"
+			if customer&.active?
+				Finish.new(iq, customer, tel)
+			elsif customer
+				EMPromise.resolve(new(iq, customer, tel))
+			else
+				# Create customer_id
+				raise "TODO"
+			end
 		end
 
 		def initialize(iq, customer, tel)

test/test_registration.rb 🔗

@@ -5,9 +5,21 @@ require "registration"
 
 class RegistrationTest < Minitest::Test
 	def test_for_activated
-		skip "Registration#for activated not implemented yet"
+		BACKEND_SGX.expect(
+			:registered?,
+			EMPromise.resolve(nil),
+			["test"]
+		)
+		web_manager = WebRegisterManager.new
+		web_manager["test@example.com"] = "+15555550000"
 		iq = Blather::Stanza::Iq::Command.new
-		Registration.for(iq, Customer.new("test"), Minitest::Mock.new).sync
+		iq.from = "test@example.com"
+		result = Registration.for(
+			iq,
+			Customer.new("test", plan_name: "test_usd", expires_at: Time.now + 999),
+			web_manager
+		).sync
+		assert_kind_of Registration::Finish, result
 	end
 	em :test_for_activated