Sha256: 82307a28f2b28772ea81cca17fd9e0a0e8bfca9d146ba3f0b05f0037189392ab

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'

describe G5Updatable::AllClientUrnsFetcher do
  let(:token) { 'a-token' }

  describe '#fetch_uids' do
    before do
      allow(G5Updatable::Fetcher).to receive(:do_with_username_pw_access_token).and_yield(token)
      stub_request(:get, 'https://g5-hub.herokuapp.com/urns.json?access_token=a-token').
          with(:headers => {'Accept' => 'application/json', 'Content-Type' => 'application/json'}).
          to_return(status: status, body: fixture('urns.json'), headers: {})
    end

    subject { described_class.fetch_uids }

    context 'success' do
      let(:status) { 200 }

      it do
        is_expected.to eq(['https://g5-hub.herokuapp.com/clients/g5-c-iwcqdt3u-arenhall-management-company-client.json',
                           'https://g5-hub.herokuapp.com/clients/g5-c-iw2fm3cx-artis-senior-living-management-multidomain.json'])
      end
    end

    context '404' do
      let(:status) { 404 }

      it 'raises error' do
        expect { subject }.to raise_error("Couldn't find record at URL 'https://g5-hub.herokuapp.com/urns.json'")
      end
    end

    context '500' do
      let(:status) { 500 }

      it 'raises error' do
        expect { subject }.to raise_error("I got an unexpected response code '500'")
      end
    end
  end


  describe '#hub_url' do
    it 'returns the default hub url' do
      expect(described_class.hub_url).to eq(G5Updatable::HUB_URL)
    end

    context 'with HUB_URL override' do
      before { stub_const('G5Updatable::HUB_URL', 'http://whatever.com') }

      it 'returns a custom URL if set' do
        expect(described_class.hub_url).to eq('http://whatever.com')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
g5_updatable-0.20.3.pre.1 spec/lib/g5_updatable/all_client_urns_fetcher_spec.rb