spec/valvat/lookup_spec.rb in valvat-1.3.0 vs spec/valvat/lookup_spec.rb in valvat-1.4.0

- old
+ new

@@ -105,10 +105,12 @@ end it 'supports old :requester_vat option for backwards compatibility' do result = described_class.validate('IE6388047V', requester_vat: 'LU21416127') + skip 'VIES is down' if result.nil? + expect(result).to match({ request_date: kind_of(Date), request_identifier: /\A[\w\W]{16}\Z/, country_code: 'IE', vat_number: '6388047V', @@ -148,10 +150,32 @@ end.to raise_error(Valvat::InvalidRequester, 'The HMRC web service returned the error: ' \ 'INVALID_REQUEST (Invalid requesterVrn - Vrn parameters should be 9 or 12 digits)') end end + + context 'when set in global config' do + before { Valvat.configure(requester: 'IE6388047V') } + after { Valvat.configure(requester: nil) } + + it 'returns hash of details instead of true' do + result = described_class.validate('IE6388047V') + + skip 'VIES is down' if result.nil? + + expect(result).to match({ + request_date: kind_of(Date), + request_identifier: /\A[\w\W]{16}\Z/, + country_code: 'IE', + vat_number: '6388047V', + name: 'GOOGLE IRELAND LIMITED', + company_type: nil, + address: '3RD FLOOR, GORDON HOUSE, BARROW STREET, DUBLIN 4', + valid: true + }) + end + end end end describe '#validate with VIES test enviroment' do let(:options) do @@ -361,11 +385,11 @@ end end describe 'Error : MESSAGE_THROTTLED_OUT' do before do - stub_request(:get, /test-api.service.hmrc.gov.uk/).to_return( + stub_request(:get, /test-api\.service\.hmrc\.gov\.uk/).to_return( status: 429, body: '{"code":"MESSAGE_THROTTLED_OUT"}' ) end @@ -378,11 +402,11 @@ end end describe 'Error : SCHEDULED_MAINTENANCE' do before do - stub_request(:get, /test-api.service.hmrc.gov.uk/).to_return( + stub_request(:get, /test-api\.service\.hmrc\.gov\.uk/).to_return( status: 503, body: '{"code":"SCHEDULED_MAINTENANCE"}' ) end @@ -397,11 +421,11 @@ end end describe 'Error : SERVER_ERROR' do before do - stub_request(:get, /test-api.service.hmrc.gov.uk/).to_return( + stub_request(:get, /test-api\.service\.hmrc\.gov\.uk/).to_return( status: 503, body: '{"code":"SERVER_ERROR"}' ) end @@ -416,11 +440,11 @@ end end describe 'Error : GATEWAY_TIMEOUT' do before do - stub_request(:get, /test-api.service.hmrc.gov.uk/).to_return( + stub_request(:get, /test-api\.service\.hmrc\.gov\.uk/).to_return( status: 504, body: '{"code":"GATEWAY_TIMEOUT"}' ) end @@ -433,11 +457,11 @@ end end describe 'Network timeout' do before do - stub_request(:get, /test-api.service.hmrc.gov.uk/).to_timeout + stub_request(:get, /test-api\.service\.hmrc\.gov\.uk/).to_timeout end it 'raises error' do expect { result }.to raise_error(Net::OpenTimeout) end @@ -449,10 +473,10 @@ end end describe 'Error : INTERNAL_SERVER_ERROR' do before do - stub_request(:get, /test-api.service.hmrc.gov.uk/).to_return( + stub_request(:get, /test-api\.service\.hmrc\.gov\.uk/).to_return( status: 500, body: '{"code":"INTERNAL_SERVER_ERROR"}' ) end