spec/client_spec.rb in affirm-ruby-1.1.3 vs spec/client_spec.rb in affirm-ruby-1.2.0

- old
+ new

@@ -1,33 +1,21 @@ require "helper" RSpec.describe Affirm::Client do + before(:all) do + Affirm.configure do |config| + config.public_api_key = "abc" + config.private_api_key = "xyz" + end + end + context "new instance" do it "creates Faraday connection" do expect(subject.connection).to be_an_instance_of(Faraday::Connection) end end - context "with api keys set" do - before do - Affirm.configure do |config| - config.public_api_key = "abc" - config.private_api_key = "xyz" - end - end - - it "sets json handlers" do - expect( - subject.connection.builder.handlers - ).to include(FaradayMiddleware::EncodeJson, FaradayMiddleware::ParseJson) - end - - it "sets basic auth header" do - expect(subject.connection.headers["Authorization"]).to eq("Basic YWJjOnh5eg==") - end - end - context "post request" do before(:all) do @stubs = Faraday::Adapter::Test::Stubs.new do |stub| stub.post("/api/v2/foo") { [200, {}, ""] } stub.post("/api/v2/bar", '{"key":"value"}') { [200, {}, ""] } @@ -39,10 +27,15 @@ before do subject.connection.builder.handlers.pop subject.connection.adapter(:test, @stubs) end + it "sets basic auth header" do + response = subject.post("foo", {}) + expect(response.env.request_headers["Authorization"]).to eq("Basic YWJjOnh5eg==") + end + it "makes request to full url" do response = subject.post("foo", {}) expect(response.env.url.to_s).to eq("https://api.affirm.com/api/v2/foo") end @@ -70,9 +63,14 @@ after(:all) { @stubs.verify_stubbed_calls } before do subject.connection.builder.handlers.pop subject.connection.adapter(:test, @stubs) + end + + it "sets basic auth header" do + response = subject.get("foo", {}) + expect(response.env.request_headers["Authorization"]).to eq("Basic YWJjOnh5eg==") end it "makes request to full url" do response = subject.get("foo", {}) expect(response.env.url.to_s).to eq("https://api.affirm.com/api/v2/foo")