~singpolyma/sgx-jmp

ref: 829d69d81f60d0a222bf5d1a38f78e07ae69dfeb sgx-jmp/test/test_btc_sell_prices.rb -rw-r--r-- 822 bytes
829d69d8Stephen Paul Weber Add helper to fetch current BTC sell prices 2 years 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.new(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.new(123) / 2, @subject.usd.sync
	end
	em :test_usd
end