Sha256: 15a4caea2ef9b011899ee7254bebd0ba8af521bca475f89145cdcf3cf3fc863b

Contents?: true

Size: 1.79 KB

Versions: 8

Compression:

Stored size: 1.79 KB

Contents

# encoding: utf-8
require "spec_helper"

describe FastshopCatalog::ExternalDneService do

  include Savon::SpecHelper
  before(:all) { savon.mock! }
  after(:all)  { savon.unmock! }

  let(:service) do
    FastshopCatalog::ExternalDneService.new
  end

  let(:contract_number) do
    "1234567890"
  end
  let(:zip_code) do
    '04562030'
  end

  let(:fixture) do
    File.read("spec/fixtures/external_dne_service_successful_response.xml")
  end

  let(:fixture_wrong_contract) do
    File.read("spec/fixtures/external_dne_service_wrong_contract_response.xml")
  end

  let(:fixture_wrong_zip) do
    File.read("spec/fixtures/external_dne_service_wrong_zip_response.xml")
  end

  describe "query" do

    it "should return the list with the expected size" do
      savon.expects(:consultar).with(:message => {'tns:contrato' => contract_number, 'tns:cep' => zip_code }).returns(fixture)
      result = service.query(contract_number, zip_code)
      expect(result['Cidade']).to eq('SAO PAULO')
      expect(result['Endereco']).to eq('ARANDU')
    end

    it "should return wrong contract exception" do
      savon.expects(:consultar).with(:message => {'tns:contrato' => 'lixo', 'tns:cep' => zip_code}).returns(fixture_wrong_contract)
      expect{service.query('lixo', zip_code)}.to raise_error(FastshopCatalog::ServiceException) do |e|
        expect(e.code).to eq(2)
        expect(e.description).to eq('Contrato invalido')
      end
    end
    
    it "should return invalid zip exception" do
      savon.expects(:consultar).with(:message => {'tns:contrato' => 'lixo', 'tns:cep' => '1111'}).returns(fixture_wrong_zip)
      expect{service.query('lixo', '1111')}.to raise_error(FastshopCatalog::ServiceException) do |e|
        expect(e.code).to eq(9)
        expect(e.description).to eq('CEP invalido')
      end
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fastshop_catalog-0.0.8 spec/fastshop_catalog/external_dne_service_spec.rb
fastshop_catalog-0.0.7 spec/fastshop_catalog/external_dne_service_spec.rb
fastshop_catalog-0.0.6 spec/fastshop_catalog/external_dne_service_spec.rb
fastshop_catalog-0.0.5 spec/fastshop_catalog/external_dne_service_spec.rb
fastshop_catalog-0.0.4 spec/fastshop_catalog/external_dne_service_spec.rb
fastshop_catalog-0.0.3 spec/fastshop_catalog/external_dne_service_spec.rb
fastshop_catalog-0.0.2 spec/fastshop_catalog/external_dne_service_spec.rb
fastshop_catalog-0.0.1 spec/fastshop_catalog/external_dne_service_spec.rb