# frozen_string_literal: true

require "test_helper"
require "alt_top_up_form"
require "add_bitcoin_address"

class AddBitcoinAddressTest < Minitest::Test
	def test_for
		iq = Blather::Stanza::Iq::Command.new
		cust = customer
		AddBitcoinAddress.for(iq, AltTopUpForm.new(cust), cust)
	end

	def test_for_add_bitcoin
		iq = Blather::Stanza::Iq::Command.new
		iq.form.fields = [{ var: "add_btc_address", value: "true" }]
		cust = customer
		AddBitcoinAddress.for(iq, AltTopUpForm.new(cust), cust)
	end

	def test_write
		cust = Minitest::Mock.new
		cust.expect(:add_btc_address, EMPromise.resolve("newaddress"))
		iq = Blather::Stanza::Iq::Command.new
		AddBitcoinAddress.new(iq, cust).write.sync
		assert_mock cust
	end
	em :test_write

	class DoNotTest < Minitest::Test
		AddBitcoinAddress::DoNot::BLATHER = Minitest::Mock.new

		def test_write
			AddBitcoinAddress::DoNot::BLATHER.expect(
				:<<,
				EMPromise.resolve(nil)
			) do |stanza|
				assert_equal :completed, stanza.status
			end
			iq = Blather::Stanza::Iq::Command.new
			AddBitcoinAddress::DoNot.new(iq).write.sync
			assert_mock AddBitcoinAddress::DoNot::BLATHER
		end
		em :test_write
	end
end
