1# frozen_string_literal: true
 2
 3require "em-hiredis"
 4require "test_helper"
 5require "btc_sell_prices"
 6
 7class BCHSellPricesTest < Minitest::Test
 8	def setup
 9		@redis = Minitest::Mock.new
10		@subject = BCHSellPrices.new(@redis, "")
11	end
12
13	def test_cad
14		stub_request(:get, "https://www.canadianbitcoins.com").to_return(
15			body: "<div id='ticker'><table><tbody>" \
16			      "<tr>" \
17				  "<td>Monopoly Money</td><td></td><td></td><td>10 trillion</td>" \
18				  "</tr>" \
19				  "<tr>" \
20				  "<td>Bitcoin Cash</td><td></td><td></td><td>$123.00</td>" \
21				  "</tr>"
22		)
23		assert_equal BigDecimal(123), @subject.cad.sync
24	end
25	em :test_cad
26
27	def test_usd
28		stub_request(:get, "https://www.canadianbitcoins.com").to_return(
29			body: "<div id='ticker'><table><tbody>" \
30			      "<tr>" \
31				  "<td>Monopoly Money</td><td></td><td></td><td>10 trillion</td>" \
32				  "</tr>" \
33				  "<tr>" \
34				  "<td>Bitcoin Cash</td><td></td><td></td><td>$123.00</td>" \
35				  "</tr>"
36		)
37		@redis.expect(:get, EMPromise.resolve("0.5"), ["cad_to_usd"])
38		assert_equal BigDecimal(123) / 2, @subject.usd.sync
39	end
40	em :test_usd
41end