test_registration.rb

  1# frozen_string_literal: true
  2
  3require "test_helper"
  4require "customer"
  5require "registration"
  6
  7class RegistrationTest < Minitest::Test
  8	def test_for_registered
  9		sgx = OpenStruct.new(
 10			registered?: OpenStruct.new(phone: "+15555550000")
 11		)
 12		iq = Blather::Stanza::Iq::Command.new
 13		iq.from = "test@example.com"
 14		result = execute_command(iq) do
 15			Registration.for(
 16				customer(sgx: sgx),
 17				Minitest::Mock.new
 18			)
 19		end
 20		assert_kind_of Registration::Registered, result
 21	end
 22	em :test_for_registered
 23
 24	def test_for_activated
 25		web_manager = TelSelections.new(redis: FakeRedis.new)
 26		web_manager.set("test@example.net", "+15555550000")
 27		result = execute_command do
 28			sgx = OpenStruct.new(registered?: false)
 29			Registration.for(
 30				customer(
 31					plan_name: "test_usd",
 32					expires_at: Time.now + 999,
 33					sgx: sgx
 34				),
 35				web_manager
 36			)
 37		end
 38		assert_kind_of Registration::Finish, result
 39	end
 40	em :test_for_activated
 41
 42	def test_for_not_activated_approved
 43		sgx = OpenStruct.new(registered?: false)
 44		web_manager = TelSelections.new(redis: FakeRedis.new)
 45		web_manager.set("test\\40approved.example.com@component", "+15555550000")
 46		iq = Blather::Stanza::Iq::Command.new
 47		iq.from = "test@approved.example.com"
 48		result = execute_command(iq) do
 49			Registration.for(
 50				customer(
 51					sgx: sgx,
 52					jid: Blather::JID.new("test\\40approved.example.com@component")
 53				),
 54				web_manager
 55			)
 56		end
 57		assert_kind_of Registration::Activation::Allow, result
 58	end
 59	em :test_for_not_activated_approved
 60
 61	def test_for_not_activated_with_customer_id
 62		sgx = OpenStruct.new(registered?: false)
 63		web_manager = TelSelections.new(redis: FakeRedis.new)
 64		web_manager.set("test@example.net", "+15555550000")
 65		iq = Blather::Stanza::Iq::Command.new
 66		iq.from = "test@example.com"
 67		result = execute_command(iq) do
 68			Registration.for(
 69				customer(sgx: sgx),
 70				web_manager
 71			)
 72		end
 73		assert_kind_of Registration::Activation, result
 74	end
 75	em :test_for_not_activated_with_customer_id
 76
 77	class ActivationTest < Minitest::Test
 78		Command::COMMAND_MANAGER = Minitest::Mock.new
 79		def setup
 80			@activation = Registration::Activation.new("test", "+15555550000")
 81		end
 82
 83		def test_write
 84			stub_request(
 85				:get,
 86				"https://dashboard.bandwidth.com/v1.0/tns/+15555550000"
 87			).to_return(status: 201, body: <<~RESPONSE)
 88				<TelephoneNumberResponse>
 89					<TelephoneNumber>5555550000</TelephoneNumber>
 90				</TelephoneNumberResponse>
 91			RESPONSE
 92			stub_request(
 93				:get,
 94				"https://dashboard.bandwidth.com/v1.0/tns/5555550000/ratecenter"
 95			).to_return(status: 201, body: <<~RESPONSE)
 96				<TelephoneNumberResponse>
 97					<TelephoneNumberDetails>
 98						<State>KE</State>
 99						<RateCenter>FA</RateCenter>
