~singpolyma/sgx-jmp

cd02cc3017563f25ec51b37c1889ec179fc6f2a2 — Stephen Paul Weber 1 year, 2 months ago c7c4866
Remove LegacyCustomer

Such customers are not longer a common or valid case.
8 files changed, 2 insertions(+), 151 deletions(-)

D forms/legacy_customer_admin_info.rb
D forms/legacy_customer_info.rb
D forms/legacy_customer_info_partial.rb
M lib/customer_info_form.rb
M lib/customer_repo.rb
D lib/legacy_customer.rb
M test/test_customer_info.rb
M test/test_customer_repo.rb
D forms/legacy_customer_admin_info.rb => forms/legacy_customer_admin_info.rb +0 -29
@@ 1,29 0,0 @@
result!
title "Customer Info"

render "legacy_customer_info_partial", info: @admin_info.info

field(
	var: "jid",
	label: "JID",
	value: @admin_info.jid.unproxied.to_s
)

field(
	var: "cheo_jid",
	label: "Cheo JID",
	value: @admin_info.jid.to_s
)

field(
	var: "api",
	label: "API",
	value: @admin_info.api.to_s
)

field(
	var: "link",
	label: "Link",
	type: "jid-single",
	value: "#{@admin_info.info.tel}@#{CONFIG[:upstream_domain]}"
)

D forms/legacy_customer_info.rb => forms/legacy_customer_info.rb +0 -4
@@ 1,4 0,0 @@
result!
title "Account Info"

render "legacy_customer_info_partial"

D forms/legacy_customer_info_partial.rb => forms/legacy_customer_info_partial.rb +0 -11
@@ 1,11 0,0 @@
field(
	var: "account_status",
	label: "Account Status",
	value: "Legacy"
)

field(
	var: "tel",
	label: "Phone Number",
	value: @info.tel
)

M lib/customer_info_form.rb => lib/customer_info_form.rb +0 -1
@@ 3,7 3,6 @@
require_relative "bwmsgsv2_repo"
require_relative "customer_repo"
require_relative "proxied_jid"
require_relative "legacy_customer"

class CustomerInfoForm
	def initialize(customer_repo=CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new))

M lib/customer_repo.rb => lib/customer_repo.rb +1 -10
@@ 3,7 3,6 @@
require "lazy_object"

require_relative "customer"
require_relative "legacy_customer"
require_relative "polyfill"

class CustomerRepo


@@ 34,7 33,7 @@ class CustomerRepo
			find($1)
		else
			@redis.get("jmp_customer_id-#{jid}").then do |customer_id|
				next find_legacy_customer(jid) unless customer_id
				raise "No customer" unless customer_id

				find_inner(customer_id, jid)
			end


@@ 94,14 93,6 @@ protected
		TrivialBackendSgxRepo.new.get(customer_id).with(registered?: false)
	end

	def find_legacy_customer(jid)
		@redis.lindex("catapult_cred-#{jid}", 3).then do |tel|
			raise NotFound, "No customer" unless tel

			LegacyCustomer.new(Blather::JID.new(jid), tel)
		end
	end

	def hydrate_plan(customer_id, raw_customer)
		raw_customer.dup.tap do |data|
			data[:plan] = CustomerPlan.new(

D lib/legacy_customer.rb => lib/legacy_customer.rb +0 -58
@@ 1,58 0,0 @@
# frozen_string_literal: true

require "value_semantics/monkey_patched"
require_relative "proxied_jid"

class LegacyCustomer
	attr_reader :jid, :tel

	def initialize(jid, tel)
		@jid = jid
		@tel = tel
	end

	def customer_id
		nil
	end

	def info
		EMPromise.resolve(nil).then do
			Info.new(tel: tel)
		end
	end

	def admin_info
		EMPromise.all([
			info,
			api
		]).then do |info, api|
			AdminInfo.new(info: info, jid: jid, api: api)
		end
	end

	def api
		API.for(self)
	end

	class Info
		value_semantics do
			tel String
		end

		def form
			FormTemplate.render("legacy_customer_info", info: self)
		end
	end

	class AdminInfo
		value_semantics do
			info Info
			jid ProxiedJID, coerce: ProxiedJID.method(:new)
			api API
		end

		def form
			FormTemplate.render("legacy_customer_admin_info", admin_info: self)
		end
	end
end

M test/test_customer_info.rb => test/test_customer_info.rb +0 -18
@@ 100,24 100,6 @@ class CustomerInfoTest < Minitest::Test
	end
	em :test_inactive_admin_info_does_not_crash

	def test_legacy_customer_info_does_not_crash
		cust = LegacyCustomer.new(
			Blather::JID.new("legacy@example.com"),
			"+12223334444"
		)
		assert cust.info.sync.form
	end
	em :test_legacy_customer_info_does_not_crash

	def test_legacy_customer_admin_info_does_not_crash
		cust = LegacyCustomer.new(
			Blather::JID.new("legacy@example.com"),
			"+12223334444"
		)
		assert cust.admin_info.sync.form
	end
	em :test_legacy_customer_admin_info_does_not_crash

	def test_missing_customer_admin_info_does_not_crash
		cust = CustomerInfoForm::NoCustomer.new
		assert cust.admin_info.form

M test/test_customer_repo.rb => test/test_customer_repo.rb +1 -20
@@ 29,12 29,7 @@ class CustomerRepoTest < Minitest::Test
		"catapult_jid-+14445556666" => "test_v2@example.com",
		"catapult_cred-test_v2@example.com" => [
			"test_bw_customer", "", "", "+14445556666"
		],
		# legacy customer
		"catapult_cred-legacy@example.com" => [
			"catapult_user", "", "", "+12223334444"
		],
		"catapult_jid-+12223334444" => "legacy@example.com"
		]
	)

	FAKE_DB = FakeDB.new(


@@ 99,13 94,6 @@ class CustomerRepoTest < Minitest::Test
	end
	em :test_find_by_jid_not_found

	def test_find_legacy_customer
		customer = @repo.find_by_jid("legacy@example.com").sync
		assert_kind_of LegacyCustomer, customer
		assert_equal "+12223334444", customer.tel
	end
	em :test_find_legacy_customer

	def test_find_sgx_customer_by_phone
		customer = @repo.find_by_tel("+13334445555").sync
		assert_kind_of Customer, customer


@@ 120,13 108,6 @@ class CustomerRepoTest < Minitest::Test
	end
	em :test_find_v2_customer_by_phone

	def test_find_legacy_customer_by_phone
		customer = @repo.find_by_tel("+12223334444").sync
		assert_kind_of LegacyCustomer, customer
		assert_equal "legacy@example.com", customer.jid.to_s
	end
	em :test_find_legacy_customer_by_phone

	def test_find_missing_phone
		assert_raises do
			@repo.find_by_tel("+15556667777").sync