test_add_bitcoin_address.rb

 1# frozen_string_literal: true
 2
 3require "test_helper"
 4require "alt_top_up_form"
 5require "add_bitcoin_address"
 6
 7class AddBitcoinAddressTest < Minitest::Test
 8	def test_for
 9		iq = Blather::Stanza::Iq::Command.new
10		AddBitcoinAddress.for(iq, AltTopUpForm.new, Customer.new("test"))
11	end
12
13	def test_for_add_bitcoin
14		iq = Blather::Stanza::Iq::Command.new
15		iq.form.fields = [{ var: "add_btc_address", value: "true" }]
16		AddBitcoinAddress.for(iq, AltTopUpForm.new, Customer.new("test"))
17	end
18
19	def test_write
20		customer = Minitest::Mock.new
21		customer.expect(:add_btc_address, EMPromise.resolve("newaddress"))
22		iq = Blather::Stanza::Iq::Command.new
23		AddBitcoinAddress.new(iq, customer).write.sync
24		assert_mock customer
25	end
26	em :test_write
27
28	class DoNotTest < Minitest::Test
29		AddBitcoinAddress::DoNot::BLATHER = Minitest::Mock.new
30
31		def test_write
32			AddBitcoinAddress::DoNot::BLATHER.expect(
33				:<<,
34				EMPromise.resolve(nil)
35			) do |stanza|
36				assert_equal :completed, stanza.status
37			end
38			iq = Blather::Stanza::Iq::Command.new
39			AddBitcoinAddress::DoNot.new(iq).write.sync
40			assert_mock AddBitcoinAddress::DoNot::BLATHER
41		end
42		em :test_write
43	end
44end