Sha256: 9fde5e10bfac03b55541b5429bd9d0930f383ca5800a82ad74bb8f9061648883

Contents?: true

Size: 1.72 KB

Versions: 8

Compression:

Stored size: 1.72 KB

Contents

require_relative '../../spec_helper'

module Barometer::Query
  describe Service::FromWeatherId, vcr: {
    cassette_name: 'Service::FromWeatherId'
  } do
    describe '#call' do
      context 'when the query format is not :weather_id' do
        let(:query) { Barometer::Query.new('90210') }

        it 'returns nothing' do
          geo = Service::FromWeatherId.new(query).call
          expect( geo ).to be_nil
        end

        context 'and a :weather_id conversion exists' do
          it 'returns the correct geo data' do
            query.add_conversion(:weather_id, 'USNY0996')
            geo = Service::FromWeatherId.new(query).call

            expect( geo.latitude ).to eq 40.67
            expect( geo.longitude ).to eq -73.94
            expect( geo.locality ).to eq 'New York'
            expect( geo.region ).to eq 'NY'
            expect( geo.country_code ).to eq 'US'

            expect( geo.query ).to be_nil
            expect( geo.country ).to be_nil
            expect( geo.address ).to be_nil
            expect( geo.postal_code ).to be_nil
          end
        end
      end

      context 'when the query format is :weather_id' do
        it 'returns the correct geo data' do
          query = Barometer::Query.new('USNY0996')
          geo = Service::FromWeatherId.new(query).call

          expect( geo.latitude ).to eq 40.67
          expect( geo.longitude ).to eq -73.94
          expect( geo.locality ).to eq 'New York'
          expect( geo.region ).to eq 'NY'
          expect( geo.country_code ).to eq 'US'

          expect( geo.query ).to be_nil
          expect( geo.country ).to be_nil
          expect( geo.address ).to be_nil
          expect( geo.postal_code ).to be_nil
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
barometer-0.9.7 spec/query/services/from_weather_id_spec.rb
barometer-0.9.6 spec/query/services/from_weather_id_spec.rb
barometer-0.9.5 spec/query/services/from_weather_id_spec.rb
barometer-0.9.4 spec/query/services/from_weather_id_spec.rb
barometer-0.9.3 spec/query/services/from_weather_id_spec.rb
barometer-0.9.2 spec/query/services/from_weather_id_spec.rb
barometer-0.9.1 spec/query/services/from_weather_id_spec.rb
barometer-0.9.0 spec/query/services/from_weather_id_spec.rb