All checks were successful
continuous-integration/drone/push Build is passing
44 lines
1.3 KiB
Ruby
44 lines
1.3 KiB
Ruby
require 'rails_helper'
|
|
require 'webmock/rspec'
|
|
|
|
RSpec.describe "/api/kredits", type: :request do
|
|
|
|
describe "GET /onchain_btc_balance" do
|
|
before do
|
|
stub_request(:get, "http://btcpay.example.com/api/v1/stores/123456/payment-methods/onchain/BTC/wallet")
|
|
.to_return(status: 200, headers: {}, body: {
|
|
balance: 0.91108606,
|
|
unconfirmedBalance: 0,
|
|
confirmedBalance: 0.91108606
|
|
}.to_json)
|
|
end
|
|
|
|
it "returns a formatted result for the onchain wallet balance" do
|
|
get api_kredits_onchain_btc_balance_path
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
res = JSON.parse(response.body)
|
|
expect(res["balance"]).to eq(0.91108606)
|
|
expect(res["unconfirmed_balance"]).to eq(0)
|
|
expect(res["confirmed_balance"]).to eq(0.91108606)
|
|
end
|
|
|
|
context "upstream request error" do
|
|
before do
|
|
stub_request(:get, "http://btcpay.example.com/api/v1/stores/123456/payment-methods/onchain/BTC/wallet")
|
|
.to_return(status: 500, headers: {}, body: "")
|
|
end
|
|
|
|
it "returns a formatted error" do
|
|
get api_kredits_onchain_btc_balance_path
|
|
|
|
expect(response).to have_http_status(:server_error)
|
|
|
|
res = JSON.parse(response.body)
|
|
expect(res["error"]).not_to be_nil
|
|
end
|
|
end
|
|
end
|
|
end
|