test_registration.rb

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