refactor registration_test to use real Tn's

Phillip Davis created

Change summary

test/test_registration.rb | 81 +++++++++++++++++++++++-----------------
1 file changed, 47 insertions(+), 34 deletions(-)

Detailed changes

test/test_registration.rb 🔗

@@ -155,7 +155,8 @@ class RegistrationTest < Minitest::Test
 
 		def setup
 			@customer = Minitest::Mock.new(customer)
-			@activation = Registration::Activation.new(@customer, "+15555550000")
+			@tel = TelSelections::ChooseTel::Tn.for_pending_value("+15555550000")
+			@activation = Registration::Activation.new(@customer, @tel)
 		end
 
 		def test_write
@@ -167,7 +168,7 @@ class RegistrationTest < Minitest::Test
 				[Matching.new do |iq|
 					assert_equal :form, iq.form.type
 					assert_equal(
-						"You've selected +15555550000 as your JMP number.",
+						"You've selected (555) 555-0000 as your JMP number.",
 						iq.form.instructions.lines.first.chomp
 					)
 				end]
@@ -179,7 +180,7 @@ class RegistrationTest < Minitest::Test
 			Registration::Activation::Payment.expect(
 				:for,
 				EMPromise.reject(:test_result),
-				[Blather::Stanza::Iq, @customer, "+15555550000"]
+				[Blather::Stanza::Iq, @customer, @tel]
 			)
 			assert_equal(
 				:test_result,
@@ -200,7 +201,7 @@ class RegistrationTest < Minitest::Test
 				[Matching.new do |iq|
 					assert_equal :form, iq.form.type
 					assert_equal(
-						"You've selected +15555550000 as your JMP number.",
+						"You've selected (555) 555-0000 as your JMP number.",
 						iq.form.instructions.lines.first.chomp
 					)
 				end]
@@ -216,7 +217,7 @@ class RegistrationTest < Minitest::Test
 			Registration::Activation::Payment.expect(
 				:for,
 				EMPromise.reject(:test_result),
-				[Blather::Stanza::Iq, @customer, "+15555550000"]
+				[Blather::Stanza::Iq, @customer, @tel]
 			)
 			assert_equal(
 				:test_result,
@@ -237,7 +238,7 @@ class RegistrationTest < Minitest::Test
 				[Matching.new do |iq|
 					assert_equal :form, iq.form.type
 					assert_equal(
-						"You've selected +15555550000 as your JMP number.",
+						"You've selected (555) 555-0000 as your JMP number.",
 						iq.form.instructions.lines.first.chomp
 					)
 				end]
@@ -263,7 +264,7 @@ class RegistrationTest < Minitest::Test
 				[Matching.new do |iq|
 					assert_equal :form, iq.form.type
 					assert_equal(
-						"You've selected +15555550000 as your JMP number.",
+						"You've selected (555) 555-0000 as your JMP number.",
 						iq.form.instructions.lines.first.chomp
 					)
 				end]
@@ -282,7 +283,7 @@ class RegistrationTest < Minitest::Test
 			Registration::Activation::Finish.expect(
 				:new,
 				OpenStruct.new(write: EMPromise.reject(:test_result)),
-				[@customer, "+15555550000"]
+				[@customer, @tel]
 			)
 			assert_equal(
 				:test_result,
@@ -307,7 +308,7 @@ class RegistrationTest < Minitest::Test
 				[Matching.new do |iq|
 					assert_equal :form, iq.form.type
 					assert_equal(
-						"You've selected +15555550000 as your JMP number.",
+						"You've selected (555) 555-0000 as your JMP number.",
 						iq.form.instructions.lines.first.chomp
 					)
 				end]
@@ -325,7 +326,7 @@ class RegistrationTest < Minitest::Test
 			Registration::Activation::Payment.expect(
 				:for,
 				EMPromise.reject(:test_result),
-				[Blather::Stanza::Iq, @customer, "+15555550000"]
+				[Blather::Stanza::Iq, @customer, @tel]
 			)
 			assert_equal(
 				:test_result,
@@ -357,7 +358,7 @@ class RegistrationTest < Minitest::Test
 					[Matching.new do |iq|
 						assert_equal :form, iq.form.type
 						assert_equal(
-							"You've selected +15555550000 as your JMP number.",
+							"You've selected (555) 555-0000 as your JMP number.",
 							iq.form.instructions.lines.first.chomp
 						)
 					end]
@@ -384,7 +385,7 @@ class RegistrationTest < Minitest::Test
 					:new,
 					EMPromise.reject(:test_result)
 				) do |*args, **|
-					assert_equal "+15555550000", args[1]
+					assert_equal @tel, args[1]
 				end
 				assert_equal(
 					:test_result,
@@ -411,7 +412,7 @@ class RegistrationTest < Minitest::Test
 				[Matching.new do |iq|
 					assert_equal :form, iq.form.type
 					assert_equal(
-						"You've selected +15555550000 as your JMP number.",
+						"You've selected (555) 555-0000 as your JMP number.",
 						iq.form.instructions.lines.first.chomp
 					)
 				end]
@@ -452,7 +453,7 @@ class RegistrationTest < Minitest::Test
 				[Matching.new do |iq|
 					assert_equal :form, iq.form.type
 					assert_equal(
-						"You've selected +15555550000 as your JMP number.",
+						"You've selected (555) 555-0000 as your JMP number.",
 						iq.form.instructions.lines.first.chomp
 					)
 				end]
@@ -486,7 +487,7 @@ class RegistrationTest < Minitest::Test
 				[Matching.new do |iq|
 					assert_equal :form, iq.form.type
 					assert_equal(
-						"You've selected +15555550000 as your JMP number.",
+						"You've selected (555) 555-0000 as your JMP number.",
 						iq.form.instructions.lines.first.chomp
 					)
 				end]
@@ -514,8 +515,9 @@ class RegistrationTest < Minitest::Test
 		Registration::Activation::Allow::DB = Minitest::Mock.new
 
 		def test_write_credit_to_nil
+			tel = TelSelections::ChooseTel::Tn.for_pending_value("+15555550000")
 			cust = Minitest::Mock.new(customer("test"))
-			allow = Registration::Activation::Allow.new(cust, "+15555550000", nil)
+			allow = Registration::Activation::Allow.new(cust, tel, nil)
 
 			Command::COMMAND_MANAGER.expect(
 				:write,
@@ -525,7 +527,7 @@ class RegistrationTest < Minitest::Test
 				[Matching.new do |iq|
 					assert_equal :form, iq.form.type
 					assert_equal(
-						"You've selected +15555550000 as your JMP number.",
+						"You've selected (555) 555-0000 as your JMP number.",
 						iq.form.instructions.lines.first.chomp
 					)
 					assert_equal 1, iq.form.fields.length
@@ -550,8 +552,9 @@ class RegistrationTest < Minitest::Test
 
 		def test_write_credit_to_refercust
 			cust = Minitest::Mock.new(customer("test"))
+			tel = TelSelections::ChooseTel::Tn.for_pending_value("+15555550000")
 			allow = Registration::Activation::Allow.new(
-				cust, "+15555550000", "refercust"
+				cust, tel, "refercust"
 			)
 
 			Command::COMMAND_MANAGER.expect(
@@ -562,7 +565,7 @@ class RegistrationTest < Minitest::Test
 				[Matching.new do |iq|
 					assert_equal :form, iq.form.type
 					assert_equal(
-						"You've selected +15555550000 as your JMP number.",
+						"You've selected (555) 555-0000 as your JMP number.",
 						iq.form.instructions.lines.first.chomp
 					)
 					assert_equal 1, iq.form.fields.length
@@ -597,10 +600,11 @@ class RegistrationTest < Minitest::Test
 
 		def setup
 			@customer = customer
+			@tel = TelSelections::ChooseTel::Tn.for_pending_value("+15555550000")
 			@google_play = Registration::Activation::GooglePlay.new(
 				@customer,
 				"abcd",
-				"+15555550000"
+				@tel
 			)
 		end
 
@@ -613,7 +617,7 @@ class RegistrationTest < Minitest::Test
 				[Matching.new do |iq|
 					assert_equal :form, iq.form.type
 					assert_equal(
-						"You've selected +15555550000 as your JMP number.",
+						"You've selected (555) 555-0000 as your JMP number.",
 						iq.form.instructions.lines.first.chomp
 					)
 				end]
@@ -632,7 +636,7 @@ class RegistrationTest < Minitest::Test
 			Registration::Activation::GooglePlay::Finish.expect(
 				:new,
 				OpenStruct.new(write: EMPromise.reject(:test_result)),
-				[Customer, "+15555550000"]
+				[Customer, @tel]
 			)
 			result = execute_command { @google_play.write.catch { |e| e } }
 			assert_equal :test_result, result
@@ -648,22 +652,24 @@ class RegistrationTest < Minitest::Test
 		CustomerFinancials::BRAINTREE = Minitest::Mock.new
 
 		def test_for_bitcoin
+			tel = TelSelections::ChooseTel::Tn.for_pending_value("+15555550000")
 			iq = Blather::Stanza::Iq::Command.new
 			iq.form.fields = [
 				{ var: "activation_method", value: "bitcoin" },
 				{ var: "plan_name", value: "test_usd" }
 			]
-			result = Registration::Payment.for(iq, customer, "+15555550000")
+			result = Registration::Payment.for(iq, customer, tel)
 			assert_kind_of Registration::Payment::Bitcoin, result
 		end
 
 		def test_for_bch
+			tel = TelSelections::ChooseTel::Tn.for_pending_value("+15555550000")
 			iq = Blather::Stanza::Iq::Command.new
 			iq.form.fields = [
 				{ var: "activation_method", value: "bch" },
 				{ var: "plan_name", value: "test_usd" }
 			]
-			result = Registration::Payment.for(iq, customer, "+15555550000")
+			result = Registration::Payment.for(iq, customer, tel)
 			assert_kind_of Registration::Payment::BCH, result
 		end
 
@@ -699,7 +705,7 @@ class RegistrationTest < Minitest::Test
 				Registration::Payment.for(
 					iq,
 					cust,
-					"+15555550000"
+					TelSelections::ChooseTel::Tn.for_pending_value("+15555550000")
 				)
 			end
 			assert_kind_of Registration::Payment::InviteCode, result
@@ -718,9 +724,10 @@ class RegistrationTest < Minitest::Test
 					:add_btc_address,
 					EMPromise.resolve("testaddr")
 				)
+				@tel = TelSelections::ChooseTel::Tn.for_pending_value("+15555550000")
 				@bitcoin = Registration::Payment::Bitcoin.new(
 					@customer,
-					"+15555550000"
+					@tel
 				)
 			end
 
@@ -767,9 +774,10 @@ class RegistrationTest < Minitest::Test
 					:add_bch_address,
 					EMPromise.resolve("testaddr")
 				)
+				@tel = TelSelections::ChooseTel::Tn.for_pending_value("+15555550000")
 				@bch = Registration::Payment::BCH.new(
 					@customer,
-					"+15555550000"
+					@tel
 				)
 			end
 
@@ -806,9 +814,10 @@ class RegistrationTest < Minitest::Test
 
 		class CreditCardTest < Minitest::Test
 			def setup
+				@tel = TelSelections::ChooseTel::Tn.for_pending_value("+15555550000")
 				@credit_card = Registration::Payment::CreditCard.new(
 					customer,
-					"+15555550000"
+					@tel
 				)
 			end
 
@@ -922,6 +931,10 @@ class RegistrationTest < Minitest::Test
 			Registration::Payment::MaybeBill::BillPlan =
 				Minitest::Mock.new
 
+			def setup
+				@tel = TelSelections::ChooseTel::Tn.for_pending_value("+15555550000")
+			end
+
 			def test_write
 				customer = customer(plan_name: "test_usd")
 				Registration::Payment::InviteCode::DB.expect(:transaction, true, [])
@@ -930,7 +943,7 @@ class RegistrationTest < Minitest::Test
 					OpenStruct.new(write: nil),
 					[
 						customer,
-						"+15555550000"
+						@tel
 					]
 				)
 				execute_command do
@@ -959,7 +972,7 @@ class RegistrationTest < Minitest::Test
 
 					Registration::Payment::InviteCode.new(
 						customer,
-						"+15555550000"
+						@tel
 					).write
 				end
 				assert_mock Command::COMMAND_MANAGER
@@ -1022,7 +1035,7 @@ class RegistrationTest < Minitest::Test
 
 					Registration::Payment::InviteCode.new(
 						customer,
-						"+15555550000"
+						@tel
 					).write
 				end
 				assert_mock Command::COMMAND_MANAGER
@@ -1100,7 +1113,7 @@ class RegistrationTest < Minitest::Test
 
 					Registration::Payment::InviteCode.new(
 						customer,
-						"+15555550000"
+						@tel
 					).write.catch { |e| e }
 				end
 				assert_equal :test_result, result
@@ -1178,7 +1191,7 @@ class RegistrationTest < Minitest::Test
 
 					Registration::Payment::InviteCode.new(
 						customer,
-						"+15555550000"
+						@tel
 					).write.catch { |e| e }
 				end
 				assert_equal :test_result, result
@@ -1223,7 +1236,7 @@ class RegistrationTest < Minitest::Test
 					)
 					Registration::Payment::InviteCode.new(
 						customer,
-						"+15555550000"
+						@tel
 					).write.catch { |e| e }
 				end
 				assert_equal :test_result, result