|
| 1 | +require "spec_helper" |
| 2 | +require "faraday" |
| 3 | + |
| 4 | +describe LaunchDarkly::Requestor do |
| 5 | + describe ".request_all_flags" do |
| 6 | + describe "with a proxy" do |
| 7 | + let(:requestor) { |
| 8 | + LaunchDarkly::Requestor.new( |
| 9 | + "key", |
| 10 | + LaunchDarkly::Config.new({ |
| 11 | + :proxy => "http://proxy.com", |
| 12 | + :base_uri => "http://ld.com" |
| 13 | + }) |
| 14 | + ) |
| 15 | + } |
| 16 | + it "converts the proxy option" do |
| 17 | + faraday = Faraday.new |
| 18 | + requestor.instance_variable_set(:@client, faraday) |
| 19 | + allow(faraday).to receive(:get) do |*args, &block| |
| 20 | + req = double(Faraday::Request, :headers => {}, :options => Faraday::RequestOptions.new) |
| 21 | + block.call(req) |
| 22 | + expect(args).to eq ['http://ld.com/sdk/latest-flags'] |
| 23 | + expect(req.options.proxy[:uri]).to eq URI("http://proxy.com") |
| 24 | + double(body: '{"foo": "bar"}', status: 200, headers: {}) |
| 25 | + end |
| 26 | + |
| 27 | + requestor.request_all_flags() |
| 28 | + end |
| 29 | + end |
| 30 | + describe "without a proxy" do |
| 31 | + let(:requestor) { |
| 32 | + LaunchDarkly::Requestor.new( |
| 33 | + "key", |
| 34 | + LaunchDarkly::Config.new({ |
| 35 | + :base_uri => "http://ld.com" |
| 36 | + }) |
| 37 | + ) |
| 38 | + } |
| 39 | + it "converts the proxy option" do |
| 40 | + faraday = Faraday.new |
| 41 | + requestor.instance_variable_set(:@client, faraday) |
| 42 | + allow(faraday).to receive(:get) do |*args, &block| |
| 43 | + req = double(Faraday::Request, :headers => {}, :options => Faraday::RequestOptions.new) |
| 44 | + block.call(req) |
| 45 | + expect(args).to eq ['http://ld.com/sdk/latest-flags'] |
| 46 | + expect(req.options.proxy).to eq nil |
| 47 | + double(body: '{"foo": "bar"}', status: 200, headers: {}) |
| 48 | + end |
| 49 | + requestor.request_all_flags() |
| 50 | + end |
| 51 | + end |
| 52 | + end |
| 53 | +end |
0 commit comments