test_btc_sell_prices.rb

 1# frozen_string_literal: true
 2
 3require "em-hiredis"
 4require "test_helper"
 5require "btc_sell_prices"
 6
 7class BTCSellPricesTest < Minitest::Test
 8	def setup
 9		@redis = Minitest::Mock.new
10		@bull = Minitest::Mock.new
11		@subject = BTCSellPrices.new(@redis, "", bull: @bull)
12	end
13
14	def test_cad
15		@bull.expect(
16			:fetch_btc_cad,
17			EMPromise.resolve(BigDecimal("123.45"))
18		)
19		assert_equal BigDecimal("123.45"), @subject.cad.sync
20		assert_mock @bull
21	end
22	em :test_cad
23
24	def test_usd
25		@bull.expect(
26			:fetch_btc_cad,
27			EMPromise.resolve(BigDecimal("123.45"))
28		)
29		@redis.expect(:get, EMPromise.resolve("0.5"), ["cad_to_usd"])
30		assert_equal BigDecimal("61.725"), @subject.usd.sync
31		assert_mock @bull
32		assert_mock @redis
33	end
34	em :test_usd
35end