Sha256: 94256e53d03b8281fb04199e85ba74aa0c566c64b5f261687f54c067eb7eb36d
Contents?: true
Size: 1.92 KB
Versions: 14
Compression:
Stored size: 1.92 KB
Contents
require 'spec_helper' describe 'BooticClient::Strategies::BasicAuth' do require 'webmock/rspec' let(:root_data) { { '_links' => { 'a_product' => {'href' => 'https://api.bootic.net/v1/products/1'} }, 'message' => "Hello!" } } let(:product_data) { {'title' => 'iPhone 6 Plus'} } let(:client) { BooticClient.client(:basic_auth, username: 'foo', password: 'bar') } describe '#inspect' do it 'is informative' do expect(client.inspect).to eql %(#<BooticClient::Strategies::BasicAuth root: https://api.bootic.net/v1 username: foo>) end end context 'with missing credentials' do it 'raises error' do expect{ BooticClient.client(:basic_auth) }.to raise_error(ArgumentError) end end context 'with invalid BasicAuth credentials' do let!(:root_request) do stub_request(:get, 'https://foo:bar@api.bootic.net/v1') .to_return(status: 401, body: JSON.dump(root_data)) end it 'raises an Unauthorized error' do expect{ client.root }.to raise_error(BooticClient::UnauthorizedError) expect(root_request).to have_been_requested end end context 'with valid BasicAuth credentials' do let!(:root_request) do stub_request(:get, 'https://foo:bar@api.bootic.net/v1') .to_return(status: 200, body: JSON.dump(root_data)) end let!(:product_request) do stub_request(:get, 'https://foo:bar@api.bootic.net/v1/products/1') .to_return(status: 200, body: JSON.dump(product_data)) end let!(:root) { client.root } it 'includes Basic Auth credentials in request' do expect(root_request).to have_been_requested expect(root.message).to eql('Hello!') end it 'follows links as normal, including Basic Auth in every request' do product = root.a_product expect(product_request).to have_been_requested expect(product.title).to eql 'iPhone 6 Plus' end end end
Version data entries
14 entries across 14 versions & 1 rubygems