# frozen_string_literal: true

require "em-hiredis"
require "test_helper"
require "btc_sell_prices"

class BTCSellPricesTest < Minitest::Test
	def setup
		@redis = Minitest::Mock.new
		@bull = Minitest::Mock.new
		@subject = BTCSellPrices.new(@redis, "", bull: @bull)
	end

	def test_cad
		@bull.expect(
			:fetch_btc_cad,
			EMPromise.resolve(BigDecimal("123.45"))
		)
		assert_equal BigDecimal("123.45"), @subject.cad.sync
		assert_mock @bull
	end
	em :test_cad

	def test_usd
		@bull.expect(
			:fetch_btc_cad,
			EMPromise.resolve(BigDecimal("123.45"))
		)
		@redis.expect(:get, EMPromise.resolve("0.5"), ["cad_to_usd"])
		assert_equal BigDecimal("61.725"), @subject.usd.sync
		assert_mock @bull
		assert_mock @redis
	end
	em :test_usd
end
