~singpolyma/sgx-jmp

94010866e345f4e1f6f36ff3c9a6385164e1af0f — Stephen Paul Weber 1 year, 8 months ago c69a621 + f4ece3c
Merge branch 'activated-users-to-finish'

* activated-users-to-finish:
  Test that registered users get the Registered step
  Already activated user goes straight to finish
2 files changed, 35 insertions(+), 8 deletions(-)

M lib/registration.rb
M test/test_registration.rb
M lib/registration.rb => lib/registration.rb +8 -6
@@ 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)

M test/test_registration.rb => test/test_registration.rb +27 -2
@@ 4,10 4,35 @@ require "test_helper"
require "registration"

class RegistrationTest < Minitest::Test
	def test_for_registered
		BACKEND_SGX.expect(
			:registered?,
			EMPromise.resolve(OpenStruct.new(phone: "+15555550000")),
			["test"]
		)
		iq = Blather::Stanza::Iq::Command.new
		iq.from = "test@example.com"
		result = Registration.for(iq, Customer.new("test"), Minitest::Mock.new).sync
		assert_kind_of Registration::Registered, result
	end
	em :test_for_registered

	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