test/test_bitfex.rb in bitfex-1.2.0 vs test/test_bitfex.rb in bitfex-2.0.0

- old
+ new

@@ -17,137 +17,109 @@ client = Bitfex::Api.new client.server_url = 'https://google.com/' assert_equal 'https://google.com/', client.server_url end - def test_auth_success - stub_request(:post, 'https://auth.bitfex.trade/auth') - .with(body: '{"auth":{"email":"user@example.com","password":"123"}}') - .to_return(status: 200, body: '{"jwt":"token"}') - - client = Bitfex::Api.new - assert_equal 'token', client.auth('user@example.com', '123') - end - - def test_auth_failure - stub_request(:post, 'https://auth.bitfex.trade/auth') - .with(body: '{"auth":{"email":"user@example.com","password":"123"}}') - .to_return(status: 404, body: '{}') - - assert_raises Bitfex::AuthError do - client = Bitfex::Api.new - client.auth('user@example.com', '123') - end - end - def test_balances_success stub_request(:get, "https://bitfex.trade/api/v1/user") - .with(headers: { 'Authorization' => 'Bearer 123' }) + .with(headers: { 'X-API-Key' => '123' }) .to_return(status: 200, body: '{"success":true,"balances":{"BTC":10.5}}') - client = Bitfex::Api.new - client.token = '123' - assert_equal({'BTC' => 10.5}, client.balances) + client = Bitfex::Api.new(token: '123') + assert_equal({ 'BTC' => 10.5 }, client.balances) end def test_balances_failure stub_request(:get, "https://bitfex.trade/api/v1/user") - .with(headers: { 'Authorization' => 'Bearer 123' }) + .with(headers: { 'X-API-Key' => '123' }) .to_return(status: 403, body: '{"success":false,"errors":["TEST"]}') assert_raises Bitfex::ApiError do - client = Bitfex::Api.new - client.token = '123' + client = Bitfex::Api.new(token: '123') client.balances end end def test_orders_list_success stub_request(:get, "https://bitfex.trade/api/v1/orders?pair=BTC_RUR") - .with(headers: { 'Authorization' => 'Bearer 123' }) + .with(headers: { 'X-API-Key' => '123' }) .to_return(status: 200, body: '{"success":true,"orders":[{"id":1}]}') - client = Bitfex::Api.new - client.token = '123' + client = Bitfex::Api.new(token: '123') assert_equal([{'id' => 1}], client.orders_list('BTC_RUR')) end def test_orders_list_faulure stub_request(:get, "https://bitfex.trade/api/v1/orders?pair=BTC_RUR") - .with(headers: { 'Authorization' => 'Bearer 123' }) + .with(headers: { 'X-API-Key' => '123' }) .to_return(status: 403, body: '{"success":false,"errors":["TEST"]}') assert_raises Bitfex::ApiError do - client = Bitfex::Api.new - client.token = '123' + client = Bitfex::Api.new(token: '123') client.orders_list('BTC_RUR') end end def test_my_orders_success stub_request(:get, "https://bitfex.trade/api/v1/orders/my") - .with(headers: { 'Authorization' => 'Bearer 123' }) + .with(headers: { 'X-API-Key' => '123' }) .to_return(status: 200, body: '{"success":true,"orders":[{"id":1}]}') - client = Bitfex::Api.new - client.token = '123' + client = Bitfex::Api.new(token: '123') assert_equal([{'id' => 1}], client.my_orders) end def test_my_orders_faulure stub_request(:get, "https://bitfex.trade/api/v1/orders/my") - .with(headers: { 'Authorization' => 'Bearer 123' }) + .with(headers: { 'X-API-Key' => '123' }) .to_return(status: 403, body: '{"success":false,"errors":["TEST"]}') assert_raises Bitfex::ApiError do - client = Bitfex::Api.new - client.token = '123' + client = Bitfex::Api.new(token: '123') client.my_orders end end def test_delete_order_success stub_request(:delete, 'https://bitfex.trade/api/v1/orders/1') - .with(headers: { 'Authorization' => 'Bearer 123' }) + .with(headers: { 'X-API-Key' => '123' }) .to_return(status: 200, body: '{"success":true}') - client = Bitfex::Api.new - client.token = '123' + client = Bitfex::Api.new(token: '123') assert_equal true, client.delete_order(1) end def test_delete_order_failure stub_request(:delete, 'https://bitfex.trade/api/v1/orders/1') - .with(headers: { 'Authorization' => 'Bearer 123' }) + .with(headers: { 'X-API-Key' => '123' }) .to_return(status: 400, body: '{"success":false,"errors":["TEST"]}') assert_raises Bitfex::ApiError do - client = Bitfex::Api.new - client.token = '123' + client = Bitfex::Api.new(token: '123') client.delete_order(1) end end def test_create_order_success stub_request(:post, 'https://bitfex.trade/api/v1/orders') .with(body: "{\"order\":{\"pair\":\"BTC_RUR\",\"operation\":\"buy\",\"amount\":1.0,\"price\":60000.0}}", - headers: { 'Authorization' => 'Bearer 123' }) + headers: { 'X-API-Key' => '123' }) .to_return(status: 200, body: '{"success":true}') - client = Bitfex::Api.new - client.token = '123' + client = Bitfex::Api.new(token: '123') assert_equal true, client.create_order(:buy, 'BTC_RUR', 1.0, 600_00.0) end def test_create_order_failure stub_request(:post, 'https://bitfex.trade/api/v1/orders') - .with(body: "{\"order\":{\"pair\":\"BTC_RUR\",\"operation\":\"buy\",\"amount\":1.0,\"price\":60000.0}}", - headers: { 'Authorization' => 'Bearer 123' }) + .with( + body: '{"order":{"pair":"BTC_RUR","operation":"buy","amount":1.0,"price":60000.0}}', + headers: { 'X-API-Key' => '123' } + ) .to_return(status: 403, body: '{"success":false,"errors":["TEST"]}') assert_raises Bitfex::ApiError do - client = Bitfex::Api.new - client.token = '123' + client = Bitfex::Api.new(token: '123') client.create_order(:buy, 'BTC_RUR', 1.0, 600_00.0) end end end