100					</TelephoneNumberDetails>
101				</TelephoneNumberResponse>
102			RESPONSE
103			Command::COMMAND_MANAGER.expect(
104				:write,
105				EMPromise.reject(:test_result),
106				[Matching.new do |iq|
107					assert_equal :form, iq.form.type
108					assert_equal(
109						"You've selected +15555550000 (FA, KE) as your JMP number.",
110						iq.form.instructions.lines.first.chomp
111					)
112				end]
113			)
114			assert_equal(
115				:test_result,
116				execute_command { @activation.write.catch { |e| e } }
117			)
118			assert_mock Command::COMMAND_MANAGER
119		end
120		em :test_write
121	end
122
123	class AllowTest < Minitest::Test
124		Command::COMMAND_MANAGER = Minitest::Mock.new
125		Registration::Activation::Allow::DB = Minitest::Mock.new
126
127		def test_write_credit_to_nil
128			cust = Minitest::Mock.new(customer("test"))
129			allow = Registration::Activation::Allow.new(cust, "+15555550000", nil)
130
131			stub_request(
132				:get,
133				"https://dashboard.bandwidth.com/v1.0/tns/+15555550000"
134			).to_return(status: 201, body: <<~RESPONSE)
135				<TelephoneNumberResponse>
136					<TelephoneNumber>5555550000</TelephoneNumber>
137				</TelephoneNumberResponse>
138			RESPONSE
139			stub_request(
140				:get,
141				"https://dashboard.bandwidth.com/v1.0/tns/5555550000/ratecenter"
142			).to_return(status: 201, body: <<~RESPONSE)
143				<TelephoneNumberResponse>
144					<TelephoneNumberDetails>
145						<State>KE</State>
146						<RateCenter>FA</RateCenter>
147					</TelephoneNumberDetails>
148				</TelephoneNumberResponse>
149			RESPONSE
150			Command::COMMAND_MANAGER.expect(
151				:write,
152				EMPromise.resolve(Blather::Stanza::Iq::Command.new.tap { |iq|
153					iq.form.fields = [{ var: "plan_name", value: "test_usd" }]
154				}),
155				[Matching.new do |iq|
156					assert_equal :form, iq.form.type
157					assert_equal(
158						"You've selected +15555550000 (FA, KE) as your JMP number.",
159						iq.form.instructions.lines.first.chomp
160					)
161					assert_equal 1, iq.form.fields.length
162				end]
163			)
164			Registration::Activation::Allow::DB.expect(
165				:transaction,
166				EMPromise.reject(:test_result)
167			) do |&blk|
168				blk.call
169				true
170			end
171			cust.expect(:with_plan, cust, ["test_usd"])
172			cust.expect(:activate_plan_starting_now, nil)
173			assert_equal(
174				:test_result,
175				execute_command { allow.write.catch { |e| e } }
176			)
177			assert_mock Command::COMMAND_MANAGER
178		end
179		em :test_write_credit_to_nil
180
181		def test_write_credit_to_refercust
182			cust = Minitest::Mock.new(customer("test"))
183			allow = Registration::Activation::Allow.new(
184				cust, "+15555550000", "refercust"
185			)
186
187			stub_request(
188				:get,
189				"https://dashboard.bandwidth.com/v1.0/tns/+15555550000"
190			).to_return(status: 201, body: <<~RESPONSE)
191				<TelephoneNumberResponse>
192					<TelephoneNumber>5555550000</TelephoneNumber>
193				</TelephoneNumberResponse>
194			RESPONSE
195			stub_request(
196				:get,
197				"https://dashboard.bandwidth.com/v1.0/tns/5555550000/ratecenter"
198			).to_return(status: 201, body: <<~RESPONSE)
199				<TelephoneNumberResponse>
200					<TelephoneNumberDetails>
201						<State>KE</State>
202						<RateCenter>FA</RateCenter>
203					</TelephoneNumberDetails>
204				</TelephoneNumberResponse>
205			RESPONSE
206			Command::COMMAND_MANAGER.expect(
207				:write,
208				EMPromise.resolve(Blather::Stanza::Iq::Command.new.tap { |iq|
209					iq.form.fields = [{ var: "plan_name", value: "test_usd" }]
210				}),
211				[Matching.new do |iq|
212					assert_equal :form, iq.form.type
213					assert_equal(
214						"You've selected +15555550000 (FA, KE) as your JMP number.",
215						iq.form.instructions.lines.first.chomp
216					)
217					assert_equal 1, iq.form.fields.length
218				end]
219			)
220			Registration::Activation::Allow::DB.expect(
221				:transaction,
222				EMPromise.reject(:test_result)
223			) do |&blk|
224				blk.call
225				true
226			end
227			Registration::Activation::Allow::DB.expect(
228				:exec,
229				nil,
230				[String, ["refercust", "test"]]
231			)
232			cust.expect(:with_plan, cust, ["test_usd"])
233			cust.expect(:activate_plan_starting_now, nil)
234			assert_equal(
235				:test_result,
236				execute_command { allow.write.catch { |e| e } }
237			)
238			assert_mock Command::COMMAND_MANAGER
239		end
240		em :test_write_credit_to_refercust
241	end
242
243	class PaymentTest < Minitest::Test
244		CustomerFinancials::BRAINTREE = Minitest::Mock.new
245
246		def test_for_bitcoin
247			cust = Minitest::Mock.new(customer)
248			cust.expect(:with_plan, cust, ["test_usd"])
249			cust.expect(:save_plan!, nil)
250			iq = Blather::Stanza::Iq::Command.new
251			iq.form.fields = [
252				{ var: "activation_method", value: "bitcoin" },
253				{ var: "plan_name", value: "test_usd" }
254			]
255			result = Registration::Payment.for(iq, cust, "+15555550000")
256			assert_kind_of Registration::Payment::Bitcoin, result
257			assert_mock cust
258		end
259
260		def test_for_credit_card
261			cust = Minitest::Mock.new(customer)
262			cust.expect(:with_plan, cust, ["test_usd"])
263			cust.expect(:save_plan!, nil)
264			braintree_customer = Minitest::Mock.new
265			CustomerFinancials::BRAINTREE.expect(
266				:customer,
267				braintree_customer
268			)
269			braintree_customer.expect(
270				:find,
271				EMPromise.resolve(OpenStruct.new(payment_methods: [])),
272				["test"]
273			)
274			iq = Blather::Stanza::Iq::Command.new
275			iq.from = "test@example.com"
276			iq.form.fields = [
277				{ var: "activation_method", value: "credit_card" },
278				{ var: "plan_name", value: "test_usd" }
279			]
280			result = Registration::Payment.for(
281				iq,
282				cust,
283				"+15555550000"
284			).sync
285			assert_kind_of Registration::Payment::CreditCard, result
286			assert_mock cust
287		end
288		em :test_for_credit_card
289
290		def test_for_code
291			cust = Minitest::Mock.new(customer)
292			cust.expect(:with_plan, cust, ["test_usd"])
293			cust.expect(:save_plan!, nil)
294			iq = Blather::Stanza::Iq::Command.new
295			iq.form.fields = [
296				{ var: "activation_method", value: "code" },
297				{ var: "plan_name", value: "test_usd" }
298			]
299			result = Registration::Payment.for(
300				iq,
301				cust,
302				"+15555550000"
303			)
304			assert_kind_of Registration::Payment::InviteCode, result
305			assert_mock cust
306		end
307
308		class BitcoinTest < Minitest::Test
309			Registration::Payment::Bitcoin::BTC_SELL_PRICES = Minitest::Mock.new
310			CustomerFinancials::REDIS = Minitest::Mock.new
311
312			def setup
313				@customer = Minitest::Mock.new(
314					customer(plan_name: "test_usd")
315				)
316				@customer.expect(
317					:add_btc_address,
318					EMPromise.resolve("testaddr")
319				)
320				@bitcoin = Registration::Payment::Bitcoin.new(
321					@customer,
322					"+15555550000"
323				)
324			end
325
326			def test_write
327				CustomerFinancials::REDIS.expect(
328					:smembers,
329					EMPromise.resolve([]),
330					["jmp_customer_btc_addresses-test"]
331				)
332				reply_text = <<~NOTE
333					Activate your account by sending at least 1.000000 BTC to
334					testaddr
335
336					You will receive a notification when your payment is complete.
337				NOTE
338				blather = Minitest::Mock.new
339				blather.expect(
340					:<<,
341					nil,
342					[Matching.new do |reply|
343						assert_equal :canceled, reply.status
344						assert_equal :info, reply.note_type
345						assert_equal reply_text, reply.note.content
346						true
347					end]
348				)
349				Registration::Payment::Bitcoin::BTC_SELL_PRICES.expect(
350					:usd,
351					EMPromise.resolve(BigDecimal(1))
352				)
353				@bitcoin.stub(:save, EMPromise.resolve(nil)) do
354					execute_command(blather: blather) do
355						@bitcoin.write
356					end
357				end
358				assert_mock blather
359			end
360			em :test_write
361		end
362
363		class CreditCardTest < Minitest::Test
364			def setup
365				@credit_card = Registration::Payment::CreditCard.new(
366					customer,
367					"+15555550000"
368				)
369			end
370
371			def test_for
372				customer = Minitest::Mock.new(customer)
373				customer.expect(
374					:payment_methods,
375					EMPromise.resolve(OpenStruct.new(default_payment_method: :test))
376				)
377				assert_kind_of(
378					Registration::Payment::CreditCard::Activate,
379					Registration::Payment::CreditCard.for(
380						customer,
381						"+15555550000"
382					).sync
383				)
384			end
385			em :test_for
386
387			def test_write
388				result = execute_command do
389					Command::COMMAND_MANAGER.expect(
390						:write,
391						EMPromise.reject(:test_result),
392						[Matching.new do |reply|
393							assert_equal [:execute, :next], reply.allowed_actions
394							assert_equal(
395								"Add credit card, then return here to continue: " \
396								"http://creditcard.example.com",
397								reply.note.content
398							)
399						end]
400					)
401
402					@credit_card.write.catch { |e| e }
403				end
404
405				assert_equal :test_result, result
406			end
407			em :test_write
408		end
409
410		class ActivateTest < Minitest::Test
411			Registration::Payment::CreditCard::Activate::Finish =
412				Minitest::Mock.new
413			Registration::Payment::CreditCard::Activate::Transaction =
414				Minitest::Mock.new
415			Command::COMMAND_MANAGER = Minitest::Mock.new
416
417			def test_write
418				transaction = PromiseMock.new
419				transaction.expect(
420					:insert,
421					EMPromise.resolve(nil)
422				)
423				customer = Minitest::Mock.new(
424					customer(plan_name: "test_usd")
425				)
426				Registration::Payment::CreditCard::Activate::Transaction.expect(
427					:sale,
428					transaction
429				) do |acustomer, amount:, payment_method:|
430					assert_operator customer, :===, acustomer
431					assert_equal CONFIG[:activation_amount], amount
432					assert_equal :test_default_method, payment_method
433				end
434				customer.expect(:bill_plan, nil)
435				Registration::Payment::CreditCard::Activate::Finish.expect(
436					:new,
437					OpenStruct.new(write: nil),
438					[customer, "+15555550000"]
439				)
440				execute_command do
441					Registration::Payment::CreditCard::Activate.new(
442						customer,
443						:test_default_method,
444						"+15555550000"
445					).write
446				end
447				Registration::Payment::CreditCard::Activate::Transaction.verify
448				transaction.verify
449				customer.verify
450				Registration::Payment::CreditCard::Activate::Finish.verify
451			end
452			em :test_write
453
454			def test_write_declines
455				customer = Minitest::Mock.new(
456					customer(plan_name: "test_usd")
457				)
458				iq = Blather::Stanza::Iq::Command.new
459				iq.from = "test@example.com"
460				msg = Registration::Payment::CreditCard::Activate::DECLINE_MESSAGE
461				Command::COMMAND_MANAGER.expect(
462					:write,
463					EMPromise.reject(:test_result),
464					[Matching.new do |reply|
465						assert_equal :error, reply.note_type
466						assert_equal(
467							"#{msg}: http://creditcard.example.com",
468							reply.note.content
469						)
470					end]
471				)
472				result = execute_command do
473					Registration::Payment::CreditCard::Activate::Transaction.expect(
474						:sale,
475						EMPromise.reject("declined")
476					) do |acustomer, amount:, payment_method:|
477						assert_operator customer, :===, acustomer
478						assert_equal CONFIG[:activation_amount], amount
479						assert_equal :test_default_method, payment_method
480					end
481
482					Registration::Payment::CreditCard::Activate.new(
483						customer,
484						:test_default_method,
485						"+15555550000"
486					).write.catch { |e| e }
487				end
488				assert_equal :test_result, result
489				Registration::Payment::CreditCard::Activate::Transaction.verify
490			end
491			em :test_write_declines
492		end
493
494		class InviteCodeTest < Minitest::Test
495			Registration::Payment::InviteCode::DB =
496				Minitest::Mock.new
497			Registration::Payment::InviteCode::REDIS =
498				Minitest::Mock.new
499			Command::COMMAND_MANAGER = Minitest::Mock.new
500			Registration::Payment::InviteCode::Finish =
501				Minitest::Mock.new
502			def test_write
503				customer = customer(plan_name: "test_usd")
504				Registration::Payment::InviteCode::DB.expect(:transaction, true, [])
505				Registration::Payment::InviteCode::Finish.expect(
506					:new,
507					OpenStruct.new(write: nil),
508					[
509						customer,
510						"+15555550000"
511					]
512				)
513				execute_command do
514					Registration::Payment::InviteCode::REDIS.expect(
515						:get,
516						EMPromise.resolve(nil),
517						["jmp_invite_tries-test"]
518					)
519					Command::COMMAND_MANAGER.expect(
520						:write,
521						EMPromise.resolve(
522							Blather::Stanza::Iq::Command.new.tap { |iq|
523								iq.form.fields = [{ var: "code", value: "abc" }]
524							}
525						),
526						[Matching.new do |reply|
527							assert_equal :form, reply.form.type
528							assert_nil reply.form.instructions
529						end]
530					)
531
532					Registration::Payment::InviteCode.new(
533						customer,
534						"+15555550000"
535					).write
536				end
537				assert_mock Command::COMMAND_MANAGER
538				assert_mock Registration::Payment::InviteCode::DB
539				assert_mock Registration::Payment::InviteCode::REDIS
540				assert_mock Registration::Payment::InviteCode::Finish
541			end
542			em :test_write
543
544			def test_write_bad_code
545				result = execute_command do
546					customer = customer(plan_name: "test_usd")
547					Registration::Payment::InviteCode::REDIS.expect(
548						:get,
549						EMPromise.resolve(0),
550						["jmp_invite_tries-test"]
551					)
552					Registration::Payment::InviteCode::DB.expect(:transaction, []) do
553						raise Registration::Payment::InviteCode::Invalid, "wut"
554					end
555					Registration::Payment::InviteCode::REDIS.expect(
556						:incr,
557						EMPromise.resolve(nil),
558						["jmp_invite_tries-test"]
559					)
560					Registration::Payment::InviteCode::REDIS.expect(
561						:expire,
562						EMPromise.resolve(nil),
563						["jmp_invite_tries-test", 60 * 60]
564					)
565					Command::COMMAND_MANAGER.expect(
566						:write,
567						EMPromise.resolve(
568							Blather::Stanza::Iq::Command.new.tap { |iq|
569								iq.form.fields = [{ var: "code", value: "abc" }]
570							}
571						),
572						[Matching.new do |reply|
573							assert_equal :form, reply.form.type
574							assert_nil reply.form.instructions
575						end]
576					)
577					Command::COMMAND_MANAGER.expect(
578						:write,
579						EMPromise.reject(:test_result),
580						[Matching.new do |reply|
581							assert_equal :form, reply.form.type
582							assert_equal "wut", reply.form.instructions
583						end]
584					)
585
586					Registration::Payment::InviteCode.new(
587						customer,
588						"+15555550000"
589					).write.catch { |e| e }
590				end
591				assert_equal :test_result, result
592				assert_mock Command::COMMAND_MANAGER
593				assert_mock Registration::Payment::InviteCode::DB
594				assert_mock Registration::Payment::InviteCode::REDIS
595			end
596			em :test_write_bad_code
597
598			def test_write_bad_code_over_limit
599				result = execute_command do
600					customer = customer(plan_name: "test_usd")
601					Registration::Payment::InviteCode::REDIS.expect(
602						:get,
603						EMPromise.resolve(11),
604						["jmp_invite_tries-test"]
605					)
606					Command::COMMAND_MANAGER.expect(
607						:write,
608						EMPromise.resolve(
609							Blather::Stanza::Iq::Command.new.tap { |iq|
610								iq.form.fields = [{ var: "code", value: "abc" }]
611							}
612						),
613						[Matching.new do |reply|
614							assert_equal :form, reply.form.type
615							assert_nil reply.form.instructions
616						end]
617					)
618					Registration::Payment::InviteCode::REDIS.expect(
619						:incr,
620						EMPromise.resolve(nil),
621						["jmp_invite_tries-test"]
622					)
623					Registration::Payment::InviteCode::REDIS.expect(
624						:expire,
625						EMPromise.resolve(nil),
626						["jmp_invite_tries-test", 60 * 60]
627					)
628					Command::COMMAND_MANAGER.expect(
629						:write,
630						EMPromise.reject(:test_result),
631						[Matching.new do |reply|
632							assert_equal :form, reply.form.type
633							assert_equal "Too many wrong attempts", reply.form.instructions
634						end]
635					)
636					Registration::Payment::InviteCode.new(
637						customer,
638						"+15555550000"
639					).write.catch { |e| e }
640				end
641				assert_equal :test_result, result
642				assert_mock Command::COMMAND_MANAGER
643				assert_mock Registration::Payment::InviteCode::REDIS
644			end
645			em :test_write_bad_code_over_limit
646		end
647	end
648
649	class FinishTest < Minitest::Test
650		Command::COMMAND_MANAGER = Minitest::Mock.new
651		Registration::Finish::TEL_SELECTIONS = FakeTelSelections.new
652		Registration::Finish::REDIS = Minitest::Mock.new
653		Bwmsgsv2Repo::REDIS = Minitest::Mock.new
654
655		def setup
656			@sgx = Minitest::Mock.new(TrivialBackendSgxRepo.new.get("test"))
657			iq = Blather::Stanza::Iq::Command.new
658			iq.from = "test\\40example.com@cheogram.com"
659			@finish = Registration::Finish.new(
660				customer(sgx: @sgx),
661				"+15555550000"
662			)
663		end
664
665		def test_write
666			create_order = stub_request(
667				:post,
668				"https://dashboard.bandwidth.com/v1.0/accounts//orders"
669			).to_return(status: 201, body: <<~RESPONSE)
670				<OrderResponse>
671					<Order>
672						<id>test_order</id>
673					</Order>
674				</OrderResponse>
675			RESPONSE
676			stub_request(
677				:get,
678				"https://dashboard.bandwidth.com/v1.0/accounts//orders/test_order"
679			).to_return(status: 201, body: <<~RESPONSE)
680				<OrderResponse>
681					<OrderStatus>COMPLETE</OrderStatus>
682					<CompletedNumbers>
683						<TelephoneNumber>
684							<FullNumber>5555550000</FullNumber>
685						</TelephoneNumber>
686					</CompletedNumbers>
687				</OrderResponse>
688			RESPONSE
689			stub_request(
690				:post,
691				"https://dashboard.bandwidth.com/v1.0/accounts//sites//sippeers//movetns"
692			)
693			Registration::Finish::REDIS.expect(
694				:del,
695				nil,
696				["pending_tel_for-test@example.net"]
697			)
698			Bwmsgsv2Repo::REDIS.expect(
699				:set,
700				nil,
701				[
702					"catapult_fwd-+15555550000",
703					"xmpp:test@example.net"
704				]
705			)
706			Bwmsgsv2Repo::REDIS.expect(
707				:set,
708				nil,
709				["catapult_fwd_timeout-customer_test@component", 25]
710			)
711			blather = Minitest::Mock.new
712			blather.expect(
713				:<<,
714				nil,
715				[Matching.new do |reply|
716					assert_equal :completed, reply.status
717					assert_equal :info, reply.note_type
718					assert_equal(
719						"Your JMP account has been activated as +15555550000",
720						reply.note.content
721					)
722				end]
723			)
724			execute_command(blather: blather) do
725				@sgx.expect(
726					:register!,
727					EMPromise.resolve(@sgx.with(registered?: IBR.new.tap do |ibr|
728						ibr.phone = "+15555550000"
729					end)),
730					["+15555550000"]
731				)
732
733				@finish.write
734			end
735			assert_requested create_order
736			assert_mock @sgx
737			assert_mock Registration::Finish::REDIS
738			assert_mock Bwmsgsv2Repo::REDIS
739			assert_mock blather
740		end
741		em :test_write
742
743		def test_write_tn_fail
744			create_order = stub_request(
745				:post,
746				"https://dashboard.bandwidth.com/v1.0/accounts//orders"
747			).to_return(status: 201, body: <<~RESPONSE)
748				<OrderResponse>
749					<Order>
750						<id>test_order</id>
751					</Order>
752				</OrderResponse>
753			RESPONSE
754			stub_request(
755				:get,
756				"https://dashboard.bandwidth.com/v1.0/accounts//orders/test_order"
757			).to_return(status: 201, body: <<~RESPONSE)
758				<OrderResponse>
759					<OrderStatus>FAILED</OrderStatus>
760				</OrderResponse>
761			RESPONSE
762
763			result = execute_command do
764				Command::COMMAND_MANAGER.expect(
765					:write,
766					EMPromise.reject(:test_result),
767					[Matching.new do |iq|
768						assert_equal :form, iq.form.type
769						assert_equal(
770							"The JMP number +15555550000 is no longer available.",
771							iq.form.instructions
772						)
773					end]
774				)
775
776				@finish.write.catch { |e| e }
777			end
778
779			assert_equal :test_result, result
780			assert_mock Command::COMMAND_MANAGER
781			assert_instance_of(
782				TelSelections::ChooseTel,
783				Registration::Finish::TEL_SELECTIONS["test@example.com"]
784			)
785			assert_requested create_order
786		end
787		em :test_write_tn_fail
788	end
789end