Sha256: ae94cfd5ef9cf2aa07a0fdec409002105a7a893695bc8d792fd68b95ad1bc734

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe AgraApi::Organisation do
  subject { AgraApi.new(host: 'test.com') }

  describe 'configuration' do
    it 'should propagate the host' do
      expect(subject.organisation.client.connection.configuration.host).to eq('test.com')
    end
  end

  describe 'find_by_host' do
    let(:body) { fixture('organisation.json') }
    let(:request_path) { '/api/organisations/?host=foo.com' }

    before(:each) do
      stub_get(request_path).to_return(body: body, status: status, headers: {content_type: "application/json; charset=utf-8"})
    end

    describe 'success' do
      let(:status) { 200 }
      let(:organisation) { subject.organisation.find_by_host('foo.com') }

      it 'should find an organisation' do
        expect(organisation.settings.action_kit_host).to eq('foo.com')
      end
    end

    describe 'an error' do
      let(:status) { 500 }

      it 'should raise' do
        expect { subject.organisation.find_by_host('foo.com') }.to raise_exception(StandardError)
      end
    end
  end

  describe "basic authentication" do
    subject { AgraApi.new(host: 'test.com', username: 'username', password: 'password')}
    let(:request_path) { '/api/organisations/?host=foo.com' }
    let(:body) { "" }

    before(:each) do
      stub_request(:get, "https://test.com#{request_path}").with(basic_auth: ['username', 'password'])
        .to_return(body: body, status: status, headers: { content_type: "application/json; charset=utf-8"})
    end


    describe "unauthorized" do
      let(:status) { 401 }

      it "should raise" do
        expect { subject.organisation.find_by_host('foo.com') }.to raise_exception(StandardError)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
agra_api-0.3.5 spec/organisation_spec.rb
agra_api-0.3.4 spec/organisation_spec.rb