~singpolyma/sgx-jmp

ref: fea0ffeb22d0f229d528b30f3844c425b5009ad9 sgx-jmp/test/test_btc_sell_prices.rb -rw-r--r-- 814 bytes
fea0ffebStephen Paul Weber Merge branch 'no-more-catapult' 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

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

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

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