# frozen_string_literal: true

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

class BCHSellPricesTest < Minitest::Test
	def setup
		@redis = Minitest::Mock.new
		@subject = BCHSellPrices.new(@redis, "")
	end

	def test_cad
		stub_request(:get, "https://www.canadianbitcoins.com").to_return(
			body: "<div id='ticker'><table><tbody>" \
			      "<tr>" \
				  "<td>Monopoly Money</td><td></td><td></td><td>10 trillion</td>" \
				  "</tr>" \
				  "<tr>" \
				  "<td>Bitcoin Cash</td><td></td><td></td><td>$123.00</td>" \
				  "</tr>"
		)
		assert_equal BigDecimal(123), @subject.cad.sync
	end
	em :test_cad

	def test_usd
		stub_request(:get, "https://www.canadianbitcoins.com").to_return(
			body: "<div id='ticker'><table><tbody>" \
			      "<tr>" \
				  "<td>Monopoly Money</td><td></td><td></td><td>10 trillion</td>" \
				  "</tr>" \
				  "<tr>" \
				  "<td>Bitcoin Cash</td><td></td><td></td><td>$123.00</td>" \
				  "</tr>"
		)
		@redis.expect(:get, EMPromise.resolve("0.5"), ["cad_to_usd"])
		assert_equal BigDecimal(123) / 2, @subject.usd.sync
	end
	em :test_usd
end
