~singpolyma/sgx-jmp

5a1e3cb26c27cae749b6a9de579aa254ec2ee9c8 — Stephen Paul Weber 8 months ago 36dbdd7
s/WebRegisterManager/TelSelections
5 files changed, 15 insertions(+), 15 deletions(-)

M lib/registration.rb
R lib/{web_register_manager.rb => tel_selections.rb}
M sgx_jmp.rb
M test/test_registration.rb
R test/{test_web_register_manager.rb => test_tel_selections.rb}
M lib/registration.rb => lib/registration.rb +3 -3
@@ 9,15 9,15 @@ require_relative "./command"
require_relative "./bandwidth_tn_order"
require_relative "./em"
require_relative "./oob"
require_relative "./web_register_manager"
require_relative "./tel_selections"

class Registration
	def self.for(customer, web_register_manager)
	def self.for(customer, tel_selections)
		customer.registered?.then do |registered|
			if registered
				Registered.new(registered.phone)
			else
				web_register_manager[customer.jid].then(&:choose_tel).then do |tel|
				tel_selections[customer.jid].then(&:choose_tel).then do |tel|
					Activation.for(customer, tel)
				end
			end

R lib/web_register_manager.rb => lib/tel_selections.rb +1 -1
@@ 1,6 1,6 @@
# frozen_string_literal: true

class WebRegisterManager
class TelSelections
	THIRTY_DAYS = 60 * 60 * 24 * 30

	def initialize(redis: REDIS)

M sgx_jmp.rb => sgx_jmp.rb +4 -4
@@ 77,7 77,7 @@ require_relative "lib/low_balance"
require_relative "lib/payment_methods"
require_relative "lib/registration"
require_relative "lib/transaction"
require_relative "lib/web_register_manager"
require_relative "lib/tel_selections"
require_relative "lib/session_manager"
require_relative "lib/statsd"



@@ 169,7 169,7 @@ when_ready do
	LOG.info "Ready"
	BLATHER = self
	REDIS = EM::Hiredis.connect
	WEB_REGISTER_MANAGER = WebRegisterManager.new
	TEL_SELECTIONS = TelSelections.new
	BTC_SELL_PRICES = BTCSellPrices.new(REDIS, CONFIG[:oxr_app_id])
	DB = PG::EM::ConnectionPool.new(dbname: "jmp") do |conn|
		conn.type_map_for_results = PG::BasicTypeMapForResults.new(conn)


@@ 392,7 392,7 @@ Command.new(
		Command.execution.customer_repo.create(Command.execution.iq.from.stripped)
	}.then { |customer|
		Sentry.add_breadcrumb(Sentry::Breadcrumb.new(message: "Registration.for"))
		Registration.for(customer, WEB_REGISTER_MANAGER).then(&:write)
		Registration.for(customer, TEL_SELECTIONS).then(&:write)
	}.then {
		StatsD.increment("registration.completed")
	}.catch_only(Command::Execution::FinalStanza) do |e|


@@ 547,7 547,7 @@ command :execute?, node: "web-register", sessionid: nil do |iq|
				cmd.form.fields = [var: "to", value: jid]
				cmd.form.type = "submit"
			}).then { |result|
				WEB_REGISTER_MANAGER.set(result.form.field("from")&.value.to_s.strip, tel)
				TEL_SELECTIONS.set(result.form.field("from")&.value.to_s.strip, tel)
			}.then {
				BLATHER << iq.reply.tap { |reply| reply.status = :completed }
			}.catch { |e| panic(e, sentry_hub) }

M test/test_registration.rb => test/test_registration.rb +2 -2
@@ 35,7 35,7 @@ class RegistrationTest < Minitest::Test
	em :test_for_registered

	def test_for_activated
		web_manager = WebRegisterManager.new(redis: FakeRedis.new)
		web_manager = TelSelections.new(redis: FakeRedis.new)
		web_manager.set("test@example.net", "+15555550000")
		result = execute_command do
			sgx = OpenStruct.new(registered?: EMPromise.resolve(nil))


@@ 54,7 54,7 @@ class RegistrationTest < Minitest::Test

	def test_for_not_activated_with_customer_id
		sgx = OpenStruct.new(registered?: EMPromise.resolve(nil))
		web_manager = WebRegisterManager.new(redis: FakeRedis.new)
		web_manager = TelSelections.new(redis: FakeRedis.new)
		web_manager.set("test@example.net", "+15555550000")
		iq = Blather::Stanza::Iq::Command.new
		iq.from = "test@example.com"

R test/test_web_register_manager.rb => test/test_tel_selections.rb +5 -5
@@ 1,17 1,17 @@
# frozen_string_literal: true

require "test_helper"
require "web_register_manager"
require "tel_selections"

class WebRegisterManagerTest < Minitest::Test
class TelSelectionsTest < Minitest::Test
	def setup
		@manager = WebRegisterManager.new(redis: FakeRedis.new)
		@manager = TelSelections.new(redis: FakeRedis.new)
	end

	def test_set_get
		assert_kind_of WebRegisterManager::ChooseTel, @manager["jid@example.com"].sync
		assert_kind_of TelSelections::ChooseTel, @manager["jid@example.com"].sync
		@manager.set("jid@example.com", "+15555550000").sync
		assert_kind_of WebRegisterManager::HaveTel, @manager["jid@example.com"].sync
		assert_kind_of TelSelections::HaveTel, @manager["jid@example.com"].sync
	end
	em :test_set_